Browse Source

show message menu also for video and audio messages. Show copy menu item only for messages with text. Copy only text if that menu item was selected in order to avoid pasting of yet unhandled data formats

cyberta 5 years ago
parent
commit
7700543d19
1 changed files with 13 additions and 7 deletions
  1. 13 7
      deltachat-ios/MessageKit/Controllers/MessagesViewController.swift

+ 13 - 7
deltachat-ios/MessageKit/Controllers/MessagesViewController.swift

@@ -374,7 +374,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
         let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)
 
         switch message.kind {
-        case .text, .attributedText, .emoji, .photo, .photoText, .videoText, .fileText:
+        case .text, .attributedText, .emoji, .photo, .photoText, .videoText, .fileText, .audio, .video:
             selectedIndexPathForMenu = indexPath
             return true
         default:
@@ -386,7 +386,18 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
         if isSectionReservedForTypingIndicator(indexPath.section) {
             return false
         }
-        return (action == NSSelectorFromString("copy:"))
+
+        guard let messagesDataSource = messagesCollectionView.messagesDataSource else {
+            fatalError(MessageKitError.nilMessagesDataSource)
+        }
+        let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)
+
+        switch message.kind {
+        case .text, .emoji, .attributedText, .fileText, .photoText, .videoText:
+            return (action == NSSelectorFromString("copy:"))
+        default:
+            return false
+        }
     }
 
     open func collectionView(_ collectionView: UICollectionView, performAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) {
@@ -401,14 +412,9 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
             pasteBoard.string = text
         case .attributedText(let attributedText):
             pasteBoard.string = attributedText.string
-        case .photo(let mediaItem):
-            pasteBoard.image = mediaItem.image ?? mediaItem.placeholderImage
         case .photoText(let mediaItem), .videoText(let mediaItem):
-            pasteBoard.image = mediaItem.image ?? mediaItem.placeholderImage
             pasteBoard.string = mediaItem.text?.string
-            pasteBoard.url = mediaItem.url
         case .fileText(let mediaItem):
-            pasteBoard.url = mediaItem.url
             pasteBoard.string = mediaItem.text?.string
         default:
             break