[themotte/rDrama#451] Move the pusher_thread() function from files/routes/comment.py to files/helpers/comment.py
This commit is contained in:
parent
e94971c7b9
commit
4a6ed37166
2 changed files with 37 additions and 36 deletions
|
@ -1,7 +1,43 @@
|
||||||
|
from pusher_push_notifications import PushNotifications
|
||||||
from files.classes import Comment, Notification, Subscription
|
from files.classes import Comment, Notification, Subscription
|
||||||
from files.helpers.alerts import NOTIFY_USERS
|
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 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):
|
def update_stateful_counters(comment, delta):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,48 +4,13 @@ from files.helpers.images import *
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
from files.helpers.comments import comment_on_publish
|
from files.helpers.comments import comment_on_publish
|
||||||
from files.classes import *
|
from files.classes import *
|
||||||
from pusher_push_notifications import PushNotifications
|
|
||||||
from flask import *
|
from flask import *
|
||||||
from files.__main__ import app, limiter
|
from files.__main__ import app, limiter
|
||||||
from files.helpers.sanitize import filter_emojis_only
|
from files.helpers.sanitize import filter_emojis_only
|
||||||
from files.helpers.assetcache import assetcache_path
|
|
||||||
import requests
|
import requests
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from json import loads
|
from json import loads
|
||||||
from collections import Counter
|
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/<cid>")
|
@app.get("/comment/<cid>")
|
||||||
@app.get("/post/<pid>/<anything>/<cid>")
|
@app.get("/post/<pid>/<anything>/<cid>")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue