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]`.
This commit is contained in:
Claude
2026-04-23 14:06:41 +00:00
parent f93382daf9
commit 79188e3f7f
@@ -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<MarmotGroupChatroom>()
if (!marmotGatherers.isNullOrEmpty()) {
val inCurrentAccount =
marmotGatherers.any { room ->
account.marmotGroupList.rooms.get(room.nostrGroupId) === room
}
if (!inCurrentAccount) return false
return it.author?.pubkeyHex != loggedInUserHex
}