Jelajahi Sumber

stage files dropped by xdc

B. Petersen 2 tahun lalu
induk
melakukan
1895acf33d

+ 10 - 2
deltachat-ios/Chat/ChatViewController.swift

@@ -486,8 +486,16 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
         if RelayHelper.shared.isForwarding() {
             if RelayHelper.shared.forwardIds != nil {
                 askToForwardMessage()
-            } else if let text = RelayHelper.shared.forwardText {
-                messageInputBar.inputTextView.text = text // TODO: handle RelayHelper.shared.fileBase64
+            } else if RelayHelper.shared.forwardFileBase64 != nil || RelayHelper.shared.forwardText != nil {
+                if let text = RelayHelper.shared.forwardText {
+                    messageInputBar.inputTextView.text = text
+                }
+                if let fileBase64 = RelayHelper.shared.forwardFileBase64 {
+                    guard let data = Data(base64Encoded: fileBase64) else { return }
+                    guard let name = RelayHelper.shared.forwardFileName else { return }
+                    guard let file = FileHelper.saveData(data: data, name: name, directory: .cachesDirectory) else { return }
+                    stageDocument(url: NSURL(fileURLWithPath: file))
+                }
                 RelayHelper.shared.finishRelaying()
             }
         } else if RelayHelper.shared.isMailtoHandling() {

+ 7 - 3
deltachat-ios/Helper/FileHelper.swift

@@ -4,7 +4,7 @@ public class FileHelper {
     
     // implementation is following Apple's recommendations
     // https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/AccessingFilesandDirectories/AccessingFilesandDirectories.html
-    public static func saveData(data: Data, name: String? = nil, suffix: String, directory: FileManager.SearchPathDirectory = .applicationSupportDirectory) -> String? {
+    public static func saveData(data: Data, name: String? = nil, suffix: String? = nil, directory: FileManager.SearchPathDirectory = .applicationSupportDirectory) -> String? {
         var path: URL?
 
         // ensure directory exists (application support dir doesn't exist per default)
@@ -40,8 +40,12 @@ public class FileHelper {
 
         // add file name to path
         if let name = name {
-            path = subdirectoryURL.appendingPathComponent("\(name).\(suffix)")
-        } else {
+            if let suffix = suffix {
+                path = subdirectoryURL.appendingPathComponent("\(name).\(suffix)")
+            } else {
+                path = subdirectoryURL.appendingPathComponent(name)
+            }
+        } else if let suffix = suffix {
             let timestamp = Double(Date().timeIntervalSince1970)
             path = subdirectoryURL.appendingPathComponent("\(timestamp).\(suffix)")
         }

+ 1 - 0
deltachat-ios/Helper/RelayHelper.swift

@@ -25,6 +25,7 @@ class RelayHelper {
         return shared
     }
 
+
     // forwarding messages
 
     func setForwardMessage(text: String?, fileBase64: String?, fileName: String?) {