Browse Source

send animated image messages when selecting gifs from attach menu

cyberta 5 years ago
parent
commit
27afcf9954
1 changed files with 20 additions and 4 deletions
  1. 20 4
      deltachat-ios/Controller/ChatViewController.swift

+ 20 - 4
deltachat-ios/Controller/ChatViewController.swift

@@ -4,6 +4,7 @@ import UIKit
 import InputBarAccessoryView
 import AVFoundation
 import DcCore
+import SDWebImage
 
 protocol MediaSendHandler {
     func onSuccess()
@@ -1011,6 +1012,20 @@ extension ChatViewController: MessagesDataSource {
         }
     }
 
+    private func sendAnimatedImage(url: NSURL) {
+        if let path = url.path {
+            let result = SDAnimatedImage(contentsOfFile: path)
+            if let result = result, let animatedImageData = result.animatedImageData {
+                let path = DcUtils.saveAnimatedImage(data: animatedImageData, suffix: "gif")
+                let msg = DcMsg(viewType: DC_MSG_GIF)
+                msg.setFile(filepath: path, mimeType: "image/gif")
+                let pixelSize = result.imageSizeInPixel()
+                msg.setDimension(width: pixelSize.width, height: pixelSize.height)
+                msg.sendInChat(id: self.chatId)
+            }
+        }
+    }
+
     private func sendDocumentMessage(url: NSURL) {
         DispatchQueue.global().async {
             let msg = DcMsg(viewType: DC_MSG_FILE)
@@ -1036,10 +1051,11 @@ extension ChatViewController: MessagesDataSource {
     }
 
     private func sendImage(url: NSURL) {
-        if let data = try? Data(contentsOf: url as URL) {
-            if let image = UIImage(data: data) {
-                sendImage(image)
-            }
+        if url.pathExtension == "gif" {
+            sendAnimatedImage(url: url)
+        } else if let data = try? Data(contentsOf: url as URL),
+            let image = UIImage(data: data) {
+            sendImage(image)
         }
     }