From 78f936cc22c81421e6f45819f635704a3f24fb34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Mon, 15 Jan 2024 14:30:11 +0200 Subject: [PATCH 1/1] Fixed: Collapse multiple flair notifications into one --- model.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/model.py b/model.py index 33cd1ac..18a102d 100644 --- a/model.py +++ b/model.py @@ -87,6 +87,8 @@ class Notification: REACTION: -1, # only one kept USER_RENAMED: -1, USER_FLAIR_CHANGED: -1, + LIKE: -1, + THANKS: -1, COMMENT_IN_FOLLOWED_SUBSPACE: 0, POST_IN_FOLLOWED_SUBSPACE: 1, @@ -2654,28 +2656,31 @@ class Database: resolved = [] kept_ids = set() discarded_ids = set() - have_reaction = set() + have_single = {} # Only one of some types are kept. # Create a table of (post, src) -> [notifs]. indexed = {} for notif in notifs: - if notif.type != Notification.SUBSPACE_INFO_UPDATED and ( - not notif.post or notif.type in (Notification.LIKE, - Notification.THANKS, - Notification.ISSUE_CLOSED, + # Some notifications are always kept as-is. + if (notif.type not in (Notification.SUBSPACE_INFO_UPDATED, + Notification.USER_FLAIR_CHANGED)) and ( + not notif.post or notif.type in (Notification.ISSUE_CLOSED, Notification.REMINDER, Notification.REPORT)): - # Subspace notifications are resolved as-is. resolved.append(notif) kept_ids.add(notif.id) continue + key = (notif.post, notif.src) - # One reaction per key. - if notif.type == Notification.REACTION: - if not notif.reaction or key in have_reaction: + # The priority value -1 means "keep only one". + if notif.type in Notification.PRIORITY and Notification.PRIORITY[notif.type] < 0: + if not notif.type in have_single: + have_single[notif.type] = {key} + elif key in have_single[notif.type]: continue - have_reaction.add(key) + else: + have_single[notif.type].add(key) if key not in indexed: indexed[key] = [notif] -- 2.34.1