From fb34de8da31851316f310f9c47b2d431d7a84350 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Fri, 19 Apr 2024 20:06:08 +1200 Subject: [PATCH] notification subscription - user toggle --- app/models.py | 14 ++++++++++- app/templates/user/_notification_toggle.html | 5 ++++ app/templates/user/show_profile.html | 18 +++++++++++--- app/user/routes.py | 26 ++++++++++++++++++-- 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 app/templates/user/_notification_toggle.html diff --git a/app/models.py b/app/models.py index 229ee164..455ad0b7 100644 --- a/app/models.py +++ b/app/models.py @@ -19,7 +19,7 @@ import jwt import os from app.constants import SUBSCRIPTION_NONMEMBER, SUBSCRIPTION_MEMBER, SUBSCRIPTION_MODERATOR, SUBSCRIPTION_OWNER, \ - SUBSCRIPTION_BANNED, SUBSCRIPTION_PENDING + SUBSCRIPTION_BANNED, SUBSCRIPTION_PENDING, NOTIF_USER # datetime.utcnow() is depreciated in Python 3.12 so it will need to be swapped out eventually @@ -880,6 +880,18 @@ class User(UserMixin, db.Model): else: return '@' + self.user_name + '@' + self.ap_domain + # True if user_id wants to be notified about posts by self + def notify_new_posts(self, user_id): + existing_notification = NotificationSubscription.query.filter(NotificationSubscription.entity_id == self.id, + NotificationSubscription.user_id == user_id, + NotificationSubscription.type == NOTIF_USER).first() + return existing_notification is not None + + # ids of all the users who want to be notified when self makes a post + def notification_subscribers(self): + return db.session.execute(text('SELECT user_id FROM "notification_subscription" WHERE entity_id = :user_id AND type = :type '), + {'user_id': self.id, 'type': NOTIF_USER}).scalars() + class ActivityLog(db.Model): id = db.Column(db.Integer, primary_key=True) diff --git a/app/templates/user/_notification_toggle.html b/app/templates/user/_notification_toggle.html new file mode 100644 index 00000000..23c05af3 --- /dev/null +++ b/app/templates/user/_notification_toggle.html @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/app/templates/user/show_profile.html b/app/templates/user/show_profile.html index ea8d6dfe..3f9babd8 100644 --- a/app/templates/user/show_profile.html +++ b/app/templates/user/show_profile.html @@ -22,7 +22,11 @@ -