Skip to content

Commit

Permalink
Update referencing messages when a message was updated
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Oct 30, 2023
1 parent f4dd251 commit b3b6350
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 b3b6350

Please sign in to comment.