notification toggles

This commit is contained in:
rimu 2024-01-10 09:34:58 +13:00
parent 6fba6ef113
commit bdcb17e3c1
6 changed files with 50 additions and 9 deletions

View file

@ -830,4 +830,24 @@ def post_reply_delete(post_id: int, comment_id: int):
post.flush_cache() post.flush_cache()
flash(_('Comment deleted.')) flash(_('Comment deleted.'))
# todo: federate delete # todo: federate delete
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>/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/<int:post_reply_id>/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})

View file

@ -1,4 +1,4 @@
<a href="/community/{{ community.id }}/notification" <a href="/community/{{ community.id }}/notification" rel="nofollow"
class="fe {{ 'fe-bell' if community.notify_new_posts(current_user.id) else 'fe-no-bell' }} no-underline" class="fe {{ 'fe-bell' if community.notify_new_posts(current_user.id) else 'fe-no-bell' }} no-underline"
hx-post="/community/{{ community.id }}/notification" hx-trigger="click throttle:1s" hx-swap="outerHTML" hx-post="/community/{{ community.id }}/notification" hx-trigger="click throttle:1s" hx-swap="outerHTML"
title="{{ _('Notify about every new post. Not advisable in high traffic communities!') }}"></a> title="{{ _('Notify about every new post. Not advisable in high traffic communities!') }}"></a>

View file

@ -12,7 +12,11 @@
<div class="voting_buttons"> <div class="voting_buttons">
{% include "post/_post_voting_buttons.html" %} {% include "post/_post_voting_buttons.html" %}
</div> </div>
<h1 class="mt-2 post_title">{{ post.title }}</h1> <h1 class="mt-2 post_title">{{ post.title }}
{% if current_user.is_authenticated and post.user_id == current_user.id %}
{% include 'post/_post_notification_toggle.html' %}
{% endif %}
</h1>
{% if post.url %} {% if post.url %}
<p><small><a href="{{ post.url }}" rel="nofollow ugc" target="_blank">{{ post.url|shorten_url }} <p><small><a href="{{ post.url }}" rel="nofollow ugc" target="_blank">{{ post.url|shorten_url }}
<img src="/static/images/external_link_black.svg" class="external_link_icon" alt="External link" /> <img src="/static/images/external_link_black.svg" class="external_link_icon" alt="External link" />
@ -53,7 +57,11 @@
<div class="voting_buttons"> <div class="voting_buttons">
{% include "post/_post_voting_buttons.html" %} {% include "post/_post_voting_buttons.html" %}
</div> </div>
<h1 class="mt-2 post_title">{{ post.title }}</h1> <h1 class="mt-2 post_title">{{ post.title }}
{% if current_user.is_authenticated and post.user_id == current_user.id %}
{% include 'post/_post_notification_toggle.html' %}
{% endif %}
</h1>
{% if post.type == POST_TYPE_LINK and post.image_id and not (post.url and 'youtube.com' in post.url) %} {% if post.type == POST_TYPE_LINK and post.image_id and not (post.url and 'youtube.com' in post.url) %}
<div class="url_thumbnail"> <div class="url_thumbnail">
<a href="{{ post.url }}" target="_blank"><img src="{{ post.image.thumbnail_url() }}" alt="{{ post.image.alt_text }}" <a href="{{ post.url }}" target="_blank"><img src="{{ post.image.thumbnail_url() }}" alt="{{ post.image.alt_text }}"

View file

@ -0,0 +1,4 @@
<a href="{{ url_for('post.post_notification', post_id=post.id) }}" rel="nofollow"
class="small fe {{ 'fe-bell' if post.notify_author else 'fe-no-bell' }} no-underline"
hx-post="{{ url_for('post.post_notification', post_id=post.id) }}" hx-trigger="click throttle:1s" hx-swap="outerHTML"
title="{{ _('Notify about replies') }}"></a>

View file

@ -0,0 +1,4 @@
<a href="{{ url_for('post.post_reply_notification', post_reply_id=comment['comment'].id) }}" rel="nofollow"
class="pl-2 small fe {{ 'fe-bell' if comment['comment'].notify_author else 'fe-no-bell' }} no-underline"
hx-post="{{ url_for('post.post_reply_notification', post_reply_id=comment['comment'].id) }}" hx-trigger="click throttle:1s" hx-swap="outerHTML"
title="{{ _('Notify about replies') }}"></a>

View file

@ -87,11 +87,13 @@
{% if comment['comment'].author.created_recently() %} {% if comment['comment'].author.created_recently() %}
<span class="fe fe-new-account small" title="New account"> </span> <span class="fe fe-new-account small" title="New account"> </span>
{% endif %} {% endif %}
{% if comment['comment'].author.reputation < -10 %} {% if comment['comment'].author.id != current_user.id %}
<span class="fe fe-warning red" title="Very low reputation. Beware."> </span> {% if comment['comment'].author.reputation < -10 %}
<span class="fe fe-warning red" title="Very low reputation. Beware!"> </span> <span class="fe fe-warning red" title="Very low reputation. Beware."> </span>
{% elif comment['comment'].author.reputation < 0 %} <span class="fe fe-warning red" title="Very low reputation. Beware!"> </span>
<span class="fe fe-warning orangered" title="Low reputation."> </span> {% elif comment['comment'].author.reputation < 0 %}
<span class="fe fe-warning orangered" title="Low reputation."> </span>
{% endif %}
{% endif %} {% endif %}
{% if comment['comment'].author.id == post.author.id %}<span title="Submitter of original post" aria-label="submitter" class="small">[OP]</span>{% endif %} {% if comment['comment'].author.id == post.author.id %}<span title="Submitter of original post" aria-label="submitter" class="small">[OP]</span>{% endif %}
<span class="text-muted small">{{ moment(comment['comment'].posted_at).fromNow(refresh=True) }}{% if comment['comment'].edited_at %}, edited {{ moment(comment['comment'].edited_at).fromNow(refresh=True) }} {% endif %}</span> <span class="text-muted small">{{ moment(comment['comment'].posted_at).fromNow(refresh=True) }}{% if comment['comment'].edited_at %}, edited {{ moment(comment['comment'].edited_at).fromNow(refresh=True) }} {% endif %}</span>
@ -108,6 +110,9 @@
{% if post.comments_enabled %} {% if post.comments_enabled %}
<a href="{{ url_for('post.add_reply', post_id=post.id, comment_id=comment['comment'].id) }}" rel="nofollow"><span class="fe fe-reply"></span> reply</a> <a href="{{ url_for('post.add_reply', post_id=post.id, comment_id=comment['comment'].id) }}" rel="nofollow"><span class="fe fe-reply"></span> reply</a>
{% endif %} {% endif %}
{% if current_user.id == comment['comment'].author.id %}
{% include "post/_reply_notification_toggle.html" %}
{% endif %}
{% endif %} {% endif %}
<a href="{{ url_for('post.post_reply_options', post_id=post.id, comment_id=comment['comment'].id) }}" class="comment_actions_link" rel="nofollow"><span class="fe fe-options" title="Options"> </span></a> <a href="{{ url_for('post.post_reply_options', post_id=post.id, comment_id=comment['comment'].id) }}" class="comment_actions_link" rel="nofollow"><span class="fe fe-options" title="Options"> </span></a>
</div> </div>