@@ -73,30 +73,6 @@ import QuickLook
7373 self . getItemsOverview ( )
7474 }
7575
76- func presentItemTypeSelector( ) {
77- let itemTypesActionSheet = UIAlertController ( title: NSLocalizedString ( " Shared items " , comment: " " ) , message: nil , preferredStyle: . actionSheet)
78-
79- for itemType in availableItemTypes ( ) {
80- let itemTypeName = nameForItemType ( itemType: itemType)
81- let action = UIAlertAction ( title: itemTypeName, style: . default) { _ in
82- self . setupViewForItemType ( itemType: itemType)
83- }
84-
85- if itemType == currentItemType {
86- action. setValue ( UIImage ( named: " checkmark " ) ? . withRenderingMode ( _: . alwaysOriginal) , forKey: " image " )
87- }
88- itemTypesActionSheet. addAction ( action)
89- }
90-
91- itemTypesActionSheet. addAction ( UIAlertAction ( title: NSLocalizedString ( " Cancel " , comment: " " ) , style: . cancel, handler: nil ) )
92-
93- // Presentation on iPads
94- itemTypesActionSheet. popoverPresentationController? . sourceView = self . navigationItem. titleView
95- itemTypesActionSheet. popoverPresentationController? . sourceRect = self . navigationItem. titleView? . frame ?? CGRect ( )
96-
97- self . present ( itemTypesActionSheet, animated: true , completion: nil )
98- }
99-
10076 func availableItemTypes( ) -> [ String ] {
10177 var availableItemTypes : [ String ] = [ ]
10278 for itemType in sharedItemsOverview. keys {
@@ -183,8 +159,25 @@ import QuickLook
183159 itemTypeSelectorButton. setTitle ( buttonTitle, for: . normal)
184160 itemTypeSelectorButton. titleLabel? . font = UIFont . systemFont ( ofSize: 17 , weight: . medium)
185161 itemTypeSelectorButton. setTitleColor ( NCAppBranding . themeTextColor ( ) , for: . normal)
186- itemTypeSelectorButton. addTarget ( self , action: #selector( presentItemTypeSelector) , for: . touchUpInside)
187162 self . navigationItem. titleView = itemTypeSelectorButton
163+
164+ var menuActions : [ UIAction ] = [ ]
165+
166+ for itemType in availableItemTypes ( ) {
167+ let itemTypeName = nameForItemType ( itemType: itemType)
168+ let action = UIAction ( title: itemTypeName, image: nil ) { [ unowned self] _ in
169+ self . setupViewForItemType ( itemType: itemType)
170+ }
171+
172+ if itemType == currentItemType {
173+ action. state = . on
174+ }
175+
176+ menuActions. append ( action)
177+ }
178+
179+ itemTypeSelectorButton. showsMenuAsPrimaryAction = true
180+ itemTypeSelectorButton. menu = UIMenu ( children: menuActions)
188181 }
189182
190183 func showFetchingItemsPlaceholderView( ) {
@@ -383,7 +376,12 @@ import QuickLook
383376
384377 let message = currentItems [ indexPath. row]
385378
386- cell. fileNameLabel? . text = message. parsedMessage ( ) . string
379+ if let file = message. file ( ) {
380+ cell. fileNameLabel? . text = file. name
381+ } else {
382+ cell. fileNameLabel? . text = message. parsedMessage ( ) . string
383+ }
384+
387385 var infoLabelText = NCUtils . relativeTimeFromDate ( date: Date ( timeIntervalSince1970: Double ( message. timestamp) ) )
388386 if !message. actorDisplayName. isEmpty {
389387 infoLabelText += " ⸱ " + message. actorDisplayName
@@ -409,6 +407,40 @@ import QuickLook
409407 return cell
410408 }
411409
410+ weak var previewChatViewController : BaseChatViewController ?
411+
412+ override func tableView( _ tableView: UITableView , contextMenuConfigurationForRowAt indexPath: IndexPath , point: CGPoint ) -> UIContextMenuConfiguration ? {
413+ return UIContextMenuConfiguration ( identifier: indexPath as NSCopying , previewProvider: {
414+
415+ // Init the BaseChatViewController without message to directly show a preview
416+ if let chatViewController = BaseChatViewController ( for: self . room, withMessage: [ ] , withHighlightId: 0 ) {
417+ self . previewChatViewController = chatViewController
418+
419+ // Fetch the context of the message and update the BaseChatViewController
420+ let message = self . currentItems [ indexPath. row]
421+ NCChatController ( for: self . room) . getMessageContext ( forMessageId: message. messageId, withLimit: 50 ) { messages in
422+ guard let messages else { return }
423+
424+ chatViewController. appendMessages ( messages: messages)
425+ chatViewController. reloadDataAndHighlightMessage ( messageId: message. messageId)
426+ }
427+
428+ let navController = NCNavigationController ( rootViewController: chatViewController)
429+ return navController
430+ }
431+
432+ return nil
433+ } , actionProvider: nil )
434+ }
435+
436+ override func tableView( _ tableView: UITableView , willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration , animator: UIContextMenuInteractionCommitAnimating ) {
437+ animator. addAnimations {
438+ if let previewChatViewController = self . previewChatViewController {
439+ self . navigationController? . pushViewController ( previewChatViewController, animated: false )
440+ }
441+ }
442+ }
443+
412444 override func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
413445 let cell = tableView. cellForRow ( at: indexPath) as? DirectoryTableViewCell ?? DirectoryTableViewCell ( )
414446 let message = currentItems [ indexPath. row]
0 commit comments