From a4a11f99d22d9a1397cf36d562796f760ababb6e Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sun, 11 Aug 2024 07:18:01 +0100 Subject: [PATCH] ios: fix switching to another chat prevents marking items as unread (#4652) --- apps/ios/Shared/Model/ChatModel.swift | 6 ++++++ apps/ios/Shared/Views/Chat/ChatView.swift | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/ios/Shared/Model/ChatModel.swift b/apps/ios/Shared/Model/ChatModel.swift index 0539269ac7..b302443d11 100644 --- a/apps/ios/Shared/Model/ChatModel.swift +++ b/apps/ios/Shared/Model/ChatModel.swift @@ -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 { diff --git a/apps/ios/Shared/Views/Chat/ChatView.swift b/apps/ios/Shared/Views/Chat/ChatView.swift index f4df8005aa..7951d1865f 100644 --- a/apps/ios/Shared/Views/Chat/ChatView.swift +++ b/apps/ios/Shared/Views/Chat/ChatView.swift @@ -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() @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) }