forked from rDrama/rDrama
dont generate notifs for removed posts and comments except to jannies
parent
8c6ca188bd
commit
1d477b5c72
|
@ -134,7 +134,7 @@ def add_notif(cid, uid, text, pushnotif_url=''):
|
||||||
push_notif({uid}, 'New notification', text, pushnotif_url)
|
push_notif({uid}, 'New notification', text, pushnotif_url)
|
||||||
|
|
||||||
|
|
||||||
def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None, followers_ping=True, commenters_ping_post_id=None):
|
def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=True, commenters_ping_post_id=None):
|
||||||
# Restrict young accounts from generating notifications
|
# Restrict young accounts from generating notifications
|
||||||
if v.age < NOTIFICATION_SPAM_AGE_THRESHOLD:
|
if v.age < NOTIFICATION_SPAM_AGE_THRESHOLD:
|
||||||
return set()
|
return set()
|
||||||
|
@ -163,9 +163,6 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None, followers_pi
|
||||||
admin_ids = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_SPECIFIC_WPD_COMMENTS'])]
|
admin_ids = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_SPECIFIC_WPD_COMMENTS'])]
|
||||||
notify_users.update(admin_ids)
|
notify_users.update(admin_ids)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if FEATURES['PING_GROUPS']:
|
if FEATURES['PING_GROUPS']:
|
||||||
cost = 0
|
cost = 0
|
||||||
coin_receivers = set()
|
coin_receivers = set()
|
||||||
|
@ -180,8 +177,8 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None, followers_pi
|
||||||
abort(403, f"You need {cost} currency to mention these ping groups!")
|
abort(403, f"You need {cost} currency to mention these ping groups!")
|
||||||
|
|
||||||
v.charge_account('combined', cost)
|
v.charge_account('combined', cost)
|
||||||
if log_cost:
|
if obj:
|
||||||
log_cost.ping_cost += cost
|
obj.ping_cost += cost
|
||||||
return 'everyone'
|
return 'everyone'
|
||||||
elif i.group(1) == 'jannies':
|
elif i.group(1) == 'jannies':
|
||||||
group = None
|
group = None
|
||||||
|
@ -217,8 +214,8 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None, followers_pi
|
||||||
|
|
||||||
if cost:
|
if cost:
|
||||||
v.charge_account('combined', cost)
|
v.charge_account('combined', cost)
|
||||||
if log_cost:
|
if obj:
|
||||||
log_cost.ping_cost += cost
|
obj.ping_cost += cost
|
||||||
|
|
||||||
if coin_receivers:
|
if coin_receivers:
|
||||||
g.db.query(User).options(load_only(User.id)).filter(User.id.in_(coin_receivers)).update({ User.coins: User.coins + 10 })
|
g.db.query(User).options(load_only(User.id)).filter(User.id.in_(coin_receivers)).update({ User.coins: User.coins + 10 })
|
||||||
|
@ -226,6 +223,9 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None, followers_pi
|
||||||
if len(notify_users) > 400 and v.admin_level < PERMS['POST_COMMENT_INFINITE_PINGS']:
|
if len(notify_users) > 400 and v.admin_level < PERMS['POST_COMMENT_INFINITE_PINGS']:
|
||||||
abort(403, "You can only notify a maximum of 400 users.")
|
abort(403, "You can only notify a maximum of 400 users.")
|
||||||
|
|
||||||
|
if v.shadowbanned or obj.is_banned:
|
||||||
|
notify_users = [x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['USER_SHADOWBAN']).all()]
|
||||||
|
|
||||||
return notify_users - BOT_IDs - {v.id, 0} - v.all_twoway_blocks - v.muters
|
return notify_users - BOT_IDs - {v.id, 0} - v.all_twoway_blocks - v.muters
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1392,9 +1392,6 @@ def remove_post(post_id, v):
|
||||||
def approve_post(post_id, v):
|
def approve_post(post_id, v):
|
||||||
post = get_post(post_id)
|
post = get_post(post_id)
|
||||||
|
|
||||||
if not complies_with_chud(post):
|
|
||||||
abort(400, "You can't bypass the chud award!")
|
|
||||||
|
|
||||||
if post.is_banned:
|
if post.is_banned:
|
||||||
ma=ModAction(
|
ma=ModAction(
|
||||||
kind="unban_post",
|
kind="unban_post",
|
||||||
|
@ -1641,9 +1638,6 @@ def remove_comment(c_id, v):
|
||||||
def approve_comment(c_id, v):
|
def approve_comment(c_id, v):
|
||||||
comment = get_comment(c_id)
|
comment = get_comment(c_id)
|
||||||
|
|
||||||
if not complies_with_chud(comment):
|
|
||||||
abort(400, "You can't bypass the chud award!")
|
|
||||||
|
|
||||||
if comment.is_banned:
|
if comment.is_banned:
|
||||||
ma=ModAction(
|
ma=ModAction(
|
||||||
kind="unban_comment",
|
kind="unban_comment",
|
||||||
|
|
|
@ -348,7 +348,7 @@ def comment(v):
|
||||||
execute_longpostbot(c, level, body, body_html, post_target, v)
|
execute_longpostbot(c, level, body, body_html, post_target, v)
|
||||||
execute_zozbot(c, level, post_target, v)
|
execute_zozbot(c, level, post_target, v)
|
||||||
|
|
||||||
notify_users = NOTIFY_USERS(body, v, ghost=c.ghost, log_cost=c, commenters_ping_post_id=commenters_ping_post_id)
|
notify_users = NOTIFY_USERS(body, v, ghost=c.ghost, obj=c, commenters_ping_post_id=commenters_ping_post_id)
|
||||||
|
|
||||||
if notify_users == 'everyone':
|
if notify_users == 'everyone':
|
||||||
alert_everyone(c.id)
|
alert_everyone(c.id)
|
||||||
|
@ -367,7 +367,7 @@ def comment(v):
|
||||||
|
|
||||||
notify_users -= BOT_IDs
|
notify_users -= BOT_IDs
|
||||||
|
|
||||||
if v.shadowbanned:
|
if v.shadowbanned or c.is_banned:
|
||||||
notify_users = [x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['USER_SHADOWBAN']).all()]
|
notify_users = [x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['USER_SHADOWBAN']).all()]
|
||||||
|
|
||||||
for x in notify_users:
|
for x in notify_users:
|
||||||
|
@ -705,16 +705,13 @@ def edit_comment(cid, v):
|
||||||
|
|
||||||
g.db.add(c)
|
g.db.add(c)
|
||||||
|
|
||||||
notify_users = NOTIFY_USERS(body, v, oldtext=oldtext, ghost=c.ghost, log_cost=c, commenters_ping_post_id=c.parent_post)
|
notify_users = NOTIFY_USERS(body, v, oldtext=oldtext, ghost=c.ghost, obj=c, commenters_ping_post_id=c.parent_post)
|
||||||
|
|
||||||
if notify_users == 'everyone':
|
if notify_users == 'everyone':
|
||||||
alert_everyone(c.id)
|
alert_everyone(c.id)
|
||||||
else:
|
else:
|
||||||
notify_users -= BOT_IDs
|
notify_users -= BOT_IDs
|
||||||
|
|
||||||
if v.shadowbanned:
|
|
||||||
notify_users = [x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['USER_SHADOWBAN']).all()]
|
|
||||||
|
|
||||||
for x in notify_users:
|
for x in notify_users:
|
||||||
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=x).one_or_none()
|
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=x).one_or_none()
|
||||||
if not notif:
|
if not notif:
|
||||||
|
|
|
@ -60,7 +60,7 @@ def publish(pid, v):
|
||||||
p.created_utc = int(time.time())
|
p.created_utc = int(time.time())
|
||||||
g.db.add(p)
|
g.db.add(p)
|
||||||
|
|
||||||
notify_users = NOTIFY_USERS(f'{p.title} {p.body}', v, ghost=p.ghost, log_cost=p, followers_ping=False)
|
notify_users = NOTIFY_USERS(f'{p.title} {p.body}', v, ghost=p.ghost, obj=p, followers_ping=False)
|
||||||
|
|
||||||
if notify_users:
|
if notify_users:
|
||||||
cid, text = notif_comment2(p)
|
cid, text = notif_comment2(p)
|
||||||
|
@ -634,17 +634,6 @@ def submit_post(v, hole=None):
|
||||||
else:
|
else:
|
||||||
abort(415)
|
abort(415)
|
||||||
|
|
||||||
if not p.private:
|
|
||||||
notify_users = NOTIFY_USERS(f'{title} {body}', v, ghost=p.ghost, log_cost=p, followers_ping=False)
|
|
||||||
|
|
||||||
if notify_users:
|
|
||||||
cid, text = notif_comment2(p)
|
|
||||||
if notify_users == 'everyone':
|
|
||||||
alert_everyone(cid)
|
|
||||||
else:
|
|
||||||
for x in notify_users:
|
|
||||||
add_notif(cid, x, text, pushnotif_url=p.permalink)
|
|
||||||
|
|
||||||
if not complies_with_chud(p):
|
if not complies_with_chud(p):
|
||||||
p.is_banned = True
|
p.is_banned = True
|
||||||
p.ban_reason = "AutoJanny"
|
p.ban_reason = "AutoJanny"
|
||||||
|
@ -680,6 +669,17 @@ def submit_post(v, hole=None):
|
||||||
autojanny.comment_count += 1
|
autojanny.comment_count += 1
|
||||||
g.db.add(autojanny)
|
g.db.add(autojanny)
|
||||||
|
|
||||||
|
if not p.private:
|
||||||
|
notify_users = NOTIFY_USERS(f'{title} {body}', v, ghost=p.ghost, obj=p, followers_ping=False)
|
||||||
|
|
||||||
|
if notify_users:
|
||||||
|
cid, text = notif_comment2(p)
|
||||||
|
if notify_users == 'everyone':
|
||||||
|
alert_everyone(cid)
|
||||||
|
else:
|
||||||
|
for x in notify_users:
|
||||||
|
add_notif(cid, x, text, pushnotif_url=p.permalink)
|
||||||
|
|
||||||
v.post_count += 1
|
v.post_count += 1
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
|
|
||||||
|
@ -1000,7 +1000,7 @@ def edit_post(pid, v):
|
||||||
|
|
||||||
|
|
||||||
if not p.private:
|
if not p.private:
|
||||||
notify_users = NOTIFY_USERS(f'{title} {body}', v, oldtext=f'{p.title} {p.body}', ghost=p.ghost, log_cost=p, followers_ping=False)
|
notify_users = NOTIFY_USERS(f'{title} {body}', v, oldtext=f'{p.title} {p.body}', ghost=p.ghost, obj=p, followers_ping=False)
|
||||||
if notify_users:
|
if notify_users:
|
||||||
cid, text = notif_comment2(p)
|
cid, text = notif_comment2(p)
|
||||||
if notify_users == 'everyone':
|
if notify_users == 'everyone':
|
||||||
|
|
Loading…
Reference in New Issue