mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-26 01:45:18 +00:00
fix: address Codex review feedback for BCH-01-002
P1: Wire didReceivePendingFileTransfer into ChatViewModel - Add implementation that creates system message for pending files - Route to appropriate chat (public/private) - Send local notification for incoming files - Auto-decline files from blocked users P2: Keep pending files in queue if save fails - Only remove file from pendingFiles after successful save - Allows user to retry accept if initial save failed Also adds test for save failure scenario. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -165,9 +165,11 @@ final class PendingFileManager {
|
||||
|
||||
/// Accepts a pending file, saving it to disk and removing from pending queue.
|
||||
/// Returns the saved file URL, or nil if the file was not found or save failed.
|
||||
/// Note: File is only removed from queue after successful save to prevent data loss.
|
||||
func acceptFile(id: String, saveHandler: (PendingFileTransfer) -> URL?) -> URL? {
|
||||
let pending = queue.sync(flags: .barrier) { () -> PendingFileTransfer? in
|
||||
pendingFiles.removeValue(forKey: id)
|
||||
// First, get the pending file without removing it
|
||||
let pending = queue.sync { () -> PendingFileTransfer? in
|
||||
pendingFiles[id]
|
||||
}
|
||||
|
||||
guard let pending = pending else {
|
||||
@@ -175,11 +177,18 @@ final class PendingFileManager {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Attempt to save the file
|
||||
guard let url = saveHandler(pending) else {
|
||||
SecureLogger.error("Failed to save accepted file \(id.prefix(8))...", category: .session)
|
||||
// Save failed - keep the file in queue so user can retry
|
||||
SecureLogger.error("Failed to save accepted file \(id.prefix(8))... - keeping in queue for retry", category: .session)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Only remove from queue after successful save
|
||||
_ = queue.sync(flags: .barrier) {
|
||||
pendingFiles.removeValue(forKey: id)
|
||||
}
|
||||
|
||||
SecureLogger.debug("Accepted and saved pending file \(id.prefix(8))... to \(url.lastPathComponent)", category: .session)
|
||||
return url
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user