From bdcb17e3c165024e36281fc8bfaa600f9fa614bf Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:34:58 +1300 Subject: [PATCH] notification toggles --- app/post/routes.py | 22 ++++++++++++++++++- .../community/_notification_toggle.html | 2 +- app/templates/post/_post_full.html | 12 ++++++++-- .../post/_post_notification_toggle.html | 4 ++++ .../post/_reply_notification_toggle.html | 4 ++++ app/templates/post/post.html | 15 ++++++++----- 6 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 app/templates/post/_post_notification_toggle.html create mode 100644 app/templates/post/_reply_notification_toggle.html diff --git a/app/post/routes.py b/app/post/routes.py index 1ac5c449..aaeb4f1d 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -830,4 +830,24 @@ def post_reply_delete(post_id: int, comment_id: int): post.flush_cache() flash(_('Comment deleted.')) # todo: federate delete - return redirect(url_for('activitypub.post_ap', post_id=post.id)) \ No newline at end of file + return redirect(url_for('activitypub.post_ap', post_id=post.id)) + + +@bp.route('/post//notification', methods=['GET', 'POST']) +@login_required +def post_notification(post_id: int): + post = Post.query.get_or_404(post_id) + if post.user_id == current_user.id: + post.notify_author = not post.notify_author + db.session.commit() + return render_template('post/_post_notification_toggle.html', post=post) + + +@bp.route('/post_reply//notification', methods=['GET', 'POST']) +@login_required +def post_reply_notification(post_reply_id: int): + post_reply = PostReply.query.get_or_404(post_reply_id) + if post_reply.user_id == current_user.id: + post_reply.notify_author = not post_reply.notify_author + db.session.commit() + return render_template('post/_reply_notification_toggle.html', comment={'comment': post_reply}) diff --git a/app/templates/community/_notification_toggle.html b/app/templates/community/_notification_toggle.html index 42bfe40e..4cee1970 100644 --- a/app/templates/community/_notification_toggle.html +++ b/app/templates/community/_notification_toggle.html @@ -1,4 +1,4 @@ - \ No newline at end of file diff --git a/app/templates/post/_post_full.html b/app/templates/post/_post_full.html index 39eabe87..db5d1f85 100644 --- a/app/templates/post/_post_full.html +++ b/app/templates/post/_post_full.html @@ -12,7 +12,11 @@
{% include "post/_post_voting_buttons.html" %}
-

{{ post.title }}

+

{{ post.title }} + {% if current_user.is_authenticated and post.user_id == current_user.id %} + {% include 'post/_post_notification_toggle.html' %} + {% endif %} +

{% if post.url %}

{{ post.url|shorten_url }} External link @@ -53,7 +57,11 @@

-

{{ post.title }}

+

{{ post.title }} + {% if current_user.is_authenticated and post.user_id == current_user.id %} + {% include 'post/_post_notification_toggle.html' %} + {% endif %} +

{% if post.type == POST_TYPE_LINK and post.image_id and not (post.url and 'youtube.com' in post.url) %}
{{ post.image.alt_text }} \ No newline at end of file diff --git a/app/templates/post/_reply_notification_toggle.html b/app/templates/post/_reply_notification_toggle.html new file mode 100644 index 00000000..448e36d8 --- /dev/null +++ b/app/templates/post/_reply_notification_toggle.html @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/app/templates/post/post.html b/app/templates/post/post.html index 8b2b10ed..386f43ba 100644 --- a/app/templates/post/post.html +++ b/app/templates/post/post.html @@ -87,11 +87,13 @@ {% if comment['comment'].author.created_recently() %} {% endif %} - {% if comment['comment'].author.reputation < -10 %} - - - {% elif comment['comment'].author.reputation < 0 %} - + {% if comment['comment'].author.id != current_user.id %} + {% if comment['comment'].author.reputation < -10 %} + + + {% elif comment['comment'].author.reputation < 0 %} + + {% endif %} {% endif %} {% if comment['comment'].author.id == post.author.id %}[OP]{% endif %} {{ moment(comment['comment'].posted_at).fromNow(refresh=True) }}{% if comment['comment'].edited_at %}, edited {{ moment(comment['comment'].edited_at).fromNow(refresh=True) }} {% endif %} @@ -108,6 +110,9 @@ {% if post.comments_enabled %} reply {% endif %} + {% if current_user.id == comment['comment'].author.id %} + {% include "post/_reply_notification_toggle.html" %} + {% endif %} {% endif %}