From 269d56a07bf07b671f271db12a838321c4e47dfa Mon Sep 17 00:00:00 2001 From: fmodf Date: Tue, 16 Jul 2024 14:36:57 +0200 Subject: [PATCH] wip --- .../AppCore/Actions/SharingActions.swift | 2 ++ .../Middlewares/DatabaseMiddleware.swift | 25 ++++++++++++++++++- .../ConversationMessageContainer.swift | 4 ++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ConversationsClassic/AppCore/Actions/SharingActions.swift b/ConversationsClassic/AppCore/Actions/SharingActions.swift index f1db341..901358a 100644 --- a/ConversationsClassic/AppCore/Actions/SharingActions.swift +++ b/ConversationsClassic/AppCore/Actions/SharingActions.swift @@ -16,4 +16,6 @@ enum SharingAction: Stateable { case galleryItemsUpdated(items: [SharingGalleryItem]) case cameraCaptured(media: Data, type: SharingCameraMediaType) + + case retrySharing(messageId: String) } diff --git a/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift index 0972ee5..b95185a 100644 --- a/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift @@ -395,6 +395,29 @@ final class DatabaseMiddleware { } .eraseToAnyPublisher() + case .sharingAction(.retrySharing(let id)): + return Future { promise in + Task(priority: .background) { [weak self] in + guard let database = self?.database else { + promise(.success(.databaseAction(.storeMessageFailed(reason: L10n.Global.Error.genericDbError))) + ) + return + } + do { + _ = try database._db.write { db in + try Message + .filter(Column("id") == id) + .updateAll(db, Column("pending").set(to: true), Column("sentError").set(to: false)) + } + promise(.success(.empty)) + } catch { + promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription))) + ) + } + } + } + .eraseToAnyPublisher() + case .xmppAction(.xmppAttachmentUploadSuccess(let messageId, let remotePath)): return Future { promise in Task(priority: .background) { [weak self] in @@ -407,7 +430,7 @@ final class DatabaseMiddleware { _ = try database._db.write { db in try Message .filter(Column("id") == messageId) - .updateAll(db, Column("attachmentRemotePath").set(to: remotePath), Column("pending").set(to: false)) + .updateAll(db, Column("attachmentRemotePath").set(to: remotePath), Column("pending").set(to: false), Column("sentError").set(to: false)) } promise(.success(.empty)) } catch { diff --git a/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift b/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift index 0a1687b..2c134d9 100644 --- a/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift +++ b/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift @@ -70,7 +70,7 @@ private struct AttachmentView: View { let message: Message var body: some View { - if message.attachmentDownloadFailed { + if message.attachmentDownloadFailed || (message.attachmentLocalName != nil && message.sentError) { failed } else { switch message.attachmentType { @@ -134,6 +134,8 @@ private struct AttachmentView: View { .onTapGesture { if let url = message.attachmentRemotePath { store.dispatch(.fileAction(.downloadAttachmentFile(messageId: message.id, attachmentRemotePath: url))) + } else if message.attachmentLocalName != nil && message.sentError { + store.dispatch(.sharingAction(.retrySharing(messageId: message.id))) } } }