Skip to content

Commit

Permalink
feat(quote): Show context when message is currently not loaded
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
  • Loading branch information
SystemKeeper committed Feb 9, 2025
1 parent ec75d65 commit aeeb7db
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
10 changes: 10 additions & 0 deletions NextcloudTalk/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3608,6 +3608,16 @@ import SwiftUI
DispatchQueue.main.async {
if let indexPath = self.indexPath(for: message) {
self.highlightMessage(at: indexPath, with: .top)
} else {
// Show context of messages that are currently not loaded
guard let account = self.room.account,
let chatViewController = ContextChatViewController(forRoom: self.room, withAccount: account, withMessage: [], withHighlightId: 0)
else { return }

chatViewController.showContext(ofMessageId: message.messageId, withLimit: 50, withCloseButton: true)

let navController = NCNavigationController(rootViewController: chatViewController)
self.present(navController, animated: true)
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions NextcloudTalk/ContextChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,26 @@ import Foundation

self.titleView?.longPressGestureRecognizer.isEnabled = false
}

public func showContext(ofMessageId messageId: Int, withLimit limit: Int, withCloseButton closeButton: Bool) {
// Fetch the context of the message and update the BaseChatViewController
NCChatController(for: self.room).getMessageContext(forMessageId: messageId, withLimit: limit) { [weak self] messages in
guard let self else { return }

guard let messages, messages.count > 0 else {
let errorMessage = NSLocalizedString("Unable to get context of the message", comment: "")
NotificationPresenter.shared().present(text: errorMessage, dismissAfterDelay: 5.0, includedStyle: .dark)
return
}

self.appendMessages(messages: messages)
self.reloadDataAndHighlightMessage(messageId: messageId)
}

if closeButton {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("Close", comment: ""), primaryAction: UIAction { [unowned self] _ in
self.dismiss(animated: true)
})
}
}
}
13 changes: 1 addition & 12 deletions NextcloudTalk/NCMediaViewerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,7 @@ import UIKit
let message = mediaPageViewController.message

if let account = message.account, let chatViewController = ContextChatViewController(forRoom: self.room, withAccount: account, withMessage: [], withHighlightId: 0) {

// Fetch the context of the message and update the BaseChatViewController
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)
}

chatViewController.navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("Close", comment: ""), primaryAction: UIAction { [weak chatViewController] _ in
chatViewController?.dismiss(animated: true)
})
chatViewController.showContext(ofMessageId: message.messageId, withLimit: 50, withCloseButton: true)

let navController = NCNavigationController(rootViewController: chatViewController)
self.present(navController, animated: true)
Expand Down
7 changes: 1 addition & 6 deletions NextcloudTalk/RoomSharedItemsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,7 @@ import QuickLook

// 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)
}
chatViewController.showContext(ofMessageId: message.messageId, withLimit: 50, withCloseButton: false)

let navController = NCNavigationController(rootViewController: chatViewController)
self.previewNavigationChatViewController = navController
Expand Down
18 changes: 1 addition & 17 deletions NextcloudTalk/RoomsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1293,28 +1293,12 @@ - (void)presentContextChatInRoom:(NCRoom *)room forMessageId:(NSInteger)messageI
}

ContextChatViewController *contextChatViewController = [[ContextChatViewController alloc] initForRoom:room withAccount:account withMessage:@[] withHighlightId:0];
contextChatViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(closeContextChat)];

NCChatController *chatController = [[NCChatController alloc] initForRoom:room];
[chatController getMessageContextForMessageId:messageId withLimit:50 withCompletionBlock:^(NSArray<NCChatMessage *> * _Nullable messages) {
if (messages.count > 0) {
[contextChatViewController appendMessagesWithMessages:messages];
[contextChatViewController reloadDataAndHighlightMessageWithMessageId:messageId];
} else {
NSString *errorMessage = NSLocalizedString(@"Unable to get context of the message", nil);
[[JDStatusBarNotificationPresenter sharedPresenter] presentWithText:errorMessage dismissAfterDelay:5.0 includedStyle:JDStatusBarNotificationIncludedStyleDark];
}
}];
[contextChatViewController showContextOfMessageId:messageId withLimit:50 withCloseButton:YES];

_contextChatNavigationController = [[NCNavigationController alloc] initWithRootViewController:contextChatViewController];
[self presentViewController:_contextChatNavigationController animated:YES completion:nil];
}

- (void)closeContextChat
{
[_contextChatNavigationController dismissViewControllerAnimated:YES completion:nil];
}

- (void)createRoomForSelectedUser:(NCUser *)user
{
[[NCAPIController sharedInstance]
Expand Down

0 comments on commit aeeb7db

Please sign in to comment.