notify ppl when holes are deleted

pull/222/head
Aevann 2024-02-10 17:34:45 +02:00
parent 9797c57a7a
commit 498e2119b1
6 changed files with 13 additions and 19 deletions

View File

@ -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:

View File

@ -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,

View File

@ -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() \

View File

@ -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!"}

View File

@ -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}")

View File

@ -161,7 +161,7 @@
<h5>Notifications</h5>
<div class="settings-section rounded">
{% 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)}}
</div>