浏览代码

move helper method to delete files from ImageFormat to FileHelper

cyberta 2 年之前
父节点
当前提交
2f512e4acf

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

@@ -1722,7 +1722,7 @@ class ChatViewController: UITableViewController {
                     }
                     self.configureDraftArea(draft: self.draft)
                     self.focusInputTextView()
-                    ImageFormat.deleteImage(atPath: pathInCachesDir)
+                    FileHelper.deleteFile(atPath: pathInCachesDir)
                 }
             }
         }
@@ -1733,7 +1733,7 @@ class ChatViewController: UITableViewController {
             guard let self = self else { return }
             if let path = ImageFormat.saveImage(image: image, directory: .cachesDirectory) {
                 self.sendAttachmentMessage(viewType: DC_MSG_IMAGE, filePath: path, message: message)
-                ImageFormat.deleteImage(atPath: path)
+                FileHelper.deleteFile(atPath: path)
             }
         }
     }
@@ -1743,7 +1743,7 @@ class ChatViewController: UITableViewController {
             guard let self = self else { return }
             if let path = ImageFormat.saveImage(image: image, directory: .cachesDirectory) {
                 self.sendAttachmentMessage(viewType: DC_MSG_STICKER, filePath: path, message: nil)
-                ImageFormat.deleteImage(atPath: path)
+                FileHelper.deleteFile(atPath: path)
             }
         }
     }

+ 27 - 0
deltachat-ios/Helper/FileHelper.swift

@@ -56,4 +56,31 @@ public class FileHelper {
             return nil
         }
     }
+
+    public static func deleteFile(atPath: String?) {
+        if Thread.isMainThread {
+            DispatchQueue.global(qos: .background).async {
+                deleteFile(atPath)
+            }
+        } else {
+            deleteFile(atPath)
+        }
+    }
+
+    private static func deleteFile(_ atPath: String?) {
+        guard let atPath = atPath else {
+            return
+        }
+
+        let fileManager = FileManager.default
+        if !fileManager.fileExists(atPath: atPath) {
+            return
+        }
+
+        do {
+            try fileManager.removeItem(atPath: atPath)
+        } catch {
+            print("err: \(error.localizedDescription)")
+        }
+    }
 }

+ 0 - 23
deltachat-ios/Helper/ImageFormat.swift

@@ -106,27 +106,4 @@ extension ImageFormat {
         }
         return nil
     }
-
-    public static func deleteImage(atPath: String) {
-        if Thread.isMainThread {
-            DispatchQueue.global(qos: .background).async {
-                deleteFile(atPath: atPath)
-            }
-        } else {
-            deleteFile(atPath: atPath)
-        }
-    }
-
-    private static func deleteFile(atPath: String) {
-        let fileManager = FileManager.default
-        if !fileManager.fileExists(atPath: atPath) {
-            return
-        }
-
-        do {
-            try fileManager.removeItem(atPath: atPath)
-        } catch {
-            print("err: \(error.localizedDescription)")
-        }
-    }
 }