Skip to content

Commit

Permalink
Merge pull request #1916 from nextcloud/issue-1704-open-msg-context-m…
Browse files Browse the repository at this point in the history
…ediaview

Added ability to view context of messages in media viewer
  • Loading branch information
SystemKeeper authored Dec 15, 2024
2 parents e1aa7a5 + 79aa4f6 commit 20c6b71
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
4 changes: 2 additions & 2 deletions NextcloudTalk/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3342,7 +3342,7 @@ import SwiftUI

public func cellWants(toDownloadFile fileParameter: NCMessageFileParameter, for message: NCChatMessage) {
if NCUtils.isImage(fileType: fileParameter.mimetype) {
let mediaViewController = NCMediaViewerViewController(initialMessage: message)
let mediaViewController = NCMediaViewerViewController(initialMessage: message, room: self.room)
let navController = CustomPresentableNavigationController(rootViewController: mediaViewController)

self.present(navController, interactiveDismissalType: .standard)
Expand All @@ -3356,7 +3356,7 @@ import SwiftUI
if NCUtils.isVideo(fileType: fileParameter.mimetype) {
// Skip unsupported formats here ("webm" and "mkv") and use VLC later
if !fileExtension.isEmpty, !VLCKitVideoViewController.supportedFileExtensions.contains(fileExtension) {
let mediaViewController = NCMediaViewerViewController(initialMessage: message)
let mediaViewController = NCMediaViewerViewController(initialMessage: message, room: self.room)
let navController = CustomPresentableNavigationController(rootViewController: mediaViewController)

self.present(navController, interactiveDismissalType: .standard)
Expand Down
39 changes: 37 additions & 2 deletions NextcloudTalk/NCMediaViewerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import UIKit
UIPageViewControllerDataSource,
NCMediaViewerPageViewControllerDelegate {

private let room: NCRoom
private let pageController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal)
private var initialMessage: NCChatMessage

Expand Down Expand Up @@ -38,7 +39,36 @@ import UIKit
return shareButton
}()

init(initialMessage: NCChatMessage) {
private lazy var showMessageButton = {
let showMessageButton = UIBarButtonItem(title: nil, style: .plain, target: nil, action: nil)
showMessageButton.isEnabled = false
showMessageButton.primaryAction = UIAction(title: "", image: .init(systemName: "text.magnifyingglass"), handler: { [unowned self, unowned showMessageButton] _ in
guard let mediaPageViewController = self.getCurrentPageViewController() else { return }

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)

}

let navController = NCNavigationController(rootViewController: chatViewController)
self.present(navController, animated: true)
}

})

return showMessageButton
}()

init(initialMessage: NCChatMessage, room: NCRoom) {
self.room = room
self.initialMessage = initialMessage

super.init(nibName: nil, bundle: nil)
Expand Down Expand Up @@ -87,11 +117,14 @@ import UIKit

let appearance = UIToolbarAppearance()
appearance.backgroundColor = .secondarySystemBackground

self.navigationController?.toolbar.standardAppearance = appearance
self.navigationController?.toolbar.compactAppearance = appearance
self.navigationController?.toolbar.scrollEdgeAppearance = appearance

self.toolbarItems = [shareButton]
let fixedSpace = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
fixedSpace.width = 20
self.toolbarItems = [shareButton, fixedSpace, showMessageButton]
}

func getCurrentPageViewController() -> NCMediaViewerPageViewController? {
Expand Down Expand Up @@ -184,6 +217,7 @@ import UIKit
self.navigationItem.title = mediaPageViewController.navigationItem.title

self.shareButton.isEnabled = (mediaPageViewController.currentImage != nil) || (mediaPageViewController.currentVideoURL != nil)
self.showMessageButton.isEnabled = (mediaPageViewController.currentImage != nil) || (mediaPageViewController.currentVideoURL != nil)
}

// MARK: - NCMediaViewerPageViewController delegate
Expand All @@ -206,6 +240,7 @@ import UIKit
func mediaViewerPageMediaDidLoad(_ controller: NCMediaViewerPageViewController) {
if let mediaPageViewController = self.getCurrentPageViewController(), mediaPageViewController.isEqual(controller) {
self.shareButton.isEnabled = true
self.showMessageButton.isEnabled = true
}
}
}

0 comments on commit 20c6b71

Please sign in to comment.