Skip to content

Commit

Permalink
Merge pull request #1404 from nextcloud/reload-referencing-messages
Browse files Browse the repository at this point in the history
Update referencing messages when a message was updated
  • Loading branch information
Ivansss authored Nov 3, 2023
2 parents 0ec421f + b3b6350 commit ba2409c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion NextcloudTalk/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,28 @@ import QuickLook
internal func updateMessage(withMessageId messageId: Int, updatedMessage: NCChatMessage) {
DispatchQueue.main.async {
guard let (indexPath, message) = self.indexPathAndMessage(forMessageId: messageId) else { return }
var reloadIndexPaths = [indexPath]

let isAtBottom = self.shouldScrollOnNewMessages()
let keyDate = self.dateSections[indexPath.section]
updatedMessage.isGroupMessage = message.isGroupMessage && message.actorType != "bots"
self.messages[keyDate]?[indexPath.row] = updatedMessage

// Check if there are any messages that reference our message as a parent -> these need to be reloaded as well
if let visibleIndexPaths = self.tableView?.indexPathsForVisibleRows {
let referencingIndexPaths = visibleIndexPaths.filter({
guard let message = self.message(for: $0),
let parentMessage = message.parent()
else { return false }

return parentMessage.messageId == messageId
})

reloadIndexPaths.append(contentsOf: referencingIndexPaths)
}

self.tableView?.beginUpdates()
self.tableView?.reloadRows(at: [indexPath], with: .none)
self.tableView?.reloadRows(at: reloadIndexPaths, with: .none)
self.tableView?.endUpdates()

if isAtBottom {
Expand Down

0 comments on commit ba2409c

Please sign in to comment.