Skip to content

Commit

Permalink
Fixed bug with disappearing messages
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmitrevski committed Nov 23, 2023
1 parent ca4d3f7 commit 6575128
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/StreamChatSwiftUI/Utils/MessageCachingUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6575128

Please sign in to comment.