From fd9e1c3fec86a9a5713d5d46537b80871ec219fd Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 26 Feb 2023 11:37:44 +0200 Subject: [PATCH] in push notifs: link the post I was mentioned in --- files/helpers/alerts.py | 10 ++++++++-- files/routes/posts.py | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 3625cdcd6..e1e6ac909 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -103,7 +103,7 @@ def notif_comment2(p): return create_comment(text_html), text -def add_notif(cid, uid, text): +def add_notif(cid, uid, text, pushnotif_url): if uid in bots: return existing = g.db.query(Notification.user_id).filter_by(comment_id=cid, user_id=uid).one_or_none() @@ -111,7 +111,13 @@ def add_notif(cid, uid, text): notif = Notification(comment_id=cid, user_id=uid) g.db.add(notif) - push_notif({uid}, 'New notification', text, f'{SITE_FULL}/comment/{cid}?read=true#context') + if not pushnotif_url: + pushnotif_url = f'{SITE_FULL}/comment/{cid}?read=true#context' + + if ' has mentioned you: [' in text: + text = text.split(':')[0] + '!' + + push_notif({uid}, 'New notification', text, pushnotif_url) def NOTIFY_USERS(text, v): diff --git a/files/routes/posts.py b/files/routes/posts.py index 5e66237bc..f0fde7a8e 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -52,7 +52,7 @@ def publish(pid, v): if notify_users: cid, text = notif_comment2(post) for x in notify_users: - add_notif(cid, x, text) + add_notif(cid, x, text, pushnotif_url=post.permalink) cache.delete_memoized(frontlist) @@ -332,7 +332,7 @@ def edit_post(pid, v): if notify_users: cid, text = notif_comment2(p) for x in notify_users: - add_notif(cid, x, text) + add_notif(cid, x, text, pushnotif_url=p.permalink) if v.id == p.author_id: if int(time.time()) - p.created_utc > 60 * 3: p.edited_utc = int(time.time()) @@ -748,7 +748,7 @@ def submit_post(v:User, sub=None): if notify_users: cid, text = notif_comment2(post) for x in notify_users: - add_notif(cid, x, text) + add_notif(cid, x, text, pushnotif_url=post.permalink) if v.agendaposter and not v.marseyawarded and AGENDAPOSTER_PHRASE not in f'{post.body}{post.title}'.lower() and sub != 'chudrama': post.is_banned = True