Skip to content

Commit

Permalink
Prefetch reference data
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Mar 10, 2024
1 parent 598eac2 commit 6e6fdad
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion NextcloudTalk/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ import QuickLook
FileMessageTableViewCellDelegate,
LocationMessageTableViewCellDelegate,
ObjectShareMessageTableViewCellDelegate,
ChatMessageTableViewCellDelegate {
ChatMessageTableViewCellDelegate,
UITableViewDataSourcePrefetching {

// MARK: - Internal var
internal var messages: [Date: [NCChatMessage]] = [:]
Expand Down Expand Up @@ -195,6 +196,7 @@ import QuickLook
self.hidesBottomBarWhenPushed = true
self.tableView?.estimatedRowHeight = 0
self.tableView?.estimatedSectionHeaderHeight = 0
self.tableView?.prefetchDataSource = self

FilePreviewImageView.setSharedImageDownloader(NCAPIController.sharedInstance().imageDownloader)
NotificationCenter.default.addObserver(self, selector: #selector(willShowKeyboard(notification:)), name: UIWindow.keyboardWillShowNotification, object: nil)
Expand Down Expand Up @@ -2513,6 +2515,20 @@ import QuickLook
return headerView
}

public func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
guard tableView == self.tableView else { return }

for indexPath in indexPaths {
guard let message = self.message(for: indexPath) else { continue }

DispatchQueue.global(qos: .userInitiated).async {
if message.containsURL() {
message.getReferenceData()
}
}
}
}

public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView != self.autoCompletionView,
let message = self.message(for: indexPath) {
Expand Down

0 comments on commit 6e6fdad

Please sign in to comment.