From 623e4c610109123b951d940044a4899bf12c5aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sat, 2 Dec 2023 17:17:28 +0100 Subject: [PATCH 1/8] Show filename in SharedItemsTableViewController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- NextcloudTalk/RoomSharedItemsTableViewController.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/NextcloudTalk/RoomSharedItemsTableViewController.swift b/NextcloudTalk/RoomSharedItemsTableViewController.swift index 864775e36..ce6d3cc29 100644 --- a/NextcloudTalk/RoomSharedItemsTableViewController.swift +++ b/NextcloudTalk/RoomSharedItemsTableViewController.swift @@ -383,7 +383,12 @@ import QuickLook let message = currentItems[indexPath.row] - cell.fileNameLabel?.text = message.parsedMessage().string + if let file = message.file() { + cell.fileNameLabel?.text = file.name + } else { + cell.fileNameLabel?.text = message.parsedMessage().string + } + var infoLabelText = NCUtils.relativeTimeFromDate(date: Date(timeIntervalSince1970: Double(message.timestamp))) if !message.actorDisplayName.isEmpty { infoLabelText += " ⸱ " + message.actorDisplayName From bfaaf65f5d5b56c8f87755c3eda376870e5f57d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sat, 2 Dec 2023 22:18:34 +0100 Subject: [PATCH 2/8] Change style of RoomSharedItemsTableViewController to insetGrouped MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- .../RoomSharedItemsTableViewController.xib | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/NextcloudTalk/RoomSharedItemsTableViewController.xib b/NextcloudTalk/RoomSharedItemsTableViewController.xib index 6a564d84f..01880255f 100644 --- a/NextcloudTalk/RoomSharedItemsTableViewController.xib +++ b/NextcloudTalk/RoomSharedItemsTableViewController.xib @@ -1,11 +1,10 @@ - + - + - @@ -15,11 +14,10 @@ - + - @@ -27,9 +25,4 @@ - - - - - From 2b3b3183da8b6479f27f37c1d9954460421402cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sat, 2 Dec 2023 22:37:55 +0100 Subject: [PATCH 3/8] Use contentOffset to correctly position the highlighted message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- NextcloudTalk/BaseChatViewController.swift | 53 ++++++++++++++++------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/NextcloudTalk/BaseChatViewController.swift b/NextcloudTalk/BaseChatViewController.swift index 843dfa72e..cad4d8d0f 100644 --- a/NextcloudTalk/BaseChatViewController.swift +++ b/NextcloudTalk/BaseChatViewController.swift @@ -202,7 +202,9 @@ import QuickLook NCUserInterfaceController.sharedInstance().numberOfAllocatedChatViewControllers += 1 } - public convenience init?(for room: NCRoom, withMessage messages: [NCChatMessage]) { + // Not using an optional here, because it is not available from ObjC + // Pass "0" as highlightMessageId to not highlight a message + public convenience init?(for room: NCRoom, withMessage messages: [NCChatMessage], withHighlightId highlightMessageId: Int) { self.init(for: room) // When we pass in a fixed number of messages, we hide the inputbar by default @@ -213,18 +215,33 @@ import QuickLook self.tableView?.slk_scrollToBottom(animated: false) self.appendMessages(messages: messages) - self.tableView?.reloadData() - } - // Not using an optional here, because it is not available from ObjC - public convenience init?(for room: NCRoom, withMessage messages: [NCChatMessage], withHighlightId highlightMessageId: Int) { - self.init(for: room, withMessage: messages) + guard let tableView = self.tableView + else { return } - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - if let (indexPath, _) = self.indexPathAndMessage(forMessageId: highlightMessageId) { - self.highlightMessage(at: indexPath, with: .middle) - } - } + tableView.performBatchUpdates({ + tableView.reloadData() + }, completion: { _ in + guard highlightMessageId > 0, + let (indexPath, message) = self.indexPathAndMessage(forMessageId: highlightMessageId) + else { return } + + self.highlightMessage(at: indexPath, with: .none) + + let messageHeight = self.getCellHeight(for: message) + let rect = tableView.rectForRow(at: indexPath) + + // ContentOffset when the cell is at the top of the tableView + let contentOffsetTop = rect.origin.y - tableView.safeAreaInsets.top + + // ContentOffset when the cell is at the middle of the tableView + let contentOffsetMiddle = contentOffsetTop - tableView.frame.height / 2 + messageHeight / 2 + + // Fallback to the top offset in case the top of the cell would be scrolled outside of the view + let newContentOffset = min(contentOffsetTop, contentOffsetMiddle) + + tableView.contentOffset.y = newContentOffset + }) } required init?(coder decoder: NSCoder) { @@ -2550,15 +2567,21 @@ import QuickLook } if let message = self.message(for: indexPath) { - var width = tableView.frame.width - kChatCellAvatarHeight - width -= tableView.safeAreaInsets.left + tableView.safeAreaInsets.right - - return self.getCellHeight(for: message, with: width) + return self.getCellHeight(for: message) } return kChatMessageCellMinimumHeight } + func getCellHeight(for message: NCChatMessage) -> CGFloat { + guard let tableView = self.tableView else { return kChatMessageCellMinimumHeight } + + var width = tableView.frame.width - kChatCellAvatarHeight + width -= tableView.safeAreaInsets.left + tableView.safeAreaInsets.right + + return self.getCellHeight(for: message, with: width) + } + // swiftlint:disable:next cyclomatic_complexity func getCellHeight(for message: NCChatMessage, with originalWidth: CGFloat) -> CGFloat { // Chat separators From 6ef61760888ae40ac6bb3f69f9b83e13e36a7191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sat, 2 Dec 2023 22:42:22 +0100 Subject: [PATCH 4/8] Add Message-Context API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- NextcloudTalk/NCAPIController.h | 2 ++ NextcloudTalk/NCAPIController.m | 34 +++++++++++++++++++++++++++++++ NextcloudTalk/NCChatController.h | 2 ++ NextcloudTalk/NCChatController.m | 35 ++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) diff --git a/NextcloudTalk/NCAPIController.h b/NextcloudTalk/NCAPIController.h index 85d154e7a..9b5eb9c10 100644 --- a/NextcloudTalk/NCAPIController.h +++ b/NextcloudTalk/NCAPIController.h @@ -72,6 +72,7 @@ typedef void (^DeleteChatMessageCompletionBlock)(NSDictionary *messageDict, NSEr typedef void (^ClearChatHistoryCompletionBlock)(NSDictionary *messageDict, NSError *error, NSInteger statusCode); typedef void (^GetSharedItemsOverviewCompletionBlock)(NSDictionary *sharedItemsOverview, NSError *error, NSInteger statusCode); typedef void (^GetSharedItemsCompletionBlock)(NSArray *sharedItems, NSInteger lastKnownMessage, NSError *error, NSInteger statusCode); +typedef void (^GetMessageContextInRoomCompletionBlock)(NSArray *messages, NSError *error, NSInteger statusCode); typedef void (^GetTranslationsCompletionBlock)(NSArray *languages, BOOL languageDetection, NSError *error, NSInteger statusCode); typedef void (^MessageTranslationCompletionBlock)(NSDictionary *translationDict, NSError *error, NSInteger statusCode); @@ -224,6 +225,7 @@ extern NSInteger const kReceivedChatMessagesLimit; - (NSURLSessionDataTask *)markChatAsUnreadInRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(SendChatMessagesCompletionBlock)block; - (NSURLSessionDataTask *)getSharedItemsOverviewInRoom:(NSString *)token withLimit:(NSInteger)limit forAccount:(TalkAccount *)account withCompletionBlock:(GetSharedItemsOverviewCompletionBlock)block; - (NSURLSessionDataTask *)getSharedItemsOfType:(NSString *)objectType fromLastMessageId:(NSInteger)messageId withLimit:(NSInteger)limit inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(GetSharedItemsCompletionBlock)block; +- (NSURLSessionDataTask *)getMessageContextInRoom:(NSString *)token forMessageId:(NSInteger)messageId withLimit:(NSInteger)limit forAccount:(TalkAccount *)account withCompletionBlock:(GetMessageContextInRoomCompletionBlock)block; // Translations - (NSURLSessionDataTask *)getAvailableTranslationsForAccount:(TalkAccount *)account withCompletionBlock:(GetTranslationsCompletionBlock)block; diff --git a/NextcloudTalk/NCAPIController.m b/NextcloudTalk/NCAPIController.m index 8e32637de..43ee5f1e1 100644 --- a/NextcloudTalk/NCAPIController.m +++ b/NextcloudTalk/NCAPIController.m @@ -1587,6 +1587,7 @@ - (NSURLSessionDataTask *)getSharedItemsOverviewInRoom:(NSString *)token withLim return task; } + - (NSURLSessionDataTask *)getSharedItemsOfType:(NSString *)objectType fromLastMessageId:(NSInteger)messageId withLimit:(NSInteger)limit inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(GetSharedItemsCompletionBlock)block { NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]; @@ -1637,6 +1638,39 @@ - (NSURLSessionDataTask *)getSharedItemsOfType:(NSString *)objectType fromLastMe return task; } +- (NSURLSessionDataTask *)getMessageContextInRoom:(NSString *)token forMessageId:(NSInteger)messageId withLimit:(NSInteger)limit forAccount:(TalkAccount *)account withCompletionBlock:(GetMessageContextInRoomCompletionBlock)block +{ + NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]; + NSString *endpoint = [NSString stringWithFormat:@"chat/%@/%ld/context", encodedToken, (long)messageId]; + NSInteger chatAPIVersion = [self chatAPIVersionForAccount:account]; + NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:chatAPIVersion forAccount:account]; + + NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init]; + + if (limit && limit > 0) { + // Limit is optional server-side and defaults to 50, maximum is 100 + [parameters setObject:@(limit) forKey:@"limit"]; + } + + NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId]; + + NSURLSessionDataTask *task = [apiSessionManager GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + NSArray *responseMessages = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"]; + + if (block) { + block(responseMessages, nil, 0); + } + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSInteger statusCode = [self getResponseStatusCode:task.response]; + [self checkResponseStatusCode:statusCode forAccount:account]; + if (block) { + block(nil, error, statusCode); + } + }]; + + return task; +} + #pragma mark - Translations Controller - (NSURLSessionDataTask *)getAvailableTranslationsForAccount:(TalkAccount *)account withCompletionBlock:(GetTranslationsCompletionBlock)block diff --git a/NextcloudTalk/NCChatController.h b/NextcloudTalk/NCChatController.h index 80afb3bd3..07ebcb48b 100644 --- a/NextcloudTalk/NCChatController.h +++ b/NextcloudTalk/NCChatController.h @@ -26,6 +26,7 @@ #import "NCChatMessage.h" typedef void (^UpdateHistoryInBackgroundCompletionBlock)(NSError *error); +typedef void (^GetMessagesContextCompletionBlock)(NSArray * _Nullable messages); @class NCRoom; @@ -65,5 +66,6 @@ extern NSString * const NCChatControllerDidReceiveMessagesInBackgroundNotificati - (void)removeExpiredMessages; - (BOOL)hasHistoryFromMessageId:(NSInteger)messageId; - (void)storeMessages:(NSArray *)messages withRealm:(RLMRealm *)realm; +- (void)getMessageContextForMessageId:(NSInteger)messageId withLimit:(NSInteger)limit withCompletionBlock:(GetMessagesContextCompletionBlock)block; @end diff --git a/NextcloudTalk/NCChatController.m b/NextcloudTalk/NCChatController.m index 2397fb082..9b6209b70 100644 --- a/NextcloudTalk/NCChatController.m +++ b/NextcloudTalk/NCChatController.m @@ -814,4 +814,39 @@ - (BOOL)hasHistoryFromMessageId:(NSInteger)messageId return YES; } +- (void)getMessageContextForMessageId:(NSInteger)messageId withLimit:(NSInteger)limit withCompletionBlock:(GetMessagesContextCompletionBlock)block +{ + [[NCAPIController sharedInstance] getMessageContextInRoom:self.room.token forMessageId:messageId withLimit:limit forAccount:self.account withCompletionBlock:^(NSArray *messages, NSError *error, NSInteger statusCode) { + if (error) { + if (block) { + block(nil); + } + + return; + } + + NSMutableArray *chatMessages = [[NSMutableArray alloc] initWithCapacity:messages.count]; + + for (NSDictionary *messageDict in messages) { + NCChatMessage *message = [NCChatMessage messageWithDictionary:messageDict andAccountId:self.account.accountId]; + [chatMessages addObject:message]; + + if (!message.file) { + continue; + } + + // Try to get the stored preview height from our database, when the message is already stored + NCChatMessage *managedMessage = [NCChatMessage objectsWhere:@"internalId = %@", message.internalId].firstObject; + + if (managedMessage && managedMessage.file && managedMessage.file.previewImageHeight > 0) { + message.file.previewImageHeight = managedMessage.file.previewImageHeight; + } + } + + if (block) { + block(chatMessages); + } + }]; +} + @end From 734c07147d46d87eb50c0e7c64439bd3740d5413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sat, 2 Dec 2023 23:50:54 +0100 Subject: [PATCH 5/8] Move contentOffset logic for highlighting to separate func MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- NextcloudTalk/BaseChatViewController.swift | 55 ++++++++++++---------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/NextcloudTalk/BaseChatViewController.swift b/NextcloudTalk/BaseChatViewController.swift index cad4d8d0f..38c9193f4 100644 --- a/NextcloudTalk/BaseChatViewController.swift +++ b/NextcloudTalk/BaseChatViewController.swift @@ -216,31 +216,10 @@ import QuickLook self.appendMessages(messages: messages) - guard let tableView = self.tableView - else { return } - - tableView.performBatchUpdates({ - tableView.reloadData() + self.tableView?.performBatchUpdates({ + self.tableView?.reloadData() }, completion: { _ in - guard highlightMessageId > 0, - let (indexPath, message) = self.indexPathAndMessage(forMessageId: highlightMessageId) - else { return } - - self.highlightMessage(at: indexPath, with: .none) - - let messageHeight = self.getCellHeight(for: message) - let rect = tableView.rectForRow(at: indexPath) - - // ContentOffset when the cell is at the top of the tableView - let contentOffsetTop = rect.origin.y - tableView.safeAreaInsets.top - - // ContentOffset when the cell is at the middle of the tableView - let contentOffsetMiddle = contentOffsetTop - tableView.frame.height / 2 + messageHeight / 2 - - // Fallback to the top offset in case the top of the cell would be scrolled outside of the view - let newContentOffset = min(contentOffsetTop, contentOffsetMiddle) - - tableView.contentOffset.y = newContentOffset + self.highlightMessageWithContentOffset(messageId: highlightMessageId) }) } @@ -3029,6 +3008,34 @@ import QuickLook } } + internal func highlightMessageWithContentOffset(messageId: Int) { + guard messageId > 0, + let tableView = self.tableView, + let (indexPath, message) = self.indexPathAndMessage(forMessageId: messageId) + else { return } + + self.highlightMessage(at: indexPath, with: .none) + + let messageHeight = self.getCellHeight(for: message) + let rect = tableView.rectForRow(at: indexPath) + + // ContentOffset when the cell is at the top of the tableView + let contentOffsetTop = rect.origin.y - tableView.safeAreaInsets.top + + // ContentOffset when the cell is at the middle of the tableView + let contentOffsetMiddle = contentOffsetTop - tableView.frame.height / 2 + messageHeight / 2 + + // Fallback to the top offset in case the top of the cell would be scrolled outside of the view + let newContentOffset = min(contentOffsetTop, contentOffsetMiddle) + + tableView.contentOffset.y = newContentOffset + } + + public func reloadDataAndHighlightMessage(messageId: Int) { + self.tableView?.reloadData() + self.highlightMessageWithContentOffset(messageId: messageId) + } + func showNewMessagesView(until message: NCChatMessage) { self.firstUnreadMessage = message self.unreadMessageButton.isHidden = false From b217808db453d851392b08023cc1b6cc8369804e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sat, 2 Dec 2023 23:53:34 +0100 Subject: [PATCH 6/8] Show message context as preview MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- .../RoomSharedItemsTableViewController.swift | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/NextcloudTalk/RoomSharedItemsTableViewController.swift b/NextcloudTalk/RoomSharedItemsTableViewController.swift index ce6d3cc29..0e4904a29 100644 --- a/NextcloudTalk/RoomSharedItemsTableViewController.swift +++ b/NextcloudTalk/RoomSharedItemsTableViewController.swift @@ -414,6 +414,40 @@ import QuickLook return cell } + weak var previewChatViewController: BaseChatViewController? + + override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { + return UIContextMenuConfiguration(identifier: indexPath as NSCopying, previewProvider: { + + // Init the BaseChatViewController without message to directly show a preview + if let chatViewController = BaseChatViewController(for: self.room, withMessage: [], withHighlightId: 0) { + self.previewChatViewController = chatViewController + + // Fetch the context of the message and update the BaseChatViewController + let message = self.currentItems[indexPath.row] + NCChatController(for: self.room).getMessageContext(forMessageId: message.messageId, withLimit: 50) { messages in + guard let messages else { return } + + chatViewController.appendMessages(messages: messages) + chatViewController.reloadDataAndHighlightMessage(messageId: message.messageId) + } + + let navController = NCNavigationController(rootViewController: chatViewController) + return navController + } + + return nil + }, actionProvider: nil) + } + + override func tableView(_ tableView: UITableView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) { + animator.addAnimations { + if let previewChatViewController = self.previewChatViewController { + self.navigationController?.pushViewController(previewChatViewController, animated: false) + } + } + } + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let cell = tableView.cellForRow(at: indexPath) as? DirectoryTableViewCell ?? DirectoryTableViewCell() let message = currentItems[indexPath.row] From 73c46a77340e12947977da23bd7a6df1d85ffb80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sun, 3 Dec 2023 00:04:07 +0100 Subject: [PATCH 7/8] Move from UIAlertController to UIMenu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- .../RoomSharedItemsTableViewController.swift | 43 ++++++++----------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/NextcloudTalk/RoomSharedItemsTableViewController.swift b/NextcloudTalk/RoomSharedItemsTableViewController.swift index 0e4904a29..9689f6d98 100644 --- a/NextcloudTalk/RoomSharedItemsTableViewController.swift +++ b/NextcloudTalk/RoomSharedItemsTableViewController.swift @@ -73,30 +73,6 @@ import QuickLook self.getItemsOverview() } - func presentItemTypeSelector() { - let itemTypesActionSheet = UIAlertController(title: NSLocalizedString("Shared items", comment: ""), message: nil, preferredStyle: .actionSheet) - - for itemType in availableItemTypes() { - let itemTypeName = nameForItemType(itemType: itemType) - let action = UIAlertAction(title: itemTypeName, style: .default) { _ in - self.setupViewForItemType(itemType: itemType) - } - - if itemType == currentItemType { - action.setValue(UIImage(named: "checkmark")?.withRenderingMode(_: .alwaysOriginal), forKey: "image") - } - itemTypesActionSheet.addAction(action) - } - - itemTypesActionSheet.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil)) - - // Presentation on iPads - itemTypesActionSheet.popoverPresentationController?.sourceView = self.navigationItem.titleView - itemTypesActionSheet.popoverPresentationController?.sourceRect = self.navigationItem.titleView?.frame ?? CGRect() - - self.present(itemTypesActionSheet, animated: true, completion: nil) - } - func availableItemTypes() -> [String] { var availableItemTypes: [String] = [] for itemType in sharedItemsOverview.keys { @@ -183,8 +159,25 @@ import QuickLook itemTypeSelectorButton.setTitle(buttonTitle, for: .normal) itemTypeSelectorButton.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .medium) itemTypeSelectorButton.setTitleColor(NCAppBranding.themeTextColor(), for: .normal) - itemTypeSelectorButton.addTarget(self, action: #selector(presentItemTypeSelector), for: .touchUpInside) self.navigationItem.titleView = itemTypeSelectorButton + + var menuActions: [UIAction] = [] + + for itemType in availableItemTypes() { + let itemTypeName = nameForItemType(itemType: itemType) + let action = UIAction(title: itemTypeName, image: nil) { [unowned self] _ in + self.setupViewForItemType(itemType: itemType) + } + + if itemType == currentItemType { + action.state = .on + } + + menuActions.append(action) + } + + itemTypeSelectorButton.showsMenuAsPrimaryAction = true + itemTypeSelectorButton.menu = UIMenu(children: menuActions) } func showFetchingItemsPlaceholderView() { From c1498c51f3e7033f89bd92da35b53082028384f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sun, 3 Dec 2023 17:47:23 +0100 Subject: [PATCH 8/8] Don't calculate the cell height twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- NextcloudTalk/BaseChatViewController.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/NextcloudTalk/BaseChatViewController.swift b/NextcloudTalk/BaseChatViewController.swift index 38c9193f4..49ae52e7a 100644 --- a/NextcloudTalk/BaseChatViewController.swift +++ b/NextcloudTalk/BaseChatViewController.swift @@ -3011,19 +3011,18 @@ import QuickLook internal func highlightMessageWithContentOffset(messageId: Int) { guard messageId > 0, let tableView = self.tableView, - let (indexPath, message) = self.indexPathAndMessage(forMessageId: messageId) + let (indexPath, _) = self.indexPathAndMessage(forMessageId: messageId) else { return } self.highlightMessage(at: indexPath, with: .none) - let messageHeight = self.getCellHeight(for: message) let rect = tableView.rectForRow(at: indexPath) // ContentOffset when the cell is at the top of the tableView let contentOffsetTop = rect.origin.y - tableView.safeAreaInsets.top // ContentOffset when the cell is at the middle of the tableView - let contentOffsetMiddle = contentOffsetTop - tableView.frame.height / 2 + messageHeight / 2 + let contentOffsetMiddle = contentOffsetTop - tableView.frame.height / 2 + rect.height / 2 // Fallback to the top offset in case the top of the cell would be scrolled outside of the view let newContentOffset = min(contentOffsetTop, contentOffsetMiddle)