mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-27 15:48:54 +00:00
android, desktop: fix pop chat collector reading the primary chat list
PopChatCollector is created per ChatsContext, but it was a nested class taking the context as a constructor parameter, so only its init block held a reference to it. popCollectedChats() is a separate method, and a nested class has no enclosing instance, so the unqualified getChat() and chats in it did not resolve to ChatsContext - they resolved outward to the ChatModel object, whose chats is the primary list. The method therefore built a reordered copy of the primary chat list, and init installed it as the secondary context's list. With a group reports view or a member support chat open, receiving a message from one chat, then another, then the first again gives the first chat a non-zero position in the secondary list, which schedules a pop; two seconds later the secondary context's chat list is replaced by the primary one. ChatView derives the unread count of the open chat from that list, so the reports or member support view then shows the count of the group's main chat. Make the class inner. getChat and chats then resolve to the context that owns the collector, and the same mistake cannot be reintroduced by adding another method to it. Nothing changes for the primary context, where the two lists are the same.
This commit is contained in:
+3
-4
@@ -779,10 +779,9 @@ object ChatModel {
|
||||
}
|
||||
}
|
||||
|
||||
val popChatCollector = PopChatCollector(this)
|
||||
val popChatCollector = PopChatCollector()
|
||||
|
||||
// TODO [contexts] no reason for this to be nested?
|
||||
class PopChatCollector(chatsCtx: ChatsContext) {
|
||||
inner class PopChatCollector {
|
||||
private val subject = MutableSharedFlow<Unit>()
|
||||
private var remoteHostId: Long? = null
|
||||
private val chatsToPop = mutableMapOf<ChatId, Instant>()
|
||||
@@ -793,7 +792,7 @@ object ChatModel {
|
||||
.throttleLatest(2000)
|
||||
.collect {
|
||||
withContext(Dispatchers.Main) {
|
||||
chatsCtx.chats.replaceAll(popCollectedChats())
|
||||
chats.replaceAll(popCollectedChats())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user