android, desktop, ios: correct the upsertChatItem scope-guard comment

The comment claimed addChatItem doesn't create the chat entry for a scoped ChatInfo
either. It does - with an empty chatItems list. State the actual reason the upsert
must not: it would seed the main list with the support item as preview, and since
ChatInfo.Group.id ignores the scope that entry shadows the real group.

Also note at the sent-item mirror why passing a scoped ChatInfo into the primary
context is safe (updateChatInfo strips the scope; chatItemBelongsToScope keeps the
item out of the primary's list).
This commit is contained in:
Narasimha-sc
2026-07-23 15:31:03 +00:00
parent 5afce0e600
commit 5a94b9f86d
2 changed files with 8 additions and 4 deletions
+3 -2
View File
@@ -725,8 +725,9 @@ final class ChatModel: ObservableObject {
chat.chatItems = [cItem]
}
} else if cInfo.groupChatScope() == nil {
// an upsert of a support item must not create the main list entry (addChatItem doesn't either),
// and itemAdded here would notify it as a new message
// an upsert must not materialise the chat entry for a support item: unlike addChatItem, which
// creates a placeholder with no items, this would seed the main list with the support item as
// preview, and itemAdded would have chatItemSimpleUpdate notify it as a new message
addChat(Chat(chatInfo: cInfo, chatItems: [cItem]))
itemAdded = true
}
@@ -524,6 +524,8 @@ object ChatModel {
// so the main-list preview updates for a pending invitee's own message - #5909.
// Only a pending invitee's preview reads support items, so nothing else needs the primary touched:
// without the scope/memberPending checks this also re-ran the primary for items it had already handled.
// Passing the scoped chatInfo on is safe: updateChatInfo strips the scope before storing it, and
// chatItemBelongsToScope keeps a scoped item out of the primary context's item list.
if (secondaryContextFilter is SecondaryContextFilter.GroupChatScopeContext && cItem.chatDir.sent &&
chatInfo.groupChatScope() != null && chatInfo.groupInfo_?.membership?.memberPending == true) {
chatsContext.addChatItem(rhId, chatInfo, cItem)
@@ -627,8 +629,9 @@ object ChatModel {
}
}
} else if (cInfo.groupChatScope() == null) {
// an upsert of a support item must not create the chat entry (addChatItem doesn't either) -
// it would seed the main list with a support item as preview, from a scoped ChatInfo
// an upsert must not materialise the chat entry for a support item: unlike addChatItem, which
// creates a placeholder with no items, this would seed the main list with the support item as
// preview - and ChatInfo.Group.id ignores the scope, so that entry shadows the real group
addChat(Chat(remoteHostId = rhId, chatInfo = cInfo, chatItems = arrayListOf(cItem)))
itemAdded = true
}