From 657512878c2adec9d6fa3bcb8fb2e91b3f5abb8f Mon Sep 17 00:00:00 2001 From: martinmitrevski Date: Thu, 23 Nov 2023 16:53:54 +0100 Subject: [PATCH] Fixed bug with disappearing messages --- .../ChatChannel/ChatChannelViewModel.swift | 12 +++++++++--- .../Utils/MessageCachingUtils.swift | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift index e2f77d15..5a8756b9 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift @@ -42,7 +42,6 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource { private var loadingPreviousMessages: Bool = false private var loadingMessagesAround: Bool = false - private var jumpedToOtherPage: Bool = false private var lastMessageRead: String? private var disableDateIndicator = false private var channelName = "" @@ -141,7 +140,12 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource { messages = channelDataSource.messages DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in - self?.scrolledId = scrollToMessage?.messageId + if let scrollToMessage, scrollToMessage.parentMessageId != nil, messageController == nil { + self?.threadMessage = scrollToMessage + self?.threadMessageShown = true + } else { + self?.scrolledId = scrollToMessage?.messageId + } } NotificationCenter.default.addObserver( @@ -214,6 +218,9 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource { } return true } else { + if messageCachingUtils.isQuotedMessage(with: messageId) && !isMessageThread { + return false + } scrolledId = nil if loadingMessagesAround { return false @@ -226,7 +233,6 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource { } DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { self?.scrolledId = messageId - self?.jumpedToOtherPage = true self?.loadingMessagesAround = false } } diff --git a/Sources/StreamChatSwiftUI/Utils/MessageCachingUtils.swift b/Sources/StreamChatSwiftUI/Utils/MessageCachingUtils.swift index 36876f73..1ae948f6 100644 --- a/Sources/StreamChatSwiftUI/Utils/MessageCachingUtils.swift +++ b/Sources/StreamChatSwiftUI/Utils/MessageCachingUtils.swift @@ -73,6 +73,16 @@ class MessageCachingUtils { return quoted } + + func isQuotedMessage(with id: String) -> Bool { + for (_, value) in quotedMessageMapping { + if value.messageId == id { + return true + } + } + + return false + } func userDisplayInfo(with id: String) -> UserDisplayInfo? { for userInfo in messageAuthors.values {