ios: fix switching to another chat prevents marking items as unread (#4652)

This commit is contained in:
Evgeny
2024-08-11 07:18:01 +01:00
committed by GitHub
parent 7c8955fcdb
commit a4a11f99d2
2 changed files with 11 additions and 2 deletions
+6
View File
@@ -910,6 +910,12 @@ final class Chat: ObservableObject, Identifiable, ChatLike {
chatStats: chatStats ?? self.chatStats
)
}
func copyFrom(_ c: Chat) {
self.chatInfo = c.chatInfo
self.chatItems = c.chatItems
self.chatStats = c.chatStats
}
var userCanSend: Bool {
switch chatInfo {
+5 -2
View File
@@ -21,6 +21,7 @@ struct ChatView: View {
@Environment(\.colorScheme) var colorScheme
@Environment(\.presentationMode) var presentationMode
@Environment(\.scenePhase) var scenePhase
// chat cannot be assigned, as it breaks observation in chat items
@State @ObservedObject var chat: Chat
@StateObject private var scrollModel = ReverseListScrollModel<ChatItem>()
@StateObject private var floatingButtonModel = FloatingButtonModel()
@@ -141,7 +142,8 @@ struct ChatView: View {
if let cId {
selectedChatItems = nil
if let c = chatModel.getChat(cId) {
chat = c
// chat cannot be assigned, as it breaks observation in chat items
chat.copyFrom(c)
}
initChatView()
theme = buildTheme()
@@ -407,7 +409,8 @@ struct ChatView: View {
}
.onChange(of: chatModel.chatId) { chatId in
if let chatId, let c = chatModel.getChat(chatId) {
chat = c
// chat cannot be assigned, as it breaks observation in chat items
chat.copyFrom(c)
showChatInfoSheet = false
loadChat(chat: c)
}