add push notifs to add_notif()
parent
5a511c00a8
commit
3e7ccb7756
|
@ -54,7 +54,7 @@ def send_notification(uid, text):
|
|||
|
||||
if uid in bots: return
|
||||
cid = notif_comment(text)
|
||||
add_notif(cid, uid)
|
||||
add_notif(cid, uid, text)
|
||||
|
||||
|
||||
def notif_comment(text):
|
||||
|
@ -92,19 +92,20 @@ def notif_comment(text):
|
|||
|
||||
def notif_comment2(p):
|
||||
|
||||
text = f"@{p.author.username} has mentioned you: [{p.title}](/post/{p.id})"
|
||||
|
||||
search_html = f'%</a> has mentioned you: <a href="/post/{p.id}">%'
|
||||
|
||||
existing = g.db.query(Comment.id).filter(Comment.author_id == AUTOJANNY_ID, Comment.parent_submission == None, Comment.body_html.like(search_html)).first()
|
||||
|
||||
if existing: return existing[0]
|
||||
if existing: return existing[0], text
|
||||
else:
|
||||
text = f"@{p.author.username} has mentioned you: [{p.title}](/post/{p.id})"
|
||||
if p.sub: text += f" in <a href='/h/{p.sub}'>/h/{p.sub}"
|
||||
text_html = sanitize(text, blackjack="notification")
|
||||
return create_comment(text_html)
|
||||
return create_comment(text_html), text
|
||||
|
||||
|
||||
def add_notif(cid, uid):
|
||||
def add_notif(cid, uid, text):
|
||||
if uid in bots: return
|
||||
|
||||
existing = g.db.query(Notification.user_id).filter_by(comment_id=cid, user_id=uid).one_or_none()
|
||||
|
@ -112,6 +113,9 @@ def add_notif(cid, uid):
|
|||
notif = Notification(comment_id=cid, user_id=uid)
|
||||
g.db.add(notif)
|
||||
|
||||
g.db.flush()
|
||||
push_notif({uid}, 'New notification', text, f'{SITE_FULL}/comment/{cid}?read=true#context')
|
||||
|
||||
|
||||
def NOTIFY_USERS(text, v):
|
||||
# Restrict young accounts from generating notifications
|
||||
|
|
|
@ -170,20 +170,21 @@ def distribute(v:User, option_id):
|
|||
votes = option.votes
|
||||
coinsperperson = int(pool / len(votes))
|
||||
|
||||
cid = notif_comment(f"You won {coinsperperson} coins betting on [{post.title}]({post.shortlink}) :marseyparty:")
|
||||
text = f"You won {coinsperperson} coins betting on [{post.title}]({post.shortlink}) :marseyparty:"
|
||||
cid = notif_comment(text)
|
||||
for vote in votes:
|
||||
u = vote.user
|
||||
u.pay_account('coins', coinsperperson)
|
||||
add_notif(cid, u.id)
|
||||
add_notif(cid, u.id, text)
|
||||
|
||||
|
||||
cid = notif_comment(f"You lost the {POLL_BET_COINS} coins you bet on [{post.title}]({post.shortlink}) :marseylaugh:")
|
||||
text = f"You lost the {POLL_BET_COINS} coins you bet on [{post.title}]({post.shortlink}) :marseylaugh:"
|
||||
cid = notif_comment(text)
|
||||
losing_voters = []
|
||||
for o in post.options:
|
||||
if o.exclusive == 2:
|
||||
losing_voters.extend([x.user_id for x in o.votes])
|
||||
for uid in losing_voters:
|
||||
add_notif(cid, uid)
|
||||
add_notif(cid, uid, text)
|
||||
|
||||
ma = ModAction(
|
||||
kind="distribute",
|
||||
|
|
|
@ -49,9 +49,9 @@ def publish(pid, v):
|
|||
notify_users = NOTIFY_USERS(f'{post.title} {post.body}', v)
|
||||
|
||||
if notify_users:
|
||||
cid = notif_comment2(post)
|
||||
cid, text = notif_comment2(post)
|
||||
for x in notify_users:
|
||||
add_notif(cid, x)
|
||||
add_notif(cid, x, text)
|
||||
|
||||
|
||||
cache.delete_memoized(frontlist)
|
||||
|
@ -326,9 +326,9 @@ def edit_post(pid, v):
|
|||
if not p.private and not p.ghost:
|
||||
notify_users = NOTIFY_USERS(f'{p.title} {p.body}', v)
|
||||
if notify_users:
|
||||
cid = notif_comment2(p)
|
||||
cid, text = notif_comment2(p)
|
||||
for x in notify_users:
|
||||
add_notif(cid, x)
|
||||
add_notif(cid, x, text)
|
||||
|
||||
if v.id == p.author_id:
|
||||
if int(time.time()) - p.created_utc > 60 * 3: p.edited_utc = int(time.time())
|
||||
|
@ -739,9 +739,9 @@ def submit_post(v:User, sub=None):
|
|||
notify_users = NOTIFY_USERS(f'{title} {body}', v)
|
||||
|
||||
if notify_users:
|
||||
cid = notif_comment2(post)
|
||||
cid, text = notif_comment2(post)
|
||||
for x in notify_users:
|
||||
add_notif(cid, x)
|
||||
add_notif(cid, x, text)
|
||||
|
||||
if v.agendaposter and not v.marseyawarded and AGENDAPOSTER_PHRASE not in f'{post.body}{post.title}'.lower() and sub != 'chudrama':
|
||||
post.is_banned = True
|
||||
|
|
|
@ -252,9 +252,10 @@ def settings_personal_post(v):
|
|||
notify_users = NOTIFY_USERS(friends, v)
|
||||
|
||||
if notify_users:
|
||||
cid = notif_comment(f"@{v.username} has added you to their friends list!")
|
||||
text = f"@{v.username} has added you to their friends list!"
|
||||
cid = notif_comment(text)
|
||||
for x in notify_users:
|
||||
add_notif(cid, x)
|
||||
add_notif(cid, x, text)
|
||||
|
||||
v.friends = friends[:1000]
|
||||
v.friends_html=friends_html
|
||||
|
@ -276,9 +277,10 @@ def settings_personal_post(v):
|
|||
|
||||
notify_users = NOTIFY_USERS(enemies, v)
|
||||
if notify_users:
|
||||
cid = notif_comment(f"@{v.username} has added you to their enemies list!")
|
||||
text = f"@{v.username} has added you to their enemies list!"
|
||||
cid = notif_comment(text)
|
||||
for x in notify_users:
|
||||
add_notif(cid, x)
|
||||
add_notif(cid, x, text)
|
||||
|
||||
v.enemies = enemies[:1000]
|
||||
v.enemies_html=enemies_html
|
||||
|
|
Loading…
Reference in New Issue