From d31d6b8617602caa948c5cb5cdd0359fac654221 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 27 Jun 2022 20:42:41 +0200 Subject: [PATCH] restore push notifs --- files/routes/comments.py | 10 +++--- files/routes/users.py | 64 +++++++++++++++++++-------------------- files/templates/home.html | 20 ++++++------ 3 files changed, 46 insertions(+), 48 deletions(-) diff --git a/files/routes/comments.py b/files/routes/comments.py index c248590f5..9d38e0b0d 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -26,8 +26,8 @@ import os d = Dict("en_US") -# if PUSHER_ID != 'blahblahblah': -# beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY) +if PUSHER_ID != 'blahblahblah': + beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY) WORDLE_COLOR_MAPPINGS = {-1: "🟥", 0: "🟨", 1: "🟩"} @@ -597,9 +597,9 @@ def api_comment(v): n = Notification(comment_id=c.id, user_id=x) g.db.add(n) - # if parent.author.id != v.id and PUSHER_ID != 'blahblahblah' and not v.shadowbanned: - # try: gevent.spawn(pusher_thread, f'{request.host}{parent.author.id}', c, c.author_name) - # except: pass + if parent.author.id != v.id and PUSHER_ID != 'blahblahblah' and not v.shadowbanned: + try: gevent.spawn(pusher_thread, f'{request.host}{parent.author.id}', c, c.author_name) + except: pass diff --git a/files/routes/users.py b/files/routes/users.py index 20bec311c..4a51a26d9 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -17,8 +17,8 @@ import gevent from sys import stdout import os -# if PUSHER_ID != 'blahblahblah': -# beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY) +if PUSHER_ID != 'blahblahblah': + beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY) def pusher_thread2(interests, notifbody, username): beams_client.publish_to_interests( @@ -707,12 +707,12 @@ def message2(v, username): g.db.add(notif) - # if PUSHER_ID != 'blahblahblah' and not v.shadowbanned: - # if len(message) > 500: notifbody = message[:500] + '...' - # else: notifbody = message + if PUSHER_ID != 'blahblahblah' and not v.shadowbanned: + if len(message) > 500: notifbody = message[:500] + '...' + else: notifbody = message - # try: gevent.spawn(pusher_thread2, f'{request.host}{user.id}', notifbody, v.username) - # except: pass + try: gevent.spawn(pusher_thread2, f'{request.host}{user.id}', notifbody, v.username) + except: pass return {"message": "Message sent!"} @@ -773,32 +773,32 @@ def messagereply(v): for n in notifications: g.db.delete(n) - # if PUSHER_ID != 'blahblahblah' and not v.shadowbanned: - # if len(body) > 500: notifbody = body[:500] + '...' - # else: notifbody = body + if PUSHER_ID != 'blahblahblah' and not v.shadowbanned: + if len(body) > 500: notifbody = body[:500] + '...' + else: notifbody = body - # beams_client.publish_to_interests( - # interests=[f'{request.host}{user_id}'], - # publish_body={ - # 'web': { - # 'notification': { - # 'title': f'New message from @{v.username}', - # 'body': notifbody, - # 'deep_link': f'{SITE_FULL}/notifications?messages=true', - # 'icon': f'{SITE_FULL}/assets/images/{SITE_NAME}/icon.webp"a=1015', - # } - # }, - # 'fcm': { - # 'notification': { - # 'title': f'New message from @{v.username}', - # 'body': notifbody, - # }, - # 'data': { - # 'url': '/notifications?messages=true', - # } - # } - # }, - # ) + beams_client.publish_to_interests( + interests=[f'{request.host}{user_id}'], + publish_body={ + 'web': { + 'notification': { + 'title': f'New message from @{v.username}', + 'body': notifbody, + 'deep_link': f'{SITE_FULL}/notifications?messages=true', + 'icon': f'{SITE_FULL}/assets/images/{SITE_NAME}/icon.webp"a=1015', + } + }, + 'fcm': { + 'notification': { + 'title': f'New message from @{v.username}', + 'body': notifbody, + }, + 'data': { + 'url': '/notifications?messages=true', + } + } + }, + ) if c.top_comment.sentto == 2: diff --git a/files/templates/home.html b/files/templates/home.html index b93d85cdc..c132d52a8 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -201,17 +201,15 @@ {% endif %} -{% if False %} - {% if PUSHER_ID != 'blahblahblah' and v %} -
{{request.host}}{{v.id}}
-
{{PUSHER_ID}}
- - - {% endif %} +{% if PUSHER_ID != 'blahblahblah' and v %} +
{{request.host}}{{v.id}}
+
{{PUSHER_ID}}
+ + {% endif %} {% if request.path in ('/','/logged_out','/logged_out/') and time.time() > session.get('tooltip_last_dismissed',0)+60*60*24*30 and not g.webview %}