diff --git a/files/classes/user.py b/files/classes/user.py index 3b68e1e7d..b5d89ee44 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -150,6 +150,7 @@ class User(Base): 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) effortpost_notifs = Column(Boolean, default=False) + offsite_mentions = Column(Boolean) if SITE_NAME == 'WPD' and not IS_LOCALHOST: nitter = False @@ -561,7 +562,7 @@ class User(Base): @property @lazy def can_view_offsite_mentions(self): - return self.has_badge(140) or self.admin_level >= PERMS['NOTIFICATIONS_OFFSITE'] + return self.offsite_mentions or self.admin_level >= PERMS['NOTIFICATIONS_OFFSITE'] @lazy def can_edit(self, target): diff --git a/files/routes/awards.py b/files/routes/awards.py index 8059c04d1..f34f39f59 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -452,6 +452,7 @@ def award_thing(v, thing_type, id): elif kind == "eye": badge_grant(badge_id=83, user=author) elif kind == "offsitementions": + author.offsite_mentions = True badge_grant(user=author, badge_id=140) elif kind == "alt": badge_grant(badge_id=84, user=author) diff --git a/files/routes/notifications.py b/files/routes/notifications.py index c03e02a7f..05b69917e 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -268,7 +268,7 @@ def notifications_modactions(v): -@app.get("/notifications/offsite") +@app.get("/notifications/site_mentions") @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required diff --git a/files/routes/settings.py b/files/routes/settings.py index 34257ea99..50fa17e76 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -186,8 +186,15 @@ def settings_personal_post(v): if v.spider: badge_grant(user=v, badge_id=179) else: badge = v.has_badge(179) - if badge: - g.db.delete(badge) + if badge: g.db.delete(badge) + + elif not updated and request.values.get("offsite_mentions", v.offsite_mentions) != v.offsite_mentions: + updated = True + v.offsite_mentions = int(request.values.get("offsite_mentions") == 'true') + if v.offsite_mentions: badge_grant(user=v, badge_id=140) + else: + badge = v.has_badge(140) + if badge: g.db.delete(badge) elif not updated and request.values.get("cursormarsey", v.cursormarsey) != v.cursormarsey: updated = True diff --git a/files/templates/notifications.html b/files/templates/notifications.html index 4ec50384b..f7747da69 100644 --- a/files/templates/notifications.html +++ b/files/templates/notifications.html @@ -40,8 +40,8 @@ {% endif %} {% if v.can_view_offsite_mentions %} {% endif %} diff --git a/files/templates/settings/advanced.html b/files/templates/settings/advanced.html index ec5cd7759..5ca1e21c8 100644 --- a/files/templates/settings/advanced.html +++ b/files/templates/settings/advanced.html @@ -170,6 +170,9 @@
Notifications
+ {% if v.offsite_mentions != None %} + {{common.toggle_section('Site Mention Notifications', 'offsite_mentions', 'offsite_mentions', v.offsite_mentions, 'Get a notification when people on other sites talk about us', false)}} + {% endif %} {{common.toggle_section('Effortpost Notifications', 'effortpost_notifs', 'effortpost_notifs', v.effortpost_notifs, 'Get a notification when a new effortpost is made.', false)}} {% if SITE_NAME != 'WPD' %} {{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)}} diff --git a/migrations/20240229-add-ability-to-toggle-purple-notifs.sql b/migrations/20240229-add-ability-to-toggle-purple-notifs.sql new file mode 100644 index 000000000..1aa1846fa --- /dev/null +++ b/migrations/20240229-add-ability-to-toggle-purple-notifs.sql @@ -0,0 +1 @@ +alter table users add column offsite_mentions bool;