Fix cleanupLocalFile lookup

This commit is contained in:
jack
2025-10-15 00:37:41 +01:00
committed by islam
parent 2bb55cbe1a
commit 3f91d6510b
+9 -5
View File
@@ -2700,11 +2700,15 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
}
private func cleanupLocalFile(forMessage message: BitchatMessage) {
let prefixes = ["[voice] ", "[image] ", "[file] "]
guard let prefix = prefixes.first(where: { message.content.hasPrefix($0) }) else { return }
let path = String(message.content.dropFirst(prefix.count))
if FileManager.default.fileExists(atPath: path) {
try? FileManager.default.removeItem(atPath: path)
let prefixes = ["[voice] ": "voicenotes/outgoing",
"[image] ": "images/outgoing",
"[file] ": "files/outgoing"]
guard let entry = prefixes.first(where: { message.content.hasPrefix($0.key) }) else { return }
let filename = String(message.content.dropFirst(entry.key.count)).trimmingCharacters(in: .whitespacesAndNewlines)
guard !filename.isEmpty, let base = try? applicationFilesDirectory() else { return }
let target = base.appendingPathComponent(entry.value, isDirectory: true).appendingPathComponent(filename)
if FileManager.default.fileExists(atPath: target.path) {
try? FileManager.default.removeItem(at: target)
}
}