Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update referencing messages when a message was updated #1404

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 Expand Up @@ -2355,7 +2369,7 @@
return super.numberOfSections(in: tableView)
}

// TODO: There should be a better place to do this

Check warning on line 2372 in NextcloudTalk/BaseChatViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (There should be a better place...) (todo)
if tableView == self.tableView, !self.dateSections.isEmpty {
tableView.backgroundView = nil
} else {
Expand Down Expand Up @@ -2747,7 +2761,7 @@
let maxPreviewWidth = self.view.bounds.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right
let maxPreviewHeight = self.view.bounds.size.height * 0.6

// TODO: Take padding into account

Check warning on line 2764 in NextcloudTalk/BaseChatViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (Take padding into account) (todo)
let maxTextWidth = maxPreviewWidth - kChatCellAvatarHeight

// We need to get the height of the original cell to center the preview correctly (as the preview is always non-grouped)
Expand Down
Loading