diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index a602b30a1..7b1338de3 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -143,16 +143,18 @@ def NOTIFY_USERS(text, v): return notify_users - bots - {v.id, 0} -def push_notif(uids, title, body, url): +def push_notif(uids, title, body, url_or_comment): if VAPID_PUBLIC_KEY == DEFAULT_CONFIG_VALUE: return - if isinstance(url, tuple): - cid, posting_to_submission = url - if posting_to_submission: - url = f'{SITE_FULL}/comment/{cid}?read=true#context' + if isinstance(url_or_comment, Comment): + c = url_or_comment + if c.wall_user_id: + url = f'{SITE_FULL}/@{c.wall_user.username}/wall/comment/{c.id}?read=true#context' else: - url = f'{SITE_FULL}/@{c.wall_user.username}/wall/comment/{cid}?read=true#context' + url = f'{SITE_FULL}/comment/{c.id}?read=true#context' + else: + url = url_or_comment if len(body) > PUSH_NOTIF_LIMIT: body = body[:PUSH_NOTIF_LIMIT] + "..." diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index c1bc6ecc0..1d036a9fd 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -227,7 +227,7 @@ def execute_blackjack(v, target, body, type): n = Notification(comment_id=target.id, user_id=id) g.db.add(n) - push_notif(notified_ids, f'Blackjack by @{v.username}', target.body, (target.id,bool(target.wall_user_id))) + push_notif(notified_ids, f'Blackjack by @{v.username}', target.body, target) extra_info = None diff --git a/files/routes/comments.py b/files/routes/comments.py index 3ad5da0ce..8ebb71c7f 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -305,14 +305,14 @@ def comment(v:User): if not v.shadowbanned: notify_users = NOTIFY_USERS(body, v) - push_notif(notify_users, f'New mention of you by @{v.username}', c.body, (c.id,bool(c.wall_user_id))) + push_notif(notify_users, f'New mention of you by @{v.username}', c.body, c) if c.level == 1 and posting_to_submission: subscriber_ids = [x[0] for x in g.db.query(Subscription.user_id).filter(Subscription.submission_id == post_target.id, Subscription.user_id != v.id).all()] notify_users.update(subscriber_ids) - push_notif(subscriber_ids, f'New comment in subscribed thread by @{v.username}', c.body, (c.id,bool(c.wall_user_id))) + push_notif(subscriber_ids, f'New comment in subscribed thread by @{v.username}', c.body, c) if parent_user.id != v.id: notify_users.add(parent_user.id) @@ -443,7 +443,7 @@ def edit_comment(cid, v): n = Notification(comment_id=c.id, user_id=x) g.db.add(n) if not v.shadowbanned: - push_notif({x}, f'New mention of you by @{v.username}', c.body, (c.id,bool(c.wall_user_id))) + push_notif({x}, f'New mention of you by @{v.username}', c.body, c) g.db.commit() return {"body": c.body, "comment": c.realbody(v)}