core, ui: update chat ts and pop chat for group on messages for secondary chat scope (#5878)

This commit is contained in:
spaced4ndy
2025-05-08 08:22:46 +00:00
committed by GitHub
parent e3957ba156
commit f5926e8b84
3 changed files with 68 additions and 59 deletions
+15 -10
View File
@@ -564,16 +564,16 @@ final class ChatModel: ObservableObject {
// }
func addChatItem(_ cInfo: ChatInfo, _ cItem: ChatItem) {
// mark chat non deleted
if case let .direct(contact) = cInfo, contact.chatDeleted {
var updatedContact = contact
updatedContact.chatDeleted = false
updateContact(updatedContact)
}
// update chat list
if cInfo.groupChatScope() == nil {
// mark chat non deleted
if case let .direct(contact) = cInfo, contact.chatDeleted {
var updatedContact = contact
updatedContact.chatDeleted = false
updateContact(updatedContact)
}
if let i = getChatIndex(cInfo.id) {
// update preview
if let i = getChatIndex(cInfo.id) {
if cInfo.groupChatScope() == nil {
chats[i].chatItems = switch cInfo {
case .group:
if let currentPreviewItem = chats[i].chatItems.first {
@@ -591,9 +591,14 @@ final class ChatModel: ObservableObject {
if case .rcvNew = cItem.meta.itemStatus {
unreadCollector.changeUnreadCounter(cInfo.id, by: 1, unreadMentions: cItem.meta.userMention ? 1 : 0)
}
popChatCollector.throttlePopChat(cInfo.id, currentPosition: i)
} else {
}
// pop chat
popChatCollector.throttlePopChat(cInfo.id, currentPosition: i)
} else {
if cInfo.groupChatScope() == nil {
addChat(Chat(chatInfo: cInfo, chatItems: [cItem]))
} else {
addChat(Chat(chatInfo: cInfo, chatItems: []))
}
}
// add to current scope
@@ -429,18 +429,18 @@ object ChatModel {
}
suspend fun addChatItem(rhId: Long?, cInfo: ChatInfo, cItem: ChatItem) {
// mark chat non deleted
if (cInfo is ChatInfo.Direct && cInfo.chatDeleted) {
val updatedContact = cInfo.contact.copy(chatDeleted = false)
updateContact(rhId, updatedContact)
}
// update chat list
if (cInfo.groupChatScope() == null) {
// mark chat non deleted
if (cInfo is ChatInfo.Direct && cInfo.chatDeleted) {
val updatedContact = cInfo.contact.copy(chatDeleted = false)
updateContact(rhId, updatedContact)
}
val i = getChatIndex(rhId, cInfo.id)
val chat: Chat
if (i >= 0) {
chat = chats[i]
// update preview
val i = getChatIndex(rhId, cInfo.id)
val chat: Chat
if (i >= 0) {
chat = chats[i]
if (cInfo.groupChatScope() == null) {
val newPreviewItem = when (cInfo) {
is ChatInfo.Group -> {
val currentPreviewItem = chat.chatItems.firstOrNull()
@@ -468,14 +468,18 @@ object ChatModel {
chat.chatStats
)
updateChatTagReadInPrimaryContext(chats[i], wasUnread)
if (appPlatform.isDesktop && cItem.chatDir.sent) {
reorderChat(chats[i], 0)
} else {
popChatCollector.throttlePopChat(chat.remoteHostId, chat.id, currentPosition = i)
}
}
// pop chat
if (appPlatform.isDesktop && cItem.chatDir.sent) {
reorderChat(chats[i], 0)
} else {
popChatCollector.throttlePopChat(chat.remoteHostId, chat.id, currentPosition = i)
}
} else {
if (cInfo.groupChatScope() == null) {
addChat(Chat(remoteHostId = rhId, chatInfo = cInfo, chatItems = arrayListOf(cItem)))
} else {
addChat(Chat(remoteHostId = rhId, chatInfo = cInfo, chatItems = emptyList()))
}
}
// add to current scope
+33 -33
View File
@@ -376,43 +376,43 @@ updateChatTsStats db User {userId} chatDirection chatTs chatStats_ = case toChat
db
"UPDATE contacts SET chat_ts = ?, chat_deleted = 0 WHERE user_id = ? AND contact_id = ?"
(chatTs, userId, contactId)
GroupChat GroupInfo {groupId} Nothing ->
GroupChat GroupInfo {groupId, membership} scopeInfo -> do
DB.execute
db
"UPDATE groups SET chat_ts = ? WHERE user_id = ? AND group_id = ?"
(chatTs, userId, groupId)
GroupChat GroupInfo {membership} (Just GCSIMemberSupport {groupMember_}) -> do
let gmId = groupMemberId' $ fromMaybe membership groupMember_
case chatStats_ of
Nothing ->
DB.execute
db
"UPDATE group_members SET support_chat_ts = ? WHERE group_member_id = ?"
(chatTs, gmId)
Just (unread, MAInc unanswered, mentions) ->
DB.execute
db
[sql|
UPDATE group_members
SET support_chat_ts = ?,
support_chat_items_unread = support_chat_items_unread + ?,
support_chat_items_member_attention = support_chat_items_member_attention + ?,
support_chat_items_mentions = support_chat_items_mentions + ?
WHERE group_member_id = ?
|]
(chatTs, unread, unanswered, mentions, gmId)
Just (unread, MAReset, mentions) ->
DB.execute
db
[sql|
UPDATE group_members
SET support_chat_ts = ?,
support_chat_items_unread = support_chat_items_unread + ?,
support_chat_items_member_attention = 0,
support_chat_items_mentions = support_chat_items_mentions + ?
WHERE group_member_id = ?
|]
(chatTs, unread, mentions, gmId)
forM_ scopeInfo $ \GCSIMemberSupport {groupMember_} -> do
let gmId = groupMemberId' $ fromMaybe membership groupMember_
case chatStats_ of
Nothing ->
DB.execute
db
"UPDATE group_members SET support_chat_ts = ? WHERE group_member_id = ?"
(chatTs, gmId)
Just (unread, MAInc unanswered, mentions) ->
DB.execute
db
[sql|
UPDATE group_members
SET support_chat_ts = ?,
support_chat_items_unread = support_chat_items_unread + ?,
support_chat_items_member_attention = support_chat_items_member_attention + ?,
support_chat_items_mentions = support_chat_items_mentions + ?
WHERE group_member_id = ?
|]
(chatTs, unread, unanswered, mentions, gmId)
Just (unread, MAReset, mentions) ->
DB.execute
db
[sql|
UPDATE group_members
SET support_chat_ts = ?,
support_chat_items_unread = support_chat_items_unread + ?,
support_chat_items_member_attention = 0,
support_chat_items_mentions = support_chat_items_mentions + ?
WHERE group_member_id = ?
|]
(chatTs, unread, mentions, gmId)
LocalChat NoteFolder {noteFolderId} ->
DB.execute
db