mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 12:25:19 +00:00
Fix cleanupLocalFile lookup
This commit is contained in:
@@ -2700,11 +2700,15 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func cleanupLocalFile(forMessage message: BitchatMessage) {
|
private func cleanupLocalFile(forMessage message: BitchatMessage) {
|
||||||
let prefixes = ["[voice] ", "[image] ", "[file] "]
|
let prefixes = ["[voice] ": "voicenotes/outgoing",
|
||||||
guard let prefix = prefixes.first(where: { message.content.hasPrefix($0) }) else { return }
|
"[image] ": "images/outgoing",
|
||||||
let path = String(message.content.dropFirst(prefix.count))
|
"[file] ": "files/outgoing"]
|
||||||
if FileManager.default.fileExists(atPath: path) {
|
guard let entry = prefixes.first(where: { message.content.hasPrefix($0.key) }) else { return }
|
||||||
try? FileManager.default.removeItem(atPath: path)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user