Skip to content

Commit

Permalink
Added context menu entry in media view: Show in Chat
Browse files Browse the repository at this point in the history
  • Loading branch information
findus committed Nov 19, 2024
1 parent 5a62976 commit cf2d795
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Signal/AppLaunch/SignalApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ extension SignalApp {
_ thread: TSThread,
action: ConversationViewAction = .none,
focusMessageId: String? = nil,
animated: Bool
animated: Bool,
forceReload: Bool = false
) {
AssertIsOnMainThread()

Expand All @@ -179,7 +180,7 @@ extension SignalApp {
}
return
}
conversationSplitViewController.presentThread(thread, action: action, focusMessageId: focusMessageId, animated: animated)
conversationSplitViewController.presentThread(thread, action: action, focusMessageId: focusMessageId, animated: animated, forceReload: forceReload)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ extension ChatListViewController {
thread,
action: action,
focusMessageId: focusMessageId,
animated: animated
animated: animated,
forceReload: false
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ConversationSplitViewController: UISplitViewController, ConversationSplit
}
}

func presentThread(_ thread: TSThread, action: ConversationViewAction, focusMessageId: String?, animated: Bool) {
func presentThread(_ thread: TSThread, action: ConversationViewAction, focusMessageId: String?, animated: Bool, forceReload: Bool = false) {
AssertIsOnMainThread()

// On iOS 13, there is a bug with UISplitViewController that causes the `isCollapsed` state to
Expand All @@ -137,14 +137,14 @@ class ConversationSplitViewController: UISplitViewController, ConversationSplit
owsFailDebug("check if this still happens")
// Reset this to avoid getting stuck in a loop. We're becoming active.
lastActiveInterfaceOrientation = windowScene.interfaceOrientation
DispatchQueue.main.async { self.presentThread(thread, action: action, focusMessageId: focusMessageId, animated: animated) }
DispatchQueue.main.async { self.presentThread(thread, action: action, focusMessageId: focusMessageId, animated: animated, forceReload: forceReload) }
return
}

if homeVC.selectedHomeTab != .chatList {
guard homeVC.presentedViewController == nil else {
homeVC.dismiss(animated: true) {
self.presentThread(thread, action: action, focusMessageId: focusMessageId, animated: animated)
self.presentThread(thread, action: action, focusMessageId: focusMessageId, animated: animated, forceReload: forceReload)
}
return
}
Expand All @@ -153,7 +153,7 @@ class ConversationSplitViewController: UISplitViewController, ConversationSplit
homeVC.selectedHomeTab = .chatList
}

guard selectedThread?.uniqueId != thread.uniqueId else {
guard ((selectedThread?.uniqueId != thread.uniqueId) || forceReload) else {
// If this thread is already selected, pop to the thread if
// anything else has been presented above the view.
guard let selectedConversationVC = selectedConversationViewController else { return }
Expand Down Expand Up @@ -684,3 +684,4 @@ extension ConversationSplitViewController: DeviceTransferServiceObserver {

func deviceTransferServiceDidRequestAppRelaunch() {}
}

2 changes: 1 addition & 1 deletion Signal/src/ViewControllers/MediaGallery/MediaGallery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class MediaGallery {
typealias Update = Sections.Update
typealias Journal = [JournalingOrderedDictionaryChange<Sections.ItemChange>]

private let thread: TSThread
let thread: TSThread

// Used for filtering.
private(set) var mediaFilter: AllMediaFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,17 @@ class MediaPageViewController: UIPageViewController {
self?.deleteCurrentMedia()
}
))

contextMenuActions.append(UIAction(
title: OWSLocalizedString(
"MEDIA_VIEWER_JUMP_TO_CONVERSATION",
comment: "Context menu item in media viewer. Jumps to position in conversation."
),
image: Theme.iconImage(.arrowUp),
handler: { [weak self] _ in
self?.jumpToConversation()
}
))
contextMenuButton.setActions(actions: contextMenuActions)
}

Expand Down Expand Up @@ -492,6 +503,16 @@ class MediaPageViewController: UIPageViewController {
let sender = fromNavigationBar ? barButtonShareMedia : bottomMediaPanel
AttachmentSharing.showShareUI(for: attachmentStream, sender: sender)
}

private func jumpToConversation() {
SignalApp.shared.presentConversationForThread(
mediaGallery.thread,
focusMessageId: currentViewController?.galleryItem.message.uniqueId,
animated: true,
forceReload: true
)
self.dismiss(animated: false)
}

private func deleteCurrentMedia() {
guard let mediaItem = currentItem else { return }
Expand Down Expand Up @@ -870,3 +891,4 @@ extension MediaPageViewController: UINavigationBarDelegate {
dismissSelf(animated: true)
}
}

3 changes: 3 additions & 0 deletions Signal/translations/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -4168,6 +4168,9 @@
/* Context menu item in media viewer. Refers to deleting currently displayed photo/video. */
"MEDIA_VIEWER_DELETE_MEDIA_ACTION" = "Delete";

/* Context menu item in media viewer, Refers to jumping to position in conversation*/
"MEDIA_VIEWER_JUMP_TO_CONVERSATION" = "Show in Chat";

/* button title to snooze a megaphone */
"MEGAPHONE_REMIND_LATER" = "Remind Me Later";

Expand Down

0 comments on commit cf2d795

Please sign in to comment.