From 73af394f9ecbfa5b4d75233ef03a374bc81069fb Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 8 Feb 2024 05:35:37 +0200 Subject: [PATCH] add settings for hole and ping group creation notifs --- files/classes/user.py | 3 +++ files/helpers/alerts.py | 13 +++++++++++++ files/helpers/config/const.py | 4 ---- files/routes/groups.py | 5 ++--- files/routes/holes.py | 8 +------- files/routes/settings.py | 2 ++ files/templates/settings/advanced.html | 12 +++++++++++- .../20240208-add-settings-for-creation-notifs.sql | 4 ++++ 8 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 migrations/20240208-add-settings-for-creation-notifs.sql diff --git a/files/classes/user.py b/files/classes/user.py index 590d80927..51f6850c6 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -148,6 +148,7 @@ class User(Base): lifetimedonated_visible = Column(Boolean, default=False) blacklisted_by = Column(Integer, ForeignKey("users.id")) grinch = Column(Boolean, default=SITE_NAME != 'rDrama') #don't put in an if condition, it will cause an error bc it has a not-null constraint + group_creation_notifs = Column(Boolean, default=False) if SITE_NAME == 'WPD': nitter = False @@ -156,6 +157,7 @@ class User(Base): reddit = 'old.reddit.com' pronouns = 'they/them' earlylife = 0 + hole_creation_notifs = False hidevotedon = Column(Boolean, default=False) else: nitter = Column(Boolean, default=False) @@ -164,6 +166,7 @@ class User(Base): reddit = Column(String, default='old.reddit.com') pronouns = Column(String, default='they/them') earlylife = Column(Integer, default=0) + hole_creation_notifs = Column(Boolean, default=True) hidevotedon = False if IS_HOMOWEEN(): diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index b5a27b937..ab3b05190 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -313,3 +313,16 @@ def alert_admins(body): g.db.flush() new_comment.top_comment_id = new_comment.id + +def alert_active_users(body, v, 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, + extra_criteria, + )] + for uid in notified_users: + add_notif(cid, uid, body, check_existing=False) diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index c7047b75b..3abcbab75 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -174,8 +174,6 @@ PERMS = { # Minimum admin_level to perform action. 'VIEW_LAST_ACTIVE': 1, 'ENABLE_VOTE_BUTTONS_ON_USER_PAGE': 1, 'NOTIFICATIONS_HOLE_INACTIVITY_DELETION': 1, - 'NOTIFICATIONS_HOLE_CREATION': 1, - 'NOTIFICATIONS_GROUP_CREATION': 1, 'NOTIFICATIONS_MODERATOR_ACTIONS': 1, 'EXEMPT_FROM_IP_LOGGING': 1, @@ -236,8 +234,6 @@ if SITE_NAME == 'rDrama': patron = "Paypig" - PERMS['NOTIFICATIONS_HOLE_CREATION'] = 0 - TAGLINES = ( "largest online LGBTQ+ club", "largest online furfest", diff --git a/files/routes/groups.py b/files/routes/groups.py index 24bb8b2da..b3900dd17 100644 --- a/files/routes/groups.py +++ b/files/routes/groups.py @@ -54,9 +54,8 @@ def create_group(v): g.db.flush() #Necessary, to make linkfying the ping group in the notification work - admins = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_GROUP_CREATION'], User.id != v.id)] - for admin in admins: - send_repeatable_notification(admin, f":!marseyparty: !{group} has been created by @{v.username} :marseyparty:") + text = f":!marseyparty: !{group} has been created by @{v.username} :marseyparty:" + alert_active_users(text, v, User.group_creation_notifs == True) return {"message": f"!{group} created successfully!"} diff --git a/files/routes/holes.py b/files/routes/holes.py index 5bc797400..89f412ba6 100644 --- a/files/routes/holes.py +++ b/files/routes/holes.py @@ -390,13 +390,7 @@ def create_sub2(v): g.db.add(mod) text = f":!marseyparty: /h/{hole} has been created by @{v.username} :marseyparty:" - text_html = sanitize(text, blackjack="notification") - cid = create_comment(text_html) - t = time.time() - 604800 - excluded_ids = (v.id, 556, 868, 6289, 21238) - notified_users = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_HOLE_CREATION'], User.last_active > t, User.id.notin_(excluded_ids))] - for uid in notified_users: - add_notif(cid, uid, text, check_existing=False) + alert_active_users(text, v, User.hole_creation_notifs == True) return redirect(f"/h/{hole}") diff --git a/files/routes/settings.py b/files/routes/settings.py index ffeaa6800..71910116b 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -175,6 +175,8 @@ def settings_personal_post(v): updated = updated or update_flag("show_sigs", "show_sigs") updated = updated or update_flag("is_private", "private") updated = updated or update_flag("lifetimedonated_visible", "lifetimedonated_visible") + updated = updated or update_flag("hole_creation_notifs", "hole_creation_notifs") + updated = updated or update_flag("group_creation_notifs", "group_creation_notifs") if not updated and request.values.get("spider", v.spider) != v.spider and v.spider <= 1: updated = True diff --git a/files/templates/settings/advanced.html b/files/templates/settings/advanced.html index 9d24440e6..42c5fea72 100644 --- a/files/templates/settings/advanced.html +++ b/files/templates/settings/advanced.html @@ -4,7 +4,6 @@
- {# toggle_section(title, id, name, flag, below_text) #}
{# note: not using the thing from common just because of how much stuff there is in here #}
Poor Mode
@@ -157,6 +156,17 @@
+ +
+
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)}} + {% 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)}} +
+
+
RSS Feed

Subscribe to the {{SITE_NAME}} RSS feed.

diff --git a/migrations/20240208-add-settings-for-creation-notifs.sql b/migrations/20240208-add-settings-for-creation-notifs.sql new file mode 100644 index 000000000..9a116df00 --- /dev/null +++ b/migrations/20240208-add-settings-for-creation-notifs.sql @@ -0,0 +1,4 @@ +alter table users add column hole_creation_notifs bool default true not null; +alter table users add column group_creation_notifs bool default false not null; +alter table users alter column hole_creation_notifs drop default; +alter table users alter column group_creation_notifs drop default;