From 6e6fdadcf2d85162650d01d9057ea3054609c6fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sun, 10 Mar 2024 12:35:31 +0100 Subject: [PATCH] Prefetch reference data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- NextcloudTalk/BaseChatViewController.swift | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/NextcloudTalk/BaseChatViewController.swift b/NextcloudTalk/BaseChatViewController.swift index aa6889d79..a6cee14c6 100644 --- a/NextcloudTalk/BaseChatViewController.swift +++ b/NextcloudTalk/BaseChatViewController.swift @@ -49,7 +49,8 @@ import QuickLook FileMessageTableViewCellDelegate, LocationMessageTableViewCellDelegate, ObjectShareMessageTableViewCellDelegate, - ChatMessageTableViewCellDelegate { + ChatMessageTableViewCellDelegate, + UITableViewDataSourcePrefetching { // MARK: - Internal var internal var messages: [Date: [NCChatMessage]] = [:] @@ -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) @@ -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) {