Merge pull request 'Make notifications open comments below THREAD_CUTOFF_DEPTH (fixes: #301)' (#302) from h3ndrik/pyfedi:cutoff_notification into main

Reviewed-on: https://codeberg.org/rimu/pyfedi/pulls/302
This commit is contained in:
rimu 2024-08-19 19:01:55 +00:00
commit e4663ea3a3

View file

@ -1921,10 +1921,16 @@ def notify_about_post_reply(parent_reply: Union[PostReply, None], new_reply: Pos
send_notifs_to = set(notification_subscribers(parent_reply.id, NOTIF_REPLY))
for notify_id in send_notifs_to:
if new_reply.user_id != notify_id:
new_notification = Notification(title=shorten_string(_('Reply to comment on %(post_title)s',
post_title=parent_reply.post.title), 50),
url=f"/post/{parent_reply.post.id}#comment_{new_reply.id}",
user_id=notify_id, author_id=new_reply.user_id)
if new_reply.depth <= THREAD_CUTOFF_DEPTH:
new_notification = Notification(title=shorten_string(_('Reply to comment on %(post_title)s',
post_title=parent_reply.post.title), 50),
url=f"/post/{parent_reply.post.id}#comment_{new_reply.id}",
user_id=notify_id, author_id=new_reply.user_id)
else:
new_notification = Notification(title=shorten_string(_('Reply to comment on %(post_title)s',
post_title=parent_reply.post.title), 50),
url=f"/post/{parent_reply.post.id}/comment/{parent_reply.id}#comment_{new_reply.id}",
user_id=notify_id, author_id=new_reply.user_id)
db.session.add(new_notification)
user = User.query.get(notify_id)
user.unread_notifications += 1