瀏覽代碼

send drafted image/gif messages

cyberta 4 年之前
父節點
當前提交
54e2037ec2

+ 6 - 6
deltachat-ios/Chat/ChatViewController.swift

@@ -930,7 +930,7 @@ class ChatViewController: UITableViewController {
                let animatedImageData = result.animatedImageData,
                let pathInDocDir = DcUtils.saveImage(data: animatedImageData, suffix: "gif") {
                 DispatchQueue.main.async {
-                    self.draft.setAttachment(viewType: DC_MSG_GIF, path: URL(fileURLWithPath: pathInDocDir))
+                    self.draft.setAttachment(viewType: DC_MSG_GIF, path: pathInDocDir)
                     self.configureDraftArea(draft: self.draft)
                     self.messageInputBar.inputTextView.becomeFirstResponder()
                 }
@@ -940,9 +940,9 @@ class ChatViewController: UITableViewController {
 
     private func stageImage(_ image: UIImage) {
         DispatchQueue.global().async {
-            if let path = DcUtils.saveImage(image: image) {
+            if let pathInDocDir = DcUtils.saveImage(image: image) {
                 DispatchQueue.main.async {
-                    self.draft.setAttachment(viewType: DC_MSG_IMAGE, path: URL(fileURLWithPath: path), mimetype: nil)
+                    self.draft.setAttachment(viewType: DC_MSG_IMAGE, path: pathInDocDir)
                     self.configureDraftArea(draft: self.draft)
                     self.messageInputBar.inputTextView.becomeFirstResponder()
                 }
@@ -1215,11 +1215,11 @@ extension ChatViewController: InputBarAccessoryViewDelegate {
         if let filePath = draft.draftAttachment, let viewType = draft.draftViewType {
             switch viewType {
             case DC_MSG_GIF:
-                self.sendImageMessage(viewType: DC_MSG_GIF, filePath: filePath.absoluteString, message: trimmedText, quoteMessage: draft.quoteMessage)
+                self.sendImageMessage(viewType: DC_MSG_GIF, filePath: filePath, message: trimmedText, quoteMessage: draft.quoteMessage)
             case DC_MSG_IMAGE:
-                self.sendImageMessage(viewType: DC_MSG_IMAGE, filePath: filePath.absoluteString, message: trimmedText, quoteMessage: draft.quoteMessage)
+                self.sendImageMessage(viewType: DC_MSG_IMAGE, filePath: filePath, message: trimmedText, quoteMessage: draft.quoteMessage)
             default:
-                logger.debug("nothing to do")
+                logger.warning("Unsupported viewType for drafted messages.")
             }
         } else if inputBar.inputTextView.images.isEmpty {
             self.sendTextMessage(text: trimmedText, quoteMessage: draft.quoteMessage)

+ 4 - 4
deltachat-ios/Chat/DraftModel.swift

@@ -6,7 +6,7 @@ public class DraftModel {
     var quoteMessage: DcMsg?
     var quoteText: String?
     var draftText: String?
-    var draftAttachment: URL?
+    var draftAttachment: String?
     var draftAttachmentMimeType: String?
     var draftViewType: Int32?
     let chatId: Int
@@ -19,7 +19,7 @@ public class DraftModel {
         draftText = draftMsg?.text
         quoteText = draftMsg?.quoteText
         quoteMessage = draftMsg?.quoteMessage
-        draftAttachment = draftMsg?.fileURL
+        draftAttachment = draftMsg?.fileURL?.absoluteString
         if let viewType = draftMsg?.type {
             draftViewType = Int32(viewType)
         }
@@ -39,7 +39,7 @@ public class DraftModel {
         }
     }
 
-    public func setAttachment(viewType: Int32?, path: URL?, mimetype: String? = nil) {
+    public func setAttachment(viewType: Int32?, path: String?, mimetype: String? = nil) {
         draftAttachment = path
         draftViewType = viewType
         draftAttachmentMimeType = mimetype
@@ -57,7 +57,7 @@ public class DraftModel {
             draftMessage.quoteMessage = quoteMessage
         }
         if draftAttachment != nil {
-            draftMessage.setFile(filepath: draftAttachment?.absoluteString, mimeType: draftAttachmentMimeType)
+            draftMessage.setFile(filepath: draftAttachment, mimeType: draftAttachmentMimeType)
         }
         context.setDraft(chatId: chatId, message: draftMessage)
     }

+ 1 - 1
deltachat-ios/Chat/Views/MediaPreview.swift

@@ -31,7 +31,7 @@ class MediaPreview: DraftPreview {
 
     override func configure(draft: DraftModel) {
         if let path = draft.draftAttachment {
-            contentImageView.sd_setImage(with: path, completed: { image, error, _, _ in
+            contentImageView.sd_setImage(with: URL(fileURLWithPath: path, isDirectory: false), completed: { image, error, _, _ in
                 if let error = error {
                     logger.error("could not load draft image: \(error)")
                     self.cancel()