=> 82955491aed1a4a121f6e91e7444d4f1c59117d7
[1mdiff --git a/model.py b/model.py[m [1mindex 88a03e4..0b3881f 100644[m [1m--- a/model.py[m [1m+++ b/model.py[m [36m@@ -100,7 +100,8 @@[m [mclass Notification:[m [m def __init__(self, id, type, dst, src, post, subspace, comment, is_sent, ts,[m src_name=None, post_title=None, post_issueid=None, post_summary=None,[m [31m- post_subname=None, post_subowner=None, subname=None, reaction=None):[m [32m+[m[32m post_subname=None, post_subowner=None, subname=None, reaction=None,[m [32m+[m[32m post_subid=None):[m self.id = id[m self.type = type[m self.dst = dst[m [36m@@ -114,6 +115,7 @@[m [mclass Notification:[m self.post_title = post_title[m self.post_issueid = post_issueid[m self.post_summary = post_summary[m [32m+[m[32m self.post_subid = post_subid[m self.post_subname = post_subname[m self.post_subowner = post_subowner[m self.subname = subname[m [36m@@ -128,6 +130,11 @@[m [mclass Notification:[m def age(self):[m return ago_text(self.ts)[m [m [32m+[m[32m def title_text(self):[m [32m+[m[32m return shorten_text(self.post_title, 50) if self.post_title \[m [32m+[m[32m else shorten_text(strip_links(clean_title(self.post_summary)), 50) if self.post_summary \[m [32m+[m[32m else None[m [32m+[m def entry(self, show_age=True, with_time=False, with_title=True, tz=None) -> tuple:[m """Returns (link, label) to use in the notification list."""[m [m [36m@@ -195,9 +202,7 @@[m [mclass Notification:[m event = f"reported the {kind}"[m [m if with_title:[m [31m- vis_title = shorten_text(self.post_title, 50) if self.post_title \[m [31m- else shorten_text(strip_links(clean_title(self.post_summary)), 50) if self.post_summary \[m [31m- else None[m [32m+[m[32m vis_title = self.title_text()[m if vis_title:[m if self.type == Notification.MENTION:[m event += ' in'[m [36m@@ -383,8 +388,6 @@[m [mclass Post:[m return self.title[m elif self.parent:[m text = f'Comment on {"u" if self.sub_owner else "s"}/{self.sub_name}/{self.parent}'[m [31m- #if self.summary:[m [31m- # text += f': "{shorten_text(self.summary(30))}"'[m return text[m else:[m return '(untitled issue)' if self.issueid else '(untitled post)'[m [36m@@ -2387,7 +2390,7 @@[m [mclass Database:[m n.id, n.type, n.dst, n.src, n.post, n.subspace, n.comment, n.is_sent, UNIX_TIMESTAMP(n.ts),[m u.name,[m p.title, p.issueid, p.summary,[m [31m- s.name, s.owner,[m [32m+[m[32m s.id, s.name, s.owner,[m s2.name,[m r.reaction[m FROM notifs n[m [36m@@ -2405,10 +2408,11 @@[m [mclass Database:[m """, tuple(values))[m notifs = [][m for (id, type, dst, src, post, subspace, comment, is_sent, ts, src_name, post_title, post_issueid,[m [31m- post_summary, post_subname, post_subowner, subname, reaction) in cur:[m [32m+[m[32m post_summary, post_subid, post_subname, post_subowner, subname, reaction) in cur:[m notifs.append(Notification(id, type, dst, src, post, subspace, comment, is_sent, ts,[m src_name, post_title, post_issueid, post_summary,[m [31m- post_subname, post_subowner, subname, reaction))[m [32m+[m[32m post_subname, post_subowner, subname, reaction,[m [32m+[m[32m post_subid=post_subid))[m [m notifs = self.resolve_notifications(notifs)[m notifs.sort(key=lambda n: n.ts, reverse=sort_desc)[m [1mdiff --git a/user.py b/user.py[m [1mindex 3213ba5..6665705 100644[m [1m--- a/user.py[m [1m+++ b/user.py[m [36m@@ -244,6 +244,38 @@[m [mdef user_actions(session):[m return 42, 'Invalid notification'[m [m [m [32m+[m[32mclass Subgrouping:[m [32m+[m[32m """Sorts notifications by related post ID and descending time."""[m [32m+[m [32m+[m[32m def __init__(self, user, notifs):[m [32m+[m[32m self.user = user[m [32m+[m[32m self.by_post = {}[m [32m+[m[32m ordered = sorted(notifs, key=lambda n: -n.ts)[m [32m+[m[32m for notif in ordered:[m [32m+[m[32m if not notif.post in self.by_post:[m [32m+[m[32m self.by_post[notif.post] = [][m [32m+[m[32m self.by_post[notif.post].append(notif)[m [32m+[m [32m+[m[32m def render(self):[m [32m+[m[32m src = [][m [32m+[m[32m top_head = False[m [32m+[m[32m for post_id, notifs in self.by_post.items():[m [32m+[m[32m if top_head:[m [32m+[m[32m # Separate subgroups.[m [32m+[m[32m src.append('')[m [32m+[m[32m top_head = post_id and len(notifs) > 1[m [32m+[m[32m if top_head:[m [32m+[m[32m n = notifs[0][m [32m+[m[32m if n.post_subname and n.post_subowner != self.user.id:[m [32m+[m[32m sub_text = f" in {'u/' if n.post_subowner else 's/'}{n.post_subname}"[m [32m+[m[32m else:[m [32m+[m[32m sub_text = ''[m [32m+[m[32m src.append(f'"{n.title_text()}"{sub_text}:')[m [32m+[m[32m for notif in notifs:[m [32m+[m[32m src.append('=> %s %s' % notif.entry(with_title=not top_head))[m [32m+[m[32m return '\n'.join(src) + '\n'[m [32m+[m [32m+[m def make_dashboard_page(session):[m if not session.user:[m return 60, "Login required"[m [36m@@ -263,6 +295,7 @@[m [mdef make_dashboard_page(session):[m if n:[m # Group in two: @user and Followed.[m yours = [][m [32m+[m[32m moderated = [][m followed = [][m for notif in notifs:[m if not notif.type in Notification.PRIORITY or \[m [36m@@ -270,19 +303,22 @@[m [mdef make_dashboard_page(session):[m Notification.PRIORITY[notif.type] >= 10:[m yours.append(notif)[m else:[m [31m- followed.append(notif)[m [32m+[m[32m if notif.post_subid in user.moderated_subspace_ids:[m [32m+[m[32m moderated.append(notif)[m [32m+[m[32m else:[m [32m+[m[32m followed.append(notif)[m [m if yours:[m page += f'\n### @{session.user.name}\n'[m [31m- for notif in sorted(yours, key=lambda n: -n.ts):[m [31m- link, label = notif.entry()[m [31m- page += f'=> {link} {label}\n'[m [32m+[m[32m page += Subgrouping(user, yours).render()[m [32m+[m [32m+[m[32m if moderated:[m [32m+[m[32m page += f'\n### Moderated\n'[m [32m+[m[32m page += Subgrouping(user, moderated).render()[m [m if followed:[m page += f'\n### Followed\n'[m [31m- for notif in sorted(followed, key=lambda n: -n.ts):[m [31m- link, label = notif.entry()[m [31m- page += f'=> {link} {label}\n'[m [32m+[m[32m page += Subgrouping(user, followed).render()[m [m page += '\n=> /notif/clear 🧹 Clear all\n'[m page += '=> /notif/feed Notifications feed\nSubscribe to this Gemini feed to view your unread notifications in a feed reader.\n'[m
text/gemini; charset=utf-8
This content has been proxied by September (3851b).