forked from rDrama/rDrama
1
0
Fork 0

give jannies push notifs for chat

master
Aevann 2022-12-25 22:30:50 +02:00
parent 959e662957
commit c4e4a8d853
4 changed files with 20 additions and 5 deletions

View File

@ -106,14 +106,16 @@ def NOTIFY_USERS(text, v):
return notify_users - bots
def push_notif(uid, title, body, url):
def push_notif(uids, title, body, url):
if uids == {AEVANN_ID}: return
if VAPID_PUBLIC_KEY == DEFAULT_CONFIG_VALUE:
return
if len(body) > PUSH_NOTIF_LIMIT:
body = body[:PUSH_NOTIF_LIMIT] + "..."
subscriptions = g.db.query(PushSubscription.subscription_json).filter_by(user_id=uid).all()
subscriptions = g.db.query(PushSubscription.subscription_json).filter(PushSubscription.user_id.in_(uids)).all()
subscriptions = [x[0] for x in subscriptions]
gevent.spawn(_push_notif_thread, subscriptions, title, body, url)

View File

@ -104,6 +104,19 @@ def speak(data, v):
muted[username] = duration
typing = []
if SITE == 'rdrama.net':
title = f'New chat message from @{v.username}'
notifbody = text
url = f'{SITE_FULL}/chat'
admin_ids = [x[0] for x in g.db.query(User.id).filter(
User.id != v.id,
User.admin_level >= PERMS['CHAT'],
).all()]
push_notif(admin_ids, title, notifbody, url)
return '', 204
@socketio.on('connect')

View File

@ -313,7 +313,7 @@ def comment(v:User):
else:
url = f'{SITE_FULL}/@{c.wall_user.username}/wall/comment/{c.id}?read=true#context'
push_notif(parent_user.id, title, notifbody, url)
push_notif({parent_user.id}, title, notifbody, url)
vote = CommentVote(user_id=v.id,
comment_id=c.id,

View File

@ -491,7 +491,7 @@ def message2(v:User, username:str):
url = f'{SITE_FULL}/notifications/messages'
push_notif(user.id, title, notifbody, url)
push_notif({user.id}, title, notifbody, url)
return {"message": "Message sent!"}
@ -558,7 +558,7 @@ def messagereply(v:User):
url = f'{SITE_FULL}/notifications/messages'
push_notif(user_id, title, notifbody, url)
push_notif({user_id}, title, notifbody, url)
top_comment = c.top_comment(g.db)