forked from rDrama/rDrama
refactor push notifs
parent
73190a8164
commit
a0cb5874cc
|
@ -3,6 +3,8 @@ from flask import g
|
|||
from .sanitize import *
|
||||
from .const import *
|
||||
from .regex import *
|
||||
from pusher_push_notifications import PushNotifications
|
||||
from sys import stdout
|
||||
|
||||
def create_comment(text_html, autojanny=False):
|
||||
if autojanny: author_id = AUTOJANNY_ID
|
||||
|
@ -134,3 +136,32 @@ def notify_mod_action(by_id, msg):
|
|||
for admin in send_to:
|
||||
notif = Notification(comment_id=new_comment.id, user_id=admin.id)
|
||||
g.db.add(notif)
|
||||
|
||||
|
||||
if PUSHER_ID != 'blahblahblah':
|
||||
beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY)
|
||||
|
||||
def pusher_thread(interests, title, notifbody, url):
|
||||
beams_client.publish_to_interests(
|
||||
interests=[interests],
|
||||
publish_body={
|
||||
'web': {
|
||||
'notification': {
|
||||
'title': title,
|
||||
'body': notifbody,
|
||||
'deep_link': url,
|
||||
'icon': f'{SITE_FULL}/assets/images/{SITE_NAME}/icon.webp?v=1015',
|
||||
}
|
||||
},
|
||||
'fcm': {
|
||||
'notification': {
|
||||
'title': title,
|
||||
'body': notifbody,
|
||||
},
|
||||
'data': {
|
||||
'url': url,
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
stdout.flush()
|
|
@ -10,6 +10,8 @@ import files.routes.static as route_static
|
|||
from files.routes.subs import sub_inactive_purge_task
|
||||
from files.routes.admin import give_monthly_marseybux_task
|
||||
|
||||
from sys import stdout
|
||||
|
||||
@app.cli.command('cron', help='Run scheduled tasks.')
|
||||
@click.option('--every-5m', is_flag=True, help='Call every 5 minutes.')
|
||||
@click.option('--every-1h', is_flag=True, help='Call every 1 hour.')
|
||||
|
@ -35,3 +37,4 @@ def cron(every_5m, every_1h, every_1d, every_1mo):
|
|||
|
||||
g.db.commit()
|
||||
g.db.close()
|
||||
stdout.flush()
|
|
@ -11,7 +11,6 @@ from files.helpers.get import *
|
|||
from files.classes import *
|
||||
from files.routes.front import comment_idlist
|
||||
from files.routes.static import marsey_list
|
||||
from pusher_push_notifications import PushNotifications
|
||||
from flask import *
|
||||
from files.__main__ import app, limiter
|
||||
from files.helpers.sanitize import filter_emojis_only
|
||||
|
@ -21,44 +20,12 @@ from json import loads
|
|||
from collections import Counter
|
||||
from enchant import Dict
|
||||
import gevent
|
||||
from sys import stdout
|
||||
import os
|
||||
|
||||
d = Dict("en_US")
|
||||
|
||||
if PUSHER_ID != 'blahblahblah':
|
||||
beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY)
|
||||
|
||||
WORDLE_COLOR_MAPPINGS = {-1: "🟥", 0: "🟨", 1: "🟩"}
|
||||
|
||||
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': f'{SITE_FULL}/assets/images/{SITE_NAME}/icon.webp?v=1015',
|
||||
}
|
||||
},
|
||||
'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("/post/<pid>/<anything>/<cid>")
|
||||
@app.get("/h/<sub>/comment/<cid>")
|
||||
|
@ -597,9 +564,17 @@ 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:
|
||||
interests = f'{request.host}{parent.author.id}'
|
||||
|
||||
title = f'New reply by @{c.author_name}'
|
||||
|
||||
if len(c.body) > 500: notifbody = c.body[:500] + '...'
|
||||
else: notifbody = c.body
|
||||
|
||||
url = f'{SITE_FULL}/comment/{c.id}?context=8&read=true#context'
|
||||
|
||||
gevent.spawn(pusher_thread, interests, title, notifbody, url)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,39 +11,11 @@ from flask import *
|
|||
from files.__main__ import app, limiter, db_session
|
||||
import sqlalchemy
|
||||
from sqlalchemy import text
|
||||
from pusher_push_notifications import PushNotifications
|
||||
from collections import Counter
|
||||
import gevent
|
||||
from sys import stdout
|
||||
import os
|
||||
|
||||
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(
|
||||
interests=[interests],
|
||||
publish_body={
|
||||
'web': {
|
||||
'notification': {
|
||||
'title': f'New message from @{username}',
|
||||
'body': notifbody,
|
||||
'deep_link': f'{SITE_FULL}/notifications?messages=true',
|
||||
'icon': f'{SITE_FULL}/assets/images/{SITE_NAME}/icon.webp?v=1015',
|
||||
}
|
||||
},
|
||||
'fcm': {
|
||||
'notification': {
|
||||
'title': f'New message from @{username}',
|
||||
'body': notifbody,
|
||||
},
|
||||
'data': {
|
||||
'url': '/notifications?messages=true',
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
stdout.flush()
|
||||
|
||||
def leaderboard_thread():
|
||||
global users9, users9_25, users13, users13_25
|
||||
|
@ -708,11 +680,16 @@ def message2(v, username):
|
|||
|
||||
|
||||
if PUSHER_ID != 'blahblahblah' and not v.shadowbanned:
|
||||
interests = f'{request.host}{user.id}'
|
||||
|
||||
title = f'New message from @{username}'
|
||||
|
||||
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
|
||||
url = f'{SITE_FULL}/notifications?messages=true'
|
||||
|
||||
gevent.spawn(pusher_thread, interests, title, notifbody, url)
|
||||
|
||||
return {"message": "Message sent!"}
|
||||
|
||||
|
@ -774,31 +751,17 @@ def messagereply(v):
|
|||
g.db.delete(n)
|
||||
|
||||
if PUSHER_ID != 'blahblahblah' and not v.shadowbanned:
|
||||
interests = f'{request.host}{user_id}'
|
||||
|
||||
title = f'New message from @{v.username}'
|
||||
|
||||
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',
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
url = f'{SITE_FULL}/notifications?messages=true'
|
||||
|
||||
gevent.spawn(pusher_thread, interests, title, notifbody, url)
|
||||
|
||||
|
||||
|
||||
if c.top_comment.sentto == 2:
|
||||
|
|
Loading…
Reference in New Issue