From 79188e3f7fdc6db705dd38a62b81db93d311bb74 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 23 Apr 2026 14:06:41 +0000 Subject: [PATCH] fix: scope Marmot messages in notification filter to the current account The notification filter accepted any note whose `inGatherers` contained a MarmotGroupChatroom, regardless of which account's list that chatroom belonged to. Since notes live in the global LocalCache and accumulate gatherer references across account switches (and are not cleaned up on leave), old messages stayed in Notifications after switching accounts or leaving a group. Mirror the NIP-17 DM guarantee: only accept a Marmot message when the gatherer is the same instance currently held by the active account's `marmotGroupList.rooms[nostrGroupId]`. --- .../notifications/dal/NotificationFeedFilter.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/dal/NotificationFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/dal/NotificationFeedFilter.kt index ccf5341b9..8f93ad00b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/dal/NotificationFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/dal/NotificationFeedFilter.kt @@ -176,9 +176,20 @@ class NotificationFeedFilter( ): Boolean { val loggedInUserHex = account.userProfile().pubkeyHex - // Marmot group messages are always acceptable (user is a group member) - val isMarmotGroupMessage = it.inGatherers?.any { g -> g is MarmotGroupChatroom } == true - if (isMarmotGroupMessage) { + // Marmot group messages are only acceptable if the gathering chatroom is + // actually in the current account's group list. Notes are stored in the + // global LocalCache and accumulate a gatherer reference from every + // account's chatroom that has ever touched them, so seeing any + // MarmotGroupChatroom is not enough — it could belong to a prior account + // or a group the user has since left. Verify the chatroom is the same + // instance held by this account's list. + val marmotGatherers = it.inGatherers?.filterIsInstance() + if (!marmotGatherers.isNullOrEmpty()) { + val inCurrentAccount = + marmotGatherers.any { room -> + account.marmotGroupList.rooms.get(room.nostrGroupId) === room + } + if (!inCurrentAccount) return false return it.author?.pubkeyHex != loggedInUserHex }