Skip to content

Commit

Permalink
Merge pull request #1149 from MixinNetwork/feature/navi_to_image
Browse files Browse the repository at this point in the history
Show image in chat
  • Loading branch information
over140 authored Oct 25, 2022
2 parents 6dfd9e4 + 7bc7910 commit 4719b80
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 23 deletions.
1 change: 1 addition & 0 deletions Mixin/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@
"shopping" = "Shopping";
"show" = "Show";
"show_asset" = "Show asset";
"show_in_chat" = "Show in chat";
"sign_in" = "Sign in";
"sign_with_emergency_contact" = "Sign in with emergency contact";
"sign_with_phone_number" = "Sign in with phone number";
Expand Down
1 change: 1 addition & 0 deletions Mixin/Resources/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@
"shopping" = "買い物";
"show" = "表示";
"show_asset" = "資産を表示する";
"show_in_chat" = "チャット内で表示";
"sign_in" = "ログイン";
"sign_with_emergency_contact" = "緊急連絡先でログイン";
"sign_with_phone_number" = "電話番号でログイン";
Expand Down
1 change: 1 addition & 0 deletions Mixin/Resources/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@
"shopping" = "Покупка";
"show" = "Показать";
"show_asset" = "Показать актив";
"show_in_chat" = "Показать в чате";
"sign_in" = "Войти";
"sign_with_emergency_contact" = "Войти через контакт для экстренных случаев";
"sign_with_phone_number" = "Войти через номер телефона";
Expand Down
1 change: 1 addition & 0 deletions Mixin/Resources/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@
"shopping" = "购物";
"show" = "显示";
"show_asset" = "显示资产";
"show_in_chat" = "在聊天中展示";
"sign_in" = "登录";
"sign_with_emergency_contact" = "通过紧急联系人登录";
"sign_with_phone_number" = "通过手机号登录";
Expand Down
1 change: 1 addition & 0 deletions Mixin/Resources/zh-Hant.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@
"shopping" = "購物";
"show" = "顯示";
"show_asset" = "顯示資產";
"show_in_chat" = "在聊天中展示";
"sign_in" = "登入";
"sign_with_emergency_contact" = "透過緊急聯絡人登入";
"sign_with_phone_number" = "透過手機號登入";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,16 @@ class ConversationViewController: UIViewController {
}
}

func scrollToMessage(messageId: String) {
if let indexPath = dataSource.indexPath(where: { $0.messageId == messageId }) {
scheduleCellBackgroundFlash(messageId: messageId)
tableView.scrollToRow(at: indexPath, at: .middle, animated: true)
} else if MessageDAO.shared.hasMessage(id: messageId) {
messageIdToFlashAfterAnimationFinished = messageId
reloadWithMessageId(messageId, scrollUpwards: true)
}
}

}

// MARK: - UIGestureRecognizerDelegate
Expand Down Expand Up @@ -1863,7 +1873,7 @@ extension ConversationViewController: PinMessageBannerViewDelegate {
let quoteMessageId = MessageDAO.shared.quoteMessageId(messageId: id) else {
return
}
scrollToPinnedMessage(messageId: quoteMessageId)
scrollToMessage(messageId: quoteMessageId)
}

}
Expand All @@ -1872,8 +1882,8 @@ extension ConversationViewController: PinMessageBannerViewDelegate {
extension ConversationViewController: PinMessagesPreviewViewControllerDelegate {

func pinMessagesPreviewViewController(_ controller: PinMessagesPreviewViewController, needsShowMessage messageId: String) {
controller.dismissAsChild {
self.scrollToPinnedMessage(messageId: messageId)
controller.dismissAsChild(animated: true) {
self.scrollToMessage(messageId: messageId)
}
}

Expand Down Expand Up @@ -2803,16 +2813,6 @@ extension ConversationViewController {
}
}

private func scrollToPinnedMessage(messageId: String) {
if let indexPath = dataSource.indexPath(where: { $0.messageId == messageId }) {
scheduleCellBackgroundFlash(messageId: messageId)
tableView.scrollToRow(at: indexPath, at: .middle, animated: true)
} else if MessageDAO.shared.hasMessage(id: messageId) {
messageIdToFlashAfterAnimationFinished = messageId
reloadWithMessageId(messageId, scrollUpwards: true)
}
}

private func updateMessagePinningAvailability() {
let isAvailable = dataSource.category != .group
|| ParticipantDAO.shared.isAdmin(conversationId: conversationId, userId: myUserId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,27 @@ final class GalleryImageItemViewController: GalleryItemViewController {

override var supportedActions: Action {
if let item = item {
if item.url == nil {
return [.forward]
let isTranscriptPreviewPresented = UIApplication
.currentConversationViewController()?
.children
.contains(where: { $0 is TranscriptPreviewViewController }) ?? false
if isTranscriptPreviewPresented {
if item.url == nil {
return [.forward]
} else {
return [.forward, .saveToLibrary, .share]
}
} else {
return [.forward, .saveToLibrary, .share]
if item.url == nil {
return [.forward, .showInChat]
} else {
let conversation = UIApplication.homeNavigationController?.viewControllers.compactMap({ $0 as? ConversationViewController }).last
if let id = conversation?.conversationId, id == item.conversationId {
return [.forward, .saveToLibrary, .share, .showInChat]
} else {
return [.forward, .saveToLibrary, .share]
}
}
}
} else {
return []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class GalleryItemViewController: UIViewController {
static let forward = Action(rawValue: 1 << 0)
static let saveToLibrary = Action(rawValue: 1 << 1)
static let share = Action(rawValue: 1 << 2)
static let showInChat = Action(rawValue: 1 << 3)
}

let operationButton = LargeModernNetworkOperationButton()
Expand Down
26 changes: 26 additions & 0 deletions Mixin/UserInterface/Controllers/Chat/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,27 @@ final class GalleryViewController: UIViewController, GalleryAnimatable {
}
}

func showInChat() {
guard let messageId = currentItemViewController?.item?.messageId else {
return
}
guard let conversationController = UIApplication.homeNavigationController?.viewControllers.first(where: { $0 is ConversationViewController }) as? ConversationViewController else {
return
}
let sharedMedia = UIApplication.homeNavigationController?.viewControllers
.compactMap({ $0 as? ContainerViewController })
.compactMap({ $0.viewController as? SharedMediaViewController })
.first
if let sharedMedia {
sharedMedia.navigationController?.popViewController(animated: false)
} else if let pinMessagesPreview = conversationController.children.first(where: { $0 is PinMessagesPreviewViewController }) as? PinMessagesPreviewViewController {
pinMessagesPreview.dismissAsChild(animated: false, completion: nil)
}
dismiss(transitionViewInitialOffsetY: 0) {
conversationController.scrollToMessage(messageId: messageId)
}
}

@objc func panAction(_ recognizer: UIPanGestureRecognizer) {
let translation = recognizer.translation(in: view)
let progress = min(1, max(0, translation.y / (view.bounds.height / 3)))
Expand Down Expand Up @@ -382,6 +403,11 @@ final class GalleryViewController: UIViewController, GalleryAnimatable {
}
}))
}
if itemViewController.supportedActions.contains(.showInChat) {
alert.addAction(UIAlertAction(title: R.string.localizable.show_in_chat(), style: .default, handler: { (_) in
self.showInChat()
}))
}
alert.addAction(UIAlertAction(title: R.string.localizable.cancel(), style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extension PinMessagesPreviewViewController {
controller.addAction(UIAlertAction(title: R.string.localizable.unpin(), style: .default) { _ in
self.ignoresPinMessageChangeNotification = true
SendMessageService.shared.sendPinMessages(items: self.pinnedMessageItems, conversationId: self.conversationId, action: .unpin)
self.dismissAsChild(completion: nil)
self.dismissAsChild(animated: true, completion: nil)
})
present(controller, animated: true, completion: nil)
}
Expand Down Expand Up @@ -163,7 +163,7 @@ extension PinMessagesPreviewViewController {
queue.async {
guard PinMessageDAO.shared.hasMessage(conversationId: conversationId) else {
DispatchQueue.main.async {
self.dismissAsChild(completion: nil)
self.dismissAsChild(animated: true, completion: nil)
}
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class StaticMessagesViewController: UIViewController {
}

@IBAction func dismissAction(_ sender: Any) {
dismissAsChild(completion: nil)
dismissAsChild(animated: true, completion: nil)
}

func attachmentURL(withFilename filename: String) -> URL? {
Expand Down Expand Up @@ -132,13 +132,13 @@ class StaticMessagesViewController: UIViewController {
})
}

func dismissAsChild(completion: (() -> Void)?) {
func dismissAsChild(animated: Bool, completion: (() -> Void)?) {
if didPlayAudioMessage {
audioManager.stop()
}
showContentConstraint.priority = .defaultLow
hideContentConstraint.priority = .defaultHigh
UIView.animate(withDuration: 0.5, delay: 0, options: .overdampedCurve) {
UIView.animate(withDuration: animated ? 0.5 : 0, delay: 0, options: .overdampedCurve) {
self.view.layoutIfNeeded()
self.view.backgroundColor = .black.withAlphaComponent(0)
} completion: { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension TranscriptPreviewViewController {
else {
return
}
dismissAsChild(completion: nil)
dismissAsChild(animated: true, completion: nil)
}

@objc private func mediaStatusDidUpdate(_ notification: Notification) {
Expand Down Expand Up @@ -131,7 +131,7 @@ extension TranscriptPreviewViewController {
guard let messageId = notification.userInfo?[ExpiredMessageDAO.messageIdKey] as? String, messageId == transcriptMessage.messageId else {
return
}
dismissAsChild(completion: nil)
dismissAsChild(animated: true, completion: nil)
}

}
Expand Down

0 comments on commit 4719b80

Please sign in to comment.