mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-22 21:52:28 +00:00
android, desktop: fix chat preview and unread counter updating wrong chat (#7072)
* android, desktop: fix chat preview and unread counter updating wrong chat While "Chat with admins", a member support chat or the reports view was open, ChatsContext.addChatItem in the secondary context looked up the chat's index in its own list but read and wrote the main chat list at that index (chatsContext.chats[i]), so an unrelated chat in the main list got the message as its preview and its unread count went up. Use the context's own list at all four sites again. The main-list qualifier had also made a pending invitee's sent support messages reach the group's preview in the main list (at a secondary-list index), so send that update to the main list explicitly: addSentChatItem passes a sent item to the main chat list context as well when it is sent from a secondary view and belongs in the main list (inMainChatList, the same rule addChatItem uses for previews). Count unread stats only in the main chat list context, so the revert does not make the open secondary view count main-list messages in its own list. * plans: wrong-chat preview and unread fix
This commit is contained in:
1 parent
87e3f8c3f6
commit
cc3f49f794
4 files changed
+176
-9
No files matched your search
+16
-6
@@ -414,6 +414,13 @@ object ChatModel {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun addSentChatItem(activeCtx: ChatsContext, rhId: Long?, cInfo: ChatInfo, cItem: ChatItem) {
|
||||
activeCtx.addChatItem(rhId, cInfo, cItem)
|
||||
if (activeCtx.secondaryContextFilter != null && cInfo.inMainChatList) {
|
||||
chatsContext.addChatItem(rhId, cInfo, cItem)
|
||||
}
|
||||
}
|
||||
|
||||
// Spec: spec/state.md#ChatsContext
|
||||
class ChatsContext(val secondaryContextFilter: SecondaryContextFilter?) {
|
||||
val chats = mutableStateOf(SnapshotStateList<Chat>())
|
||||
@@ -584,9 +591,9 @@ object ChatModel {
|
||||
val i = getChatIndex(rhId, cInfo.id)
|
||||
val chat: Chat
|
||||
if (i >= 0) {
|
||||
chat = chatsContext.chats[i]
|
||||
chat = chats[i]
|
||||
// update preview (for chat from main scope to show new items for invitee in pending status)
|
||||
if (cInfo.groupChatScope() == null || cInfo.groupInfo_?.membership?.memberPending == true) {
|
||||
if (cInfo.inMainChatList) {
|
||||
val newPreviewItem = when (cInfo) {
|
||||
is ChatInfo.Group -> {
|
||||
val currentPreviewItem = chat.chatItems.firstOrNull()
|
||||
@@ -604,20 +611,20 @@ object ChatModel {
|
||||
else -> cItem
|
||||
}
|
||||
val wasUnread = chat.unreadTag
|
||||
chatsContext.chats[i] = chat.copy(
|
||||
chats[i] = chat.copy(
|
||||
chatItems = arrayListOf(newPreviewItem),
|
||||
chatStats =
|
||||
if (cItem.meta.itemStatus is CIStatus.RcvNew) {
|
||||
if (cItem.meta.itemStatus is CIStatus.RcvNew && secondaryContextFilter == null) {
|
||||
increaseUnreadCounter(rhId, currentUser.value!!)
|
||||
chat.chatStats.copy(unreadCount = chat.chatStats.unreadCount + 1, unreadMentions = if (cItem.meta.userMention) chat.chatStats.unreadMentions + 1 else chat.chatStats.unreadMentions)
|
||||
} else
|
||||
chat.chatStats
|
||||
)
|
||||
updateChatTagReadInPrimaryContext(chatsContext.chats[i], wasUnread)
|
||||
updateChatTagReadInPrimaryContext(chats[i], wasUnread)
|
||||
}
|
||||
// pop chat
|
||||
if (appPlatform.isDesktop && cItem.chatDir.sent) {
|
||||
reorderChat(chatsContext.chats[i], 0)
|
||||
reorderChat(chats[i], 0)
|
||||
} else {
|
||||
popChatCollector.throttlePopChat(chat.remoteHostId, chat.id, currentPosition = i)
|
||||
}
|
||||
@@ -1872,6 +1879,9 @@ sealed class ChatInfo: SomeChat, NamedChat {
|
||||
|
||||
val isChannel: Boolean
|
||||
get() = groupInfo_?.useRelays == true
|
||||
|
||||
val inMainChatList: Boolean
|
||||
get() = groupChatScope() == null || groupInfo_?.membership?.memberPending == true
|
||||
}
|
||||
|
||||
@Serializable
|
||||
|
||||
+2
-2
@@ -599,7 +599,7 @@ fun ComposeView(
|
||||
if (!chatItems.isNullOrEmpty()) {
|
||||
chatItems.forEach { aChatItem ->
|
||||
withContext(Dispatchers.Main) {
|
||||
chatsCtx.addChatItem(chat.remoteHostId, aChatItem.chatInfo, aChatItem.chatItem)
|
||||
chatModel.addSentChatItem(chatsCtx, chat.remoteHostId, aChatItem.chatInfo, aChatItem.chatItem)
|
||||
}
|
||||
}
|
||||
return chatItems.first().chatItem
|
||||
@@ -741,7 +741,7 @@ fun ComposeView(
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
chatItems?.forEach { chatItem ->
|
||||
chatsCtx.addChatItem(rhId, chat.chatInfo, chatItem)
|
||||
chatModel.addSentChatItem(chatsCtx, rhId, chat.chatInfo, chatItem)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -494,7 +494,7 @@ fun sendCommandMsg(chatsCtx: ChatModel.ChatsContext, chat: Chat, msg: String) {
|
||||
if (!chatItems.isNullOrEmpty()) {
|
||||
chatItems.forEach { aChatItem ->
|
||||
withContext(Dispatchers.Main) {
|
||||
chatsCtx.addChatItem(chat.remoteHostId, aChatItem.chatInfo, aChatItem.chatItem)
|
||||
chatModel.addSentChatItem(chatsCtx, chat.remoteHostId, aChatItem.chatInfo, aChatItem.chatItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user