fix: drop Marmot chatroom on leave so messages clear from caches
When the local user leaves a Marmot MLS group, MarmotManager already wipes MLS state, the relay subscription and the persisted message log, but the chatroom (and its decrypted inner messages) lingered in marmotGroupList until the UI happened to call removeGroup. The CLI leave path skipped that step entirely, and removeGroup itself only dropped the chatroom from rooms — it left noteToGroupIndex entries and the chatroom's own messages set in place, so notes stayed strongly referenced and kept appearing in the Notification feed. Move the in-memory cleanup into Account.leaveMarmotGroup, and have MarmotGroupList.removeGroup also clear the chatroom's messages and the note→group index. LocalCache holds notes weakly, so cutting the strong refs is enough — GC reclaims them and the existing acceptableEvent filter (which keys off marmotGroupList.rooms) hides anything still in-flight.
This commit is contained in:
+17
@@ -202,4 +202,21 @@ class MarmotGroupChatroom(
|
||||
changesFlow.get()?.tryEmit(ListChange.SetDeletion<Note>(toRemove))
|
||||
return toRemove
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop every message from this chatroom. Used when the local user leaves
|
||||
* the group: cuts the strong references held in [messages] so the
|
||||
* decrypted inner notes become eligible for GC out of LocalCache (which
|
||||
* holds them weakly).
|
||||
*/
|
||||
@Synchronized
|
||||
fun clearAllMessagesSync(): Set<Note> {
|
||||
val toRemove = messages
|
||||
if (toRemove.isEmpty()) return toRemove
|
||||
messages = emptySet()
|
||||
newestMessage = null
|
||||
unreadCount.value = 0
|
||||
changesFlow.get()?.tryEmit(ListChange.SetDeletion<Note>(toRemove))
|
||||
return toRemove
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -127,8 +127,15 @@ class MarmotGroupList(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop a group from the in-memory list. Also clears the chatroom's own
|
||||
* message set and the note→group index: LocalCache holds notes weakly, so
|
||||
* once these strong references go away the decrypted inner messages
|
||||
* become eligible for GC and stop appearing in the Notification feed.
|
||||
*/
|
||||
fun removeGroup(nostrGroupId: HexKey) {
|
||||
rooms.remove(nostrGroupId)
|
||||
val chatroom = rooms.remove(nostrGroupId)
|
||||
chatroom?.clearAllMessagesSync()?.forEach { noteToGroupIndex.remove(it.idHex) }
|
||||
_groupListChanges.tryEmit(nostrGroupId)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user