From 4a6ed371669607e5370f2ce5464d41f4abf55bd2 Mon Sep 17 00:00:00 2001 From: faul_sname Date: Mon, 9 Jan 2023 00:07:49 -0800 Subject: [PATCH] [themotte/rDrama#451] Move the pusher_thread() function from files/routes/comment.py to files/helpers/comment.py --- files/helpers/comments.py | 38 +++++++++++++++++++++++++++++++++++++- files/routes/comments.py | 35 ----------------------------------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/files/helpers/comments.py b/files/helpers/comments.py index 42139a90e..60d934131 100644 --- a/files/helpers/comments.py +++ b/files/helpers/comments.py @@ -1,7 +1,43 @@ +from pusher_push_notifications import PushNotifications from files.classes import Comment, Notification, Subscription from files.helpers.alerts import NOTIFY_USERS -from files.helpers.const import PUSHER_ID +from files.helpers.const import PUSHER_ID, PUSHER_KEY, SITE_ID, SITE_FULL +from files.helpers.assetcache import assetcache_path from flask import g +from sys import stdout +import gevent + +if PUSHER_ID != 'blahblahblah': + beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY) + +def pusher_thread(interests, c, username): + if len(c.body) > 500: notifbody = c.body[:500] + '...' + else: notifbody = c.body + + beams_client.publish_to_interests( + interests=[interests], + publish_body={ + 'web': { + 'notification': { + 'title': f'New reply by @{username}', + 'body': notifbody, + 'deep_link': f'{SITE_FULL}/comment/{c.id}?context=8&read=true#context', + 'icon': SITE_FULL + assetcache_path(f'images/{SITE_ID}/icon.webp'), + } + }, + 'fcm': { + 'notification': { + 'title': f'New reply by @{username}', + 'body': notifbody, + }, + 'data': { + 'url': f'/comment/{c.id}?context=8&read=true#context', + } + } + }, + ) + stdout.flush() + def update_stateful_counters(comment, delta): """ diff --git a/files/routes/comments.py b/files/routes/comments.py index 72656a581..587b7d9aa 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -4,48 +4,13 @@ from files.helpers.images import * from files.helpers.const import * from files.helpers.comments import comment_on_publish from files.classes import * -from pusher_push_notifications import PushNotifications from flask import * from files.__main__ import app, limiter from files.helpers.sanitize import filter_emojis_only -from files.helpers.assetcache import assetcache_path import requests from shutil import copyfile from json import loads from collections import Counter -import gevent -from sys import stdout - -if PUSHER_ID != 'blahblahblah': - beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY) - -def pusher_thread(interests, c, username): - if len(c.body) > 500: notifbody = c.body[:500] + '...' - else: notifbody = c.body - - beams_client.publish_to_interests( - interests=[interests], - publish_body={ - 'web': { - 'notification': { - 'title': f'New reply by @{username}', - 'body': notifbody, - 'deep_link': f'{SITE_FULL}/comment/{c.id}?context=8&read=true#context', - 'icon': SITE_FULL + assetcache_path(f'images/{SITE_ID}/icon.webp'), - } - }, - 'fcm': { - 'notification': { - 'title': f'New reply by @{username}', - 'body': notifbody, - }, - 'data': { - 'url': f'/comment/{c.id}?context=8&read=true#context', - } - } - }, - ) - stdout.flush() @app.get("/comment/") @app.get("/post///")