view bookmarks of comments #26

This commit is contained in:
rimu 2024-06-21 17:28:49 +08:00
parent f97266833d
commit d929098147
7 changed files with 142 additions and 5 deletions

View file

@ -854,7 +854,11 @@ def post_options(post_id: int):
if post.deleted: if post.deleted:
abort(404) abort(404)
return render_template('post/post_options.html', post=post, existing_bookmark = []
if current_user.is_authenticated:
existing_bookmark = PostBookmark.query.filter(PostBookmark.post_id == post_id, PostBookmark.user_id == current_user.id).first()
return render_template('post/post_options.html', post=post, existing_bookmark=existing_bookmark,
moderating_communities=moderating_communities(current_user.get_id()), moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()),
menu_topics=menu_topics(), site=g.site) menu_topics=menu_topics(), site=g.site)
@ -867,7 +871,14 @@ def post_reply_options(post_id: int, comment_id: int):
if current_user.is_anonymous or not current_user.is_admin(): if current_user.is_anonymous or not current_user.is_admin():
if post.deleted or post_reply.deleted: if post.deleted or post_reply.deleted:
abort(404) abort(404)
existing_bookmark = []
if current_user.is_authenticated:
existing_bookmark = PostReplyBookmark.query.filter(PostReplyBookmark.post_reply_id == comment_id,
PostReplyBookmark.user_id == current_user.id).first()
return render_template('post/post_reply_options.html', post=post, post_reply=post_reply, return render_template('post/post_reply_options.html', post=post, post_reply=post_reply,
existing_bookmark=existing_bookmark,
moderating_communities=moderating_communities(current_user.get_id()), moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()),
menu_topics=menu_topics(), site=g.site menu_topics=menu_topics(), site=g.site
@ -1608,6 +1619,36 @@ def post_bookmark(post_id: int):
return redirect(url_for('activitypub.post_ap', post_id=post.id)) return redirect(url_for('activitypub.post_ap', post_id=post.id))
@bp.route('/post/<int:post_id>/remove_bookmark', methods=['GET', 'POST'])
@login_required
def post_remove_bookmark(post_id: int):
post = Post.query.get_or_404(post_id)
if post.deleted:
abort(404)
existing_bookmark = PostBookmark.query.filter(PostBookmark.post_id == post_id, PostBookmark.user_id == current_user.id).first()
if existing_bookmark:
db.session.delete(existing_bookmark)
db.session.commit()
flash(_('Bookmark has been removed.'))
return redirect(url_for('activitypub.post_ap', post_id=post.id))
@bp.route('/post/<int:post_id>/comment/<int:comment_id>/remove_bookmark', methods=['GET', 'POST'])
@login_required
def post_reply_remove_bookmark(post_id: int, comment_id: int):
post = Post.query.get_or_404(post_id)
post_reply = PostReply.query.get_or_404(comment_id)
if post.deleted or post_reply.deleted:
abort(404)
existing_bookmark = PostReplyBookmark.query.filter(PostReplyBookmark.post_reply_id == comment_id, PostReplyBookmark.user_id == current_user.id).first()
if existing_bookmark:
db.session.delete(existing_bookmark)
db.session.commit()
flash(_('Bookmark has been removed.'))
return redirect(url_for('activitypub.post_ap', post_id=post.id))
@bp.route('/post/<int:post_id>/report', methods=['GET', 'POST']) @bp.route('/post/<int:post_id>/report', methods=['GET', 'POST'])
@login_required @login_required
def post_report(post_id: int): def post_report(post_id: int):

View file

@ -26,8 +26,13 @@
{{ _('Delete') }}</a></li> {{ _('Delete') }}</a></li>
{% endif -%} {% endif -%}
{% endif -%} {% endif -%}
{% if existing_bookmark -%}
<li><a href="{{ url_for('post.post_remove_bookmark', post_id=post.id) }}" class="no-underline" rel="nofollow"><span class="fe fe-bookmark"></span>
{{ _('Remove bookmark') }}</a></li>
{% else -%}
<li><a href="{{ url_for('post.post_bookmark', post_id=post.id) }}" class="no-underline" rel="nofollow"><span class="fe fe-bookmark"></span> <li><a href="{{ url_for('post.post_bookmark', post_id=post.id) }}" class="no-underline" rel="nofollow"><span class="fe fe-bookmark"></span>
{{ _('Bookmark') }}</a></li> {{ _('Bookmark') }}</a></li>
{% endif -%}
{% if post.user_id == current_user.id and not post.mea_culpa -%} {% if post.user_id == current_user.id and not post.mea_culpa -%}
<li><a href="{{ url_for('post.post_mea_culpa', post_id=post.id) }}" class="no-underline"><span class="fe fe-mea-culpa"></span> <li><a href="{{ url_for('post.post_mea_culpa', post_id=post.id) }}" class="no-underline"><span class="fe fe-mea-culpa"></span>
{{ _("I made a mistake with this post and have changed my mind about the topic") }}</a></li> {{ _("I made a mistake with this post and have changed my mind about the topic") }}</a></li>

View file

@ -26,8 +26,13 @@
{{ _('Delete') }}</a></li> {{ _('Delete') }}</a></li>
{% endif -%} {% endif -%}
{% endif -%} {% endif -%}
{% if existing_bookmark -%}
<li><a href="{{ url_for('post.post_reply_remove_bookmark', post_id=post.id, comment_id=post_reply.id) }}" class="no-underline" rel="nofollow"><span class="fe fe-bookmark"></span>
{{ _('Remove bookmark') }}</a></li>
{% else -%}
<li><a href="{{ url_for('post.post_reply_bookmark', post_id=post.id, comment_id=post_reply.id) }}" class="no-underline" rel="nofollow"><span class="fe fe-bookmark"></span> <li><a href="{{ url_for('post.post_reply_bookmark', post_id=post.id, comment_id=post_reply.id) }}" class="no-underline" rel="nofollow"><span class="fe fe-bookmark"></span>
{{ _('Bookmark') }}</a></li> {{ _('Bookmark') }}</a></li>
{% endif -%}
{% if post_reply.user_id != current_user.id -%} {% if post_reply.user_id != current_user.id -%}
<li><a href="{{ url_for('post.post_reply_block_user', post_id=post.id, comment_id=post_reply.id) }}" class="no-underline"><span class="fe fe-block"></span> <li><a href="{{ url_for('post.post_reply_block_user', post_id=post.id, comment_id=post_reply.id) }}" class="no-underline"><span class="fe fe-block"></span>
{{ _('Block author @%(author_name)s', author_name=post_reply.author.user_name) }}</a></li> {{ _('Block author @%(author_name)s', author_name=post_reply.author.user_name) }}</a></li>

View file

@ -0,0 +1,12 @@
<div class="row mb-4">
<div class="col-auto">
<div class="btn-group">
<a href="/bookmarks" class="btn {{ 'btn-primary' if request.path == '/bookmarks' else 'btn-outline-secondary' }}">
{{ _('Posts') }}
</a>
<a href="/bookmarks/comments" class="btn {{ 'btn-primary' if request.path.endswith('/comments') else 'btn-outline-secondary' }}">
{{ _('Comments') }}
</a>
</div>
</div>
</div>

View file

@ -8,11 +8,20 @@
{% block app_content %} {% block app_content %}
<div class="row"> <div class="row">
<div class="col-12 col-md-8 position-relative main_pane"> <div class="col-12 col-md-8 position-relative main_pane">
<nav class="mb-2" aria-label="breadcrumb" id="breadcrumb_nav" title="Navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">{{ _('Home') }}</a></li>
<li class="breadcrumb-item"><a href="/u/{{ user.link() }}">{{ user.display_name() }}</a></li>
<li class="breadcrumb-item active">{{ _('Bookmarks') }}</li>
</ol>
</nav>
<h1>{{ _('Bookmarks') }}</h1>
{% include 'user/_bookmarks_nav.html' %}
<div class="post_list"> <div class="post_list">
{% for post in posts.items -%} {% for post in posts.items -%}
{% include 'post/_post_teaser.html' %} {% include 'post/_post_teaser.html' %}
{% else -%} {% else -%}
<p>{{ _('No posts have been bookmarked.') }}</p> <p>{{ _('No posts have been bookmarked. Use the three dots on each post to find the bookmark function.') }}</p>
{% endfor -%} {% endfor -%}
</div> </div>

View file

@ -0,0 +1,43 @@
{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %}
{% extends 'themes/' + theme() + '/base.html' %}
{% else %}
{% extends "base.html" %}
{% endif %}
{% set active_child = 'bookmarks' %}
{% block app_content %}
<div class="row">
<div class="col-12 col-md-8 position-relative main_pane">
<nav class="mb-2" aria-label="breadcrumb" id="breadcrumb_nav" title="Navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">{{ _('Home') }}</a></li>
<li class="breadcrumb-item"><a href="/u/{{ user.link() }}">{{ user.display_name() }}</a></li>
<li class="breadcrumb-item active">{{ _('Bookmarks') }}</li>
</ol>
</nav>
<h1>{{ _('Bookmarks of comments') }}</h1>
{% include 'user/_bookmarks_nav.html' %}
<div class="post_list">
{% for post_reply in post_replies.items %}
{% include 'post/_post_reply_teaser.html' %}
{% else -%}
<p>{{ _('No comments have been bookmarked. Use the three dots on each comment to find the bookmark function.') }}</p>
{% endfor -%}
</div>
<nav aria-label="Pagination" class="mt-4" role="navigation">
{% if prev_url %}
<a href="{{ prev_url }}" class="btn btn-primary" rel="nofollow">
<span aria-hidden="true">&larr;</span> {{ _('Previous page') }}
</a>
{% endif %}
{% if next_url %}
<a href="{{ next_url }}" class="btn btn-primary" rel="nofollow">
{{ _('Next page') }} <span aria-hidden="true">&rarr;</span>
</a>
{% endif %}
</nav>
</div>
</div>
{% endblock %}

View file

@ -15,7 +15,7 @@ from app.constants import SUBSCRIPTION_MEMBER, SUBSCRIPTION_PENDING, NOTIF_USER,
from app.email import send_verification_email from app.email import send_verification_email
from app.models import Post, Community, CommunityMember, User, PostReply, PostVote, Notification, utcnow, File, Site, \ from app.models import Post, Community, CommunityMember, User, PostReply, PostVote, Notification, utcnow, File, Site, \
Instance, Report, UserBlock, CommunityBan, CommunityJoinRequest, CommunityBlock, Filter, Domain, DomainBlock, \ Instance, Report, UserBlock, CommunityBan, CommunityJoinRequest, CommunityBlock, Filter, Domain, DomainBlock, \
InstanceBlock, NotificationSubscription, PostBookmark InstanceBlock, NotificationSubscription, PostBookmark, PostReplyBookmark
from app.user import bp from app.user import bp
from app.user.forms import ProfileForm, SettingsForm, DeleteAccountForm, ReportUserForm, FilterEditForm, \ from app.user.forms import ProfileForm, SettingsForm, DeleteAccountForm, ReportUserForm, FilterEditForm, \
RemoteFollowForm RemoteFollowForm
@ -881,7 +881,29 @@ def user_bookmarks():
prev_url = url_for('user.user_bookmarks', page=posts.prev_num) if posts.has_prev and page != 1 else None prev_url = url_for('user.user_bookmarks', page=posts.prev_num) if posts.has_prev and page != 1 else None
return render_template('user/bookmarks.html', title=_('Bookmarks'), posts=posts, show_post_community=True, return render_template('user/bookmarks.html', title=_('Bookmarks'), posts=posts, show_post_community=True,
low_bandwidth=low_bandwidth, low_bandwidth=low_bandwidth, user=current_user,
moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()),
menu_topics=menu_topics(), site=g.site,
next_url=next_url, prev_url=prev_url)
@bp.route('/bookmarks/comments')
@login_required
def user_bookmarks_comments():
page = request.args.get('page', 1, type=int)
low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1'
post_replies = PostReply.query.filter(PostReply.deleted == False).join(PostReplyBookmark, PostReplyBookmark.post_reply_id == PostReply.id).\
filter(PostReplyBookmark.user_id == current_user.id).order_by(desc(PostReplyBookmark.created_at))
post_replies = post_replies.paginate(page=page, per_page=100 if current_user.is_authenticated and not low_bandwidth else 50,
error_out=False)
next_url = url_for('user.user_bookmarks_comments', page=post_replies.next_num) if post_replies.has_next else None
prev_url = url_for('user.user_bookmarks_comments', page=post_replies.prev_num) if post_replies.has_prev and page != 1 else None
return render_template('user/bookmarks_comments.html', title=_('Comment bookmarks'), post_replies=post_replies, show_post_community=True,
low_bandwidth=low_bandwidth, user=current_user,
moderating_communities=moderating_communities(current_user.get_id()), moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()),
menu_topics=menu_topics(), site=g.site, menu_topics=menu_topics(), site=g.site,