From ed447a57221142914d7058624648d834f3370926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Sun, 14 May 2023 22:51:06 +0300 Subject: [PATCH 1/1] Added missing description of a notification Fetch the subspace info and describe the "post in followed subspace" notification. IssueID #12 --- model.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/model.py b/model.py index 06eb0e6..9c892c1 100644 --- a/model.py +++ b/model.py @@ -51,7 +51,8 @@ class Notification: ISSUE_CLOSED = 0x200 def __init__(self, id, type, dst, src, post, is_sent, ts, - src_name=None, post_title=None, post_issueid=None): + src_name=None, post_title=None, post_issueid=None, + post_subname=None, post_subowner=None): self.id = id self.type = type self.dst = dst @@ -62,6 +63,8 @@ class Notification: self.src_name = src_name self.post_title = post_title self.post_issueid = post_issueid + self.post_subname = post_subname + self.post_subowner = post_subowner def ymd_date(self): dt = datetime.datetime.fromtimestamp(self.ts, UTC) @@ -93,6 +96,8 @@ class Notification: icon = '💬 ' elif self.type == Notification.POST_BY_FOLLOWED_USER: event = 'published new a post' + elif self.type == Notification.POST_IN_FOLLOWED_SUBSPACE: + event = f'posted in followed subspace {"u/" if self.post_subowner else "s/"}{self.post_subname}' elif self.type == Notification.MENTION: event = 'mentioned you' elif self.type == Notification.NEW_POLL: @@ -1558,17 +1563,19 @@ class Database: cur.execute(f""" SELECT n.id, n.type, n.dst, n.src, n.post, n.is_sent, UNIX_TIMESTAMP(n.ts), - u.name, p.title, p.issueid + u.name, p.title, p.issueid, s.name, s.owner FROM notifs n JOIN users u ON src=u.id JOIN posts p ON post=p.id + JOIN subspaces s ON s.id=p.subspace WHERE {' AND '.join(cond)} ORDER BY ts """, tuple(values)) notifs = [] - for (id, type, dst, src, post, is_sent, ts, src_name, post_title, post_issueid) in cur: + for (id, type, dst, src, post, is_sent, ts, src_name, post_title, post_issueid, post_subname, post_subowner) in cur: notifs.append(Notification(id, type, dst, src, post, is_sent, ts, - src_name, post_title, post_issueid)) + src_name, post_title, post_issueid, + post_subname, post_subowner)) if clear and notifs: cur.execute(f"DELETE FROM notifs WHERE id IN ({','.join(map(lambda n: str(n.id), notifs))})", list()) self.commit() -- 2.34.1