Skip to content

Commit

Permalink
Fixed issue when remote reaction wasn't appear in the chat real time (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg-Pecheneg authored Feb 29, 2024
1 parent 9f7b73c commit 288a4e6
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1120,20 +1120,27 @@ extension ChatViewModel: MessagingServiceListener {
case .existingChat(let chat) = conversationState,
chatId == chat.id,
!messages.isEmpty {
let messages = messages.filter { !$0.isReactionMessage }
await self.addMessages(messages, scrollToBottom: true)
}
}

private func updateMessageFromUpdatedData(_ updatedMessage: MessagingChatMessageDisplayInfo, with newMessage: MessagingChatMessageDisplayInfo) async {
if case .existingChat(let chat) = conversationState,
updatedMessage.chatId == chat.id,
let i = self.messages.firstIndex(where: { $0.id == updatedMessage.id }) {
guard case .existingChat(let chat) = conversationState,
updatedMessage.chatId == chat.id else { return }

if let i = self.messages.firstIndex(where: { $0.id == updatedMessage.id }) {
var newMessage = newMessage
await newMessage.prepareToDisplay()
self.messages[i] = newMessage
messagesCache.remove(updatedMessage)
messagesCache.insert(newMessage)
}

if case .reaction(let info) = updatedMessage.type {
let currentReactions = messagesToReactions[info.messageId] ?? []
let filteredReactions = currentReactions.filter({ $0.messageId == updatedMessage.id })
messagesToReactions[info.messageId] = filteredReactions
}
}
}

Expand Down

0 comments on commit 288a4e6

Please sign in to comment.