From ef3564c1a1ad945a5f441e4a5196102edd79a8e2 Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 23 Aug 2023 13:42:25 +0300 Subject: [PATCH] stop using NOTIFICATION_THREAD --- files/helpers/alerts.py | 6 +++--- files/helpers/config/const.py | 3 --- files/helpers/offsitementions.py | 2 +- files/routes/comments.py | 2 +- files/routes/notifications.py | 24 ++++++++++++++++++++++++ files/routes/oauth.py | 2 +- files/templates/notifications.html | 8 ++++++-- 7 files changed, 36 insertions(+), 11 deletions(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 9a2684de9..4f971e5f5 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -41,14 +41,14 @@ def send_repeatable_notification(uid, text): notif = Notification(comment_id=c.id, user_id=uid) g.db.add(notif) - push_notif({uid}, 'New notification', text, f'{SITE_FULL}/comment/{c.id}?read=true#context') + push_notif({uid}, 'New notification', text, f'{SITE_FULL}/notification/{c.id}') return cid = create_comment(text_html) 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') + push_notif({uid}, 'New notification', text, f'{SITE_FULL}/notification/{cid}') def send_notification(uid, text): @@ -111,7 +111,7 @@ def add_notif(cid, uid, text, pushnotif_url=''): g.db.add(notif) if not pushnotif_url: - pushnotif_url = f'{SITE_FULL}/comment/{cid}?read=true#context' + pushnotif_url = f'{SITE_FULL}/notification/{cid}' if ' has mentioned you: [' in text: text = text.split(':')[0] + '!' diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 4dc71a984..e97ede4c3 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -600,7 +600,6 @@ LOTTERY_TICKET_COST = 12 LOTTERY_SINK_RATE = 3 LOTTERY_DURATION = 60 * 60 * 24 * 7 -NOTIFICATION_THREAD = 1 BUG_THREAD = 0 SIDEBAR_THREAD = 0 @@ -675,7 +674,6 @@ if SITE == 'rdrama.net': FEATURES['USERS_PERMANENT_WORD_FILTERS'] = True FEATURES['ASSET_SUBMISSIONS'] = True - NOTIFICATION_THREAD = 6489 BUG_THREAD = 18459 SIDEBAR_THREAD = 37696 @@ -821,7 +819,6 @@ elif SITE == 'watchpeopledie.tv': ERROR_MARSEYS[403] = "marseyconfused" - NOTIFICATION_THREAD = 27855 BUG_THREAD = 56363 SIDEBAR_THREAD = 5403 diff --git a/files/helpers/offsitementions.py b/files/helpers/offsitementions.py index 33c4d0111..4fc95117e 100644 --- a/files/helpers/offsitementions.py +++ b/files/helpers/offsitementions.py @@ -123,4 +123,4 @@ def notify_mentions(mentions, send_to=None, mention_str='site mention'): notif = Notification(comment_id=new_comment.id, user_id=send_to) g.db.add(notif) - push_notif({send_to}, f'New mention of you on reddit by /u/{author}', '', f'{SITE_FULL}/comment/{new_comment.id}?read=true#context') + push_notif({send_to}, f'New mention of you on reddit by /u/{author}', '', f'{SITE_FULL}/notification/{new_comment.id}') diff --git a/files/routes/comments.py b/files/routes/comments.py index 012a9dc91..c7c2071ac 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -54,7 +54,7 @@ def post_pid_comment_cid(cid, v, pid=None, anything=None, sub=None): elif comment.wall_user_id: return redirect(f"/id/{comment.wall_user_id}/wall/comment/{comment.id}") else: - post = NOTIFICATION_THREAD + return redirect(f"/notification/{comment.id}") if v and request.values.get("read"): gevent.spawn(_mark_comment_as_read, comment.id, v.id) diff --git a/files/routes/notifications.py b/files/routes/notifications.py index 148881c8e..1a31da1a5 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -9,6 +9,7 @@ from files.helpers.config.const import * from files.helpers.config.modaction_types import * from files.helpers.get import * from files.routes.wrappers import * +from files.routes.comments import _mark_comment_as_read from files.__main__ import app @app.post("/clear") @@ -422,3 +423,26 @@ def notifications(v): standalone=True, render_replies=True, ) + + +@app.get("/notification//") +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) +@auth_required +def notification(v, cid): + comment = get_comment(cid, v=v) + + if not User.can_see(v, comment): abort(403) + + comment.unread = True + + gevent.spawn(_mark_comment_as_read, comment.id, v.id) + + return render_template("notifications.html", + v=v, + notifications=[comment], + total=1, + page=1, + standalone=True, + render_replies=True, + ) diff --git a/files/routes/oauth.py b/files/routes/oauth.py index 963c527ff..ae1610966 100644 --- a/files/routes/oauth.py +++ b/files/routes/oauth.py @@ -93,7 +93,7 @@ def request_api_keys(v): notif = Notification(comment_id=new_comment.id, user_id=admin_id) g.db.add(notif) - push_notif(admin_ids, 'New notification', body, f'{SITE_FULL}/comment/{new_comment.id}?read=true#context') + push_notif(admin_ids, 'New notification', body, f'{SITE_FULL}/admin/apps') return {"message": "API keys requested successfully!"} diff --git a/files/templates/notifications.html b/files/templates/notifications.html index 9ec436389..8d3ce1139 100644 --- a/files/templates/notifications.html +++ b/files/templates/notifications.html @@ -11,7 +11,7 @@ - +{% if request.path.startswith('/notification/') %} + +{% else %} + +{% endif %}