dont generate notifs for removed posts and comments except to jannies

pull/216/head
Aevann 2023-10-29 15:03:00 +03:00
parent 8c6ca188bd
commit 1d477b5c72
4 changed files with 24 additions and 33 deletions

View File

@ -134,7 +134,7 @@ def add_notif(cid, uid, 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
if v.age < NOTIFICATION_SPAM_AGE_THRESHOLD:
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'])]
notify_users.update(admin_ids)
if FEATURES['PING_GROUPS']:
cost = 0
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!")
v.charge_account('combined', cost)
if log_cost:
log_cost.ping_cost += cost
if obj:
obj.ping_cost += cost
return 'everyone'
elif i.group(1) == 'jannies':
group = None
@ -217,8 +214,8 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None, followers_pi
if cost:
v.charge_account('combined', cost)
if log_cost:
log_cost.ping_cost += cost
if obj:
obj.ping_cost += cost
if coin_receivers:
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']:
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

View File

@ -1392,9 +1392,6 @@ def remove_post(post_id, v):
def approve_post(post_id, v):
post = get_post(post_id)
if not complies_with_chud(post):
abort(400, "You can't bypass the chud award!")
if post.is_banned:
ma=ModAction(
kind="unban_post",
@ -1641,9 +1638,6 @@ def remove_comment(c_id, v):
def approve_comment(c_id, v):
comment = get_comment(c_id)
if not complies_with_chud(comment):
abort(400, "You can't bypass the chud award!")
if comment.is_banned:
ma=ModAction(
kind="unban_comment",

View File

@ -348,7 +348,7 @@ def comment(v):
execute_longpostbot(c, level, body, body_html, 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':
alert_everyone(c.id)
@ -367,7 +367,7 @@ def comment(v):
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()]
for x in notify_users:
@ -705,16 +705,13 @@ def edit_comment(cid, v):
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':
alert_everyone(c.id)
else:
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:
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=x).one_or_none()
if not notif:

View File

@ -60,7 +60,7 @@ def publish(pid, v):
p.created_utc = int(time.time())
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:
cid, text = notif_comment2(p)
@ -634,17 +634,6 @@ def submit_post(v, hole=None):
else:
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):
p.is_banned = True
p.ban_reason = "AutoJanny"
@ -680,6 +669,17 @@ def submit_post(v, hole=None):
autojanny.comment_count += 1
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
g.db.add(v)
@ -1000,7 +1000,7 @@ def edit_post(pid, v):
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:
cid, text = notif_comment2(p)
if notify_users == 'everyone':