diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index d7997e9dd..68c77b2a6 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -133,8 +133,7 @@ def add_notif(cid, uid, text, pushnotif_url='', check_existing=True): if ' has mentioned you: [' in text: text = text.split(':')[0] + '!' - if not request.path.startswith('/submit'): - 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, obj=None, followers_ping=True, commenters_ping_post_id=None, charge=True): @@ -314,14 +313,14 @@ def alert_admins(body): new_comment.top_comment_id = new_comment.id -def alert_active_users(body, v, extra_criteria): +def alert_active_users(body, vid, extra_criteria): body_html = sanitize(body, blackjack="notification") cid = create_comment(body_html) t = time.time() - 604800 notified_users = [x[0] for x in g.db.query(User.id).filter( User.last_active > t, - User.id != v.id, + User.id != vid, extra_criteria, )] for uid in notified_users: diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 43dbb935b..0f61449ca 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -173,7 +173,6 @@ PERMS = { # Minimum admin_level to perform action. 'VIEW_ALT_VOTES': 1, 'VIEW_LAST_ACTIVE': 1, 'ENABLE_VOTE_BUTTONS_ON_USER_PAGE': 1, - 'NOTIFICATIONS_HOLE_INACTIVITY_DELETION': 1, 'NOTIFICATIONS_MODERATOR_ACTIONS': 1, 'EXEMPT_FROM_IP_LOGGING': 1, diff --git a/files/helpers/cron.py b/files/helpers/cron.py index ca89880f1..95f71ee56 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -7,6 +7,7 @@ from hashlib import md5 from collections import Counter from sqlalchemy.orm import load_only, InstrumentedAttribute from sqlalchemy.sql import text +from sqlalchemy import or_ import click import requests @@ -19,7 +20,7 @@ import files.routes.static as route_static from files.routes.front import frontlist from files.__main__ import cache from files.classes import * -from files.helpers.alerts import send_repeatable_notification, notif_comment +from files.helpers.alerts import * from files.helpers.config.const import * from files.helpers.get import * from files.helpers.lottery import check_if_end_lottery_task @@ -153,13 +154,6 @@ def _hole_inactive_purge_task(): dead_holes = g.db.query(Hole).filter(Hole.name.notin_(active_holes)).all() names = [x.name for x in dead_holes] - admins = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_HOLE_INACTIVITY_DELETION'])] - - mods = g.db.query(Mod).filter(Mod.hole.in_(names)).all() - for x in mods: - if x.user_id in admins: continue - send_repeatable_notification(x.user_id, f":marseyrave: /h/{x.hole} has been deleted for inactivity after one week without new posts. All posts in it have been moved to the main feed :marseyrave:") - for name in names: first_mod_id = g.db.query(Mod.user_id).filter_by(hole=name).order_by(Mod.created_utc).first() if first_mod_id: @@ -170,8 +164,10 @@ def _hole_inactive_purge_task(): description=f'Let a hole they owned die (/h/{name})' ) - for admin in admins: - send_repeatable_notification(admin, f":marseyrave: /h/{name} has been deleted for inactivity after one week without new posts. All posts in it have been moved to the main feed :marseyrave:") + text = f":marseyrave: /h/{name} has been deleted for inactivity after one week without new posts. All posts in it have been moved to the main feed :marseyrave:" + mod_ids = (x[0] for x in g.db.query(Mod.user_id).filter_by(hole=name)) + extra_criteria = or_(User.hole_creation_notifs == True, User.id.in_(mod_ids)) + alert_active_users(text, None, extra_criteria) posts = g.db.query(Post).filter(Post.hole.in_(names)).all() for post in posts: @@ -183,7 +179,7 @@ def _hole_inactive_purge_task(): post.hole_pinned = None g.db.add(post) - to_delete = mods \ + to_delete = g.db.query(Mod).filter(Mod.hole.in_(names)).all() \ + g.db.query(Exile).filter(Exile.hole.in_(names)).all() \ + g.db.query(HoleBlock).filter(HoleBlock.hole.in_(names)).all() \ + g.db.query(StealthHoleUnblock).filter(StealthHoleUnblock.hole.in_(names)).all() \ diff --git a/files/routes/groups.py b/files/routes/groups.py index b3900dd17..9419dfffc 100644 --- a/files/routes/groups.py +++ b/files/routes/groups.py @@ -55,7 +55,7 @@ def create_group(v): g.db.flush() #Necessary, to make linkfying the ping group in the notification work text = f":!marseyparty: !{group} has been created by @{v.username} :marseyparty:" - alert_active_users(text, v, User.group_creation_notifs == True) + alert_active_users(text, v.id, User.group_creation_notifs == True) return {"message": f"!{group} created successfully!"} diff --git a/files/routes/holes.py b/files/routes/holes.py index d1b430c98..708c37117 100644 --- a/files/routes/holes.py +++ b/files/routes/holes.py @@ -390,7 +390,7 @@ def create_sub2(v): g.db.add(mod) text = f":!marseyparty: /h/{hole} has been created by @{v.username} :marseyparty:" - alert_active_users(text, v, User.hole_creation_notifs == True) + alert_active_users(text, v.id, User.hole_creation_notifs == True) return redirect(f"/h/{hole}") diff --git a/files/templates/settings/advanced.html b/files/templates/settings/advanced.html index 44ae2bafb..9573dd4cd 100644 --- a/files/templates/settings/advanced.html +++ b/files/templates/settings/advanced.html @@ -161,7 +161,7 @@
Notifications
{% if SITE_NAME != 'WPD' %} - {{common.toggle_section('Hole Creation Notifications', 'hole_creation_notifs', 'hole_creation_notifs', v.hole_creation_notifs, 'Get a notification when a new hole is made.', false)}} + {{common.toggle_section('Hole Creation and Deletion Notifications', 'hole_creation_notifs', 'hole_creation_notifs', v.hole_creation_notifs, 'Get a notification when a hole is made or deleted.', false)}} {% endif %} {{common.toggle_section('Ping Group Creation Notifications', 'group_creation_notifs', 'group_creation_notifs', v.group_creation_notifs, 'Get a notification when a new ping group is made.', false)}}