Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to view context of messages in media viewer #1916

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 31 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,34 @@ 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: 10) { messages in
SystemKeeper marked this conversation as resolved.
Show resolved Hide resolved
guard let messages else { return }

chatViewController.appendMessages(messages: messages)
chatViewController.reloadDataAndHighlightMessage(messageId: message.messageId)
}

self.present(chatViewController, animated: true)
SystemKeeper marked this conversation as resolved.
Show resolved Hide resolved
}

})

return showMessageButton
}()

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

super.init(nibName: nil, bundle: nil)
Expand Down Expand Up @@ -91,7 +119,7 @@ import UIKit
self.navigationController?.toolbar.compactAppearance = appearance
self.navigationController?.toolbar.scrollEdgeAppearance = appearance

self.toolbarItems = [shareButton]
self.toolbarItems = [shareButton, showMessageButton]
SystemKeeper marked this conversation as resolved.
Show resolved Hide resolved
}

func getCurrentPageViewController() -> NCMediaViewerPageViewController? {
Expand Down Expand Up @@ -184,6 +212,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) // TODO include check if msg was loaded
SystemKeeper marked this conversation as resolved.
Show resolved Hide resolved
}

// MARK: - NCMediaViewerPageViewController delegate
Expand Down
Loading