This commit is contained in:
fmodf 2024-07-16 14:36:57 +02:00
parent efaaf0a4dc
commit 269d56a07b
3 changed files with 29 additions and 2 deletions

View file

@ -16,4 +16,6 @@ enum SharingAction: Stateable {
case galleryItemsUpdated(items: [SharingGalleryItem])
case cameraCaptured(media: Data, type: SharingCameraMediaType)
case retrySharing(messageId: String)
}

View file

@ -395,6 +395,29 @@ final class DatabaseMiddleware {
}
.eraseToAnyPublisher()
case .sharingAction(.retrySharing(let id)):
return Future<AppAction, Never> { 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<AppAction, Never> { 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 {

View file

@ -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)))
}
}
}