From 301226497f14f978aacfa0bbcf99ac0226d89bcc Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 11 Feb 2024 16:16:09 +0200 Subject: [PATCH] add effortpost notifications toggle --- files/classes/user.py | 21 ++++++++++++------- files/routes/notifications.py | 19 ++++++++++------- files/routes/settings.py | 1 + files/templates/settings/advanced.html | 1 + .../20240211-add-following-effortposts.sql | 2 ++ 5 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 migrations/20240211-add-following-effortposts.sql diff --git a/files/classes/user.py b/files/classes/user.py index 66921d1f6..45d80591a 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -149,6 +149,7 @@ class User(Base): 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) + effortpost_notifs = Column(Boolean, default=False) if SITE_NAME == 'WPD': nitter = False @@ -827,22 +828,26 @@ class User(Base): @property @lazy def post_notifications_count(self): + or_criteria = [ + Post.hole.in_(self.followed_holes), + and_( + Post.author_id.in_(self.followed_users), + Post.notify == True, + Post.ghost == False, + )] + + if self.effortpost_notifs: + or_criteria.append(Post.effortpost == True) + return g.db.query(Post).filter( Post.created_utc > self.last_viewed_post_notifs, - or_( - Post.hole.in_(self.followed_holes), - and_( - Post.author_id.in_(self.followed_users), - Post.notify == True, - Post.ghost == False, - ), - ), Post.deleted_utc == 0, Post.is_banned == False, Post.private == False, Post.author_id != self.id, Post.author_id.notin_(self.userblocks), or_(Post.hole == None, Post.hole.notin_(self.hole_blocks)), + or_(*or_criteria), ).count() @property diff --git a/files/routes/notifications.py b/files/routes/notifications.py index 850269735..a11b4616f 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -174,15 +174,18 @@ def notifications_modmail(v): def notifications_posts(v): page = get_page() + or_criteria = [ + Post.hole.in_(v.followed_holes), + and_( + Post.author_id.in_(v.followed_users), + Post.notify == True, + Post.ghost == False, + )] + + if v.effortpost_notifs: + or_criteria.append(Post.effortpost == True) + listing = g.db.query(Post).filter( - or_( - Post.hole.in_(v.followed_holes), - and_( - Post.author_id.in_(v.followed_users), - Post.notify == True, - Post.ghost == False, - ), - ), Post.deleted_utc == 0, Post.is_banned == False, Post.private == False, diff --git a/files/routes/settings.py b/files/routes/settings.py index 71910116b..f522003b9 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -177,6 +177,7 @@ def settings_personal_post(v): 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") + updated = updated or update_flag("effortpost_notifs", "effortpost_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 9573dd4cd..38e380e87 100644 --- a/files/templates/settings/advanced.html +++ b/files/templates/settings/advanced.html @@ -160,6 +160,7 @@
Notifications
+ {{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)}} {% endif %} diff --git a/migrations/20240211-add-following-effortposts.sql b/migrations/20240211-add-following-effortposts.sql new file mode 100644 index 000000000..fa2621f15 --- /dev/null +++ b/migrations/20240211-add-following-effortposts.sql @@ -0,0 +1,2 @@ +alter table users add column effortpost_notifs bool default false not null; +alter table users alter effortpost_notifs drop default;