This commit is contained in:
fmodf 2024-07-16 15:01:27 +02:00
parent 269d56a07b
commit d726e1fbdd
7 changed files with 39 additions and 39 deletions

View file

@ -1,5 +1,5 @@
enum AppAction: Codable { enum AppAction: Codable {
case empty case empty(String)
case flushState case flushState
case changeFlow(_ flow: AppFlow) case changeFlow(_ flow: AppFlow)

View file

@ -6,7 +6,7 @@ enum XMPPAction: Codable {
case xmppMessageSendFailed(msgId: String) case xmppMessageSendFailed(msgId: String)
case xmppMessageSendSuccess(msgId: String) case xmppMessageSendSuccess(msgId: String)
case xmppAttachmentTryUpload(Message) case xmppSharingTryUpload(Message)
case xmppAttachmentUploadFailed(msgId: String, reason: String) case xmppSharingUploadFailed(msgId: String, reason: String)
case xmppAttachmentUploadSuccess(msgId: String, attachmentRemotePath: String) case xmppSharingUploadSuccess(msgId: String, attachmentRemotePath: String)
} }

View file

@ -12,7 +12,7 @@ final class AccountsMiddleware {
case .xmppAction(.clientConnectionChanged(let jid, let connectionStatus)): case .xmppAction(.clientConnectionChanged(let jid, let connectionStatus)):
return Future<AppAction, Never> { promise in return Future<AppAction, Never> { promise in
guard let account = state.accountsState.accounts.first(where: { $0.bareJid == jid }) else { guard let account = state.accountsState.accounts.first(where: { $0.bareJid == jid }) else {
promise(.success(.empty)) promise(.success(.empty("Account not found for jid \(jid)")))
return return
} }
if account.isTemp { if account.isTemp {
@ -24,14 +24,14 @@ final class AccountsMiddleware {
if reason != "No error!" { if reason != "No error!" {
promise(.success(.accountsAction(.addAccountError(jid: jid, reason: reason)))) promise(.success(.accountsAction(.addAccountError(jid: jid, reason: reason))))
} else { } else {
promise(.success(.empty)) promise(.success(.empty("Account disconnected with no error")))
} }
default: default:
promise(.success(.empty)) promise(.success(.empty("Account connection status changed to \(connectionStatus)")))
} }
} else { } else {
promise(.success(.empty)) promise(.success(.empty("Account is not temporary, ignoring")))
} }
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()

View file

@ -100,7 +100,7 @@ final class DatabaseMiddleware {
.filter(Column("contactBareJid") == contactJID) .filter(Column("contactBareJid") == contactJID)
.updateAll(db, Column("locallyDeleted").set(to: true)) .updateAll(db, Column("locallyDeleted").set(to: true))
} }
promise(.success(.empty)) promise(.success(.empty("Roster marked as locally deleted")))
} catch { } catch {
promise(.success(.rostersAction(.rosterDeletingFailed(reason: L10n.Global.Error.genericDbError)))) promise(.success(.rostersAction(.rosterDeletingFailed(reason: L10n.Global.Error.genericDbError))))
} }
@ -122,7 +122,7 @@ final class DatabaseMiddleware {
.filter(Column("contactBareJid") == contactJID) .filter(Column("contactBareJid") == contactJID)
.updateAll(db, Column("locallyDeleted").set(to: false)) .updateAll(db, Column("locallyDeleted").set(to: false))
} }
promise(.success(.empty)) promise(.success(.empty("Roster unmarked as locally deleted")))
} catch { } catch {
promise(.success(.rostersAction(.rosterDeletingFailed(reason: L10n.Global.Error.genericDbError)))) promise(.success(.rostersAction(.rosterDeletingFailed(reason: L10n.Global.Error.genericDbError))))
} }
@ -169,14 +169,14 @@ final class DatabaseMiddleware {
return return
} }
guard message.contentType != .typing, message.body != nil else { guard message.contentType != .typing, message.body != nil else {
promise(.success(.empty)) promise(.success(.empty("Typing message received or message body is nil")))
return return
} }
do { do {
try database._db.write { db in try database._db.write { db in
try message.insert(db) try message.insert(db)
} }
promise(.success(.empty)) promise(.success(.empty("Message stored in db")))
} catch { } catch {
promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription)))) promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription))))
} }
@ -231,7 +231,7 @@ final class DatabaseMiddleware {
.filter(Column("id") == msgId) .filter(Column("id") == msgId)
.updateAll(db, Column("pending").set(to: false), Column("sentError").set(to: false)) .updateAll(db, Column("pending").set(to: false), Column("sentError").set(to: false))
} }
promise(.success(.empty)) promise(.success(.empty("Message marked in db as sent")))
} catch { } catch {
promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription))) promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription)))
) )
@ -254,7 +254,7 @@ final class DatabaseMiddleware {
.filter(Column("id") == msgId) .filter(Column("id") == msgId)
.updateAll(db, Column("pending").set(to: false), Column("sentError").set(to: true)) .updateAll(db, Column("pending").set(to: false), Column("sentError").set(to: true))
} }
promise(.success(.empty)) promise(.success(.empty("Message marked in db as failed to send")))
} catch { } catch {
promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription)))) promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription))))
} }
@ -277,7 +277,7 @@ final class DatabaseMiddleware {
.filter(Column("id") == id) .filter(Column("id") == id)
.updateAll(db, Column("attachmentDownloadFailed").set(to: false)) .updateAll(db, Column("attachmentDownloadFailed").set(to: false))
} }
promise(.success(.empty)) promise(.success(.empty("Message marked in db as starting downloading attachment")))
} catch { } catch {
promise(.success(.databaseAction(.updateAttachmentFailed(id: id, reason: error.localizedDescription))) promise(.success(.databaseAction(.updateAttachmentFailed(id: id, reason: error.localizedDescription)))
) )
@ -300,7 +300,7 @@ final class DatabaseMiddleware {
.filter(Column("id") == id) .filter(Column("id") == id)
.updateAll(db, Column("attachmentDownloadFailed").set(to: true)) .updateAll(db, Column("attachmentDownloadFailed").set(to: true))
} }
promise(.success(.empty)) promise(.success(.empty("Message marked in db as failed to download attachment")))
} catch { } catch {
promise(.success(.databaseAction(.updateAttachmentFailed(id: id, reason: error.localizedDescription))) promise(.success(.databaseAction(.updateAttachmentFailed(id: id, reason: error.localizedDescription)))
) )
@ -323,7 +323,7 @@ final class DatabaseMiddleware {
.filter(Column("id") == id) .filter(Column("id") == id)
.updateAll(db, Column("attachmentLocalName").set(to: localName), Column("attachmentDownloadFailed").set(to: false)) .updateAll(db, Column("attachmentLocalName").set(to: localName), Column("attachmentDownloadFailed").set(to: false))
} }
promise(.success(.empty)) promise(.success(.empty("Message marked in db as downloaded attachment")))
} catch { } catch {
promise(.success(.databaseAction(.updateAttachmentFailed(id: id, reason: error.localizedDescription))) promise(.success(.databaseAction(.updateAttachmentFailed(id: id, reason: error.localizedDescription)))
) )
@ -346,7 +346,7 @@ final class DatabaseMiddleware {
.filter(Column("id") == id) .filter(Column("id") == id)
.updateAll(db, Column("attachmentThumbnailName").set(to: thumbnailName)) .updateAll(db, Column("attachmentThumbnailName").set(to: thumbnailName))
} }
promise(.success(.empty)) promise(.success(.empty("Message marked in db as thumbnail created")))
} catch { } catch {
promise(.success(.databaseAction(.updateAttachmentFailed(id: id, reason: error.localizedDescription))) promise(.success(.databaseAction(.updateAttachmentFailed(id: id, reason: error.localizedDescription)))
) )
@ -386,7 +386,7 @@ final class DatabaseMiddleware {
try message.insert(db) try message.insert(db)
} }
} }
promise(.success(.empty)) promise(.success(.empty("Messages with sharings stored in db")))
} catch { } catch {
promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription))) promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription)))
) )
@ -409,7 +409,7 @@ final class DatabaseMiddleware {
.filter(Column("id") == id) .filter(Column("id") == id)
.updateAll(db, Column("pending").set(to: true), Column("sentError").set(to: false)) .updateAll(db, Column("pending").set(to: true), Column("sentError").set(to: false))
} }
promise(.success(.empty)) promise(.success(.empty("Message with shares marked in db as pending to send")))
} catch { } catch {
promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription))) promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription)))
) )
@ -418,7 +418,7 @@ final class DatabaseMiddleware {
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()
case .xmppAction(.xmppAttachmentUploadSuccess(let messageId, let remotePath)): case .xmppAction(.xmppSharingUploadSuccess(let messageId, let remotePath)):
return Future<AppAction, Never> { promise in return Future<AppAction, Never> { promise in
Task(priority: .background) { [weak self] in Task(priority: .background) { [weak self] in
guard let database = self?.database else { guard let database = self?.database else {
@ -432,7 +432,7 @@ final class DatabaseMiddleware {
.filter(Column("id") == messageId) .filter(Column("id") == messageId)
.updateAll(db, Column("attachmentRemotePath").set(to: remotePath), Column("pending").set(to: false), Column("sentError").set(to: false)) .updateAll(db, Column("attachmentRemotePath").set(to: remotePath), Column("pending").set(to: false), Column("sentError").set(to: false))
} }
promise(.success(.empty)) promise(.success(.empty("Shared file uploaded and message marked in db as sent")))
} catch { } catch {
promise(.success(.databaseAction(.updateAttachmentFailed(id: messageId, reason: error.localizedDescription))) promise(.success(.databaseAction(.updateAttachmentFailed(id: messageId, reason: error.localizedDescription)))
) )
@ -441,7 +441,7 @@ final class DatabaseMiddleware {
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()
case .xmppAction(.xmppAttachmentUploadFailed(let messageId, _)): case .xmppAction(.xmppSharingUploadFailed(let messageId, _)):
return Future<AppAction, Never> { promise in return Future<AppAction, Never> { promise in
Task(priority: .background) { [weak self] in Task(priority: .background) { [weak self] in
guard let database = self?.database else { guard let database = self?.database else {
@ -455,7 +455,7 @@ final class DatabaseMiddleware {
.filter(Column("id") == messageId) .filter(Column("id") == messageId)
.updateAll(db, Column("pending").set(to: false), Column("sentError").set(to: true)) .updateAll(db, Column("pending").set(to: false), Column("sentError").set(to: true))
} }
promise(.success(.empty)) promise(.success(.empty("Shared file upload failed and message marked in db as failed to send")))
} catch { } catch {
promise(.success(.databaseAction(.updateAttachmentFailed(id: messageId, reason: error.localizedDescription))) promise(.success(.databaseAction(.updateAttachmentFailed(id: messageId, reason: error.localizedDescription)))
) )

View file

@ -12,7 +12,7 @@ final class FileMiddleware {
case .conversationAction(.messagesUpdated(let messages)): case .conversationAction(.messagesUpdated(let messages)):
return Future { [weak self] promise in return Future { [weak self] promise in
guard let wSelf = self else { guard let wSelf = self else {
promise(.success(.empty)) promise(.success(.empty("FileMiddleware self is nil")))
return return
} }
@ -35,7 +35,7 @@ final class FileMiddleware {
} }
wSelf.downloadingMessageIDs.insert(message.id) wSelf.downloadingMessageIDs.insert(message.id)
DispatchQueue.main.async { DispatchQueue.main.async {
store.dispatch(.xmppAction(.xmppAttachmentTryUpload(message))) store.dispatch(.xmppAction(.xmppSharingTryUpload(message)))
} }
} }
@ -48,7 +48,7 @@ final class FileMiddleware {
} }
} }
promise(.success(.empty)) promise(.success(.empty("FileMiddleware messages processed for attachments/sharings")))
}.eraseToAnyPublisher() }.eraseToAnyPublisher()
case .fileAction(.downloadAttachmentFile(let id, let attachmentRemotePath)): case .fileAction(.downloadAttachmentFile(let id, let attachmentRemotePath)):
@ -64,7 +64,7 @@ final class FileMiddleware {
} }
} }
} }
promise(.success(.empty)) promise(.success(.empty("FileMiddleware started downloading attachment")))
}.eraseToAnyPublisher() }.eraseToAnyPublisher()
case .fileAction(.attachmentFileDownloaded(let id, let localName)): case .fileAction(.attachmentFileDownloaded(let id, let localName)):
@ -81,7 +81,7 @@ final class FileMiddleware {
promise(.success(.fileAction(.attachmentThumbnailCreated(messageId: id, thumbnailName: thumbnailName)))) promise(.success(.fileAction(.attachmentThumbnailCreated(messageId: id, thumbnailName: thumbnailName))))
} else { } else {
self?.downloadingMessageIDs.remove(id) self?.downloadingMessageIDs.remove(id)
promise(.success(.empty)) promise(.success(.empty("FileMiddleware failed to create thumbnail")))
} }
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()
@ -113,7 +113,7 @@ final class FileMiddleware {
if let (id, localName) = FileProcessing.shared.copyCameraCapturedForUploading(media: media, type: type) { if let (id, localName) = FileProcessing.shared.copyCameraCapturedForUploading(media: media, type: type) {
promise(.success(.fileAction(.itemsCopiedForUploading(newMessageIds: [id], localNames: [localName])))) promise(.success(.fileAction(.itemsCopiedForUploading(newMessageIds: [id], localNames: [localName]))))
} else { } else {
promise(.success(.empty)) promise(.success(.empty("FileMiddleware failed to copy camera captured")))
} }
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()

View file

@ -83,7 +83,7 @@ final class SharingMiddleware {
promise(.success(.fileAction(.itemsCopiedForUploading(newMessageIds: [id], localNames: [localName]))) promise(.success(.fileAction(.itemsCopiedForUploading(newMessageIds: [id], localNames: [localName])))
) )
} else { } else {
promise(.success(.empty)) promise(.success(.empty("Camera's captured file didn't copied")))
} }
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()

View file

@ -33,21 +33,21 @@ final class XMPPMiddleware {
case .accountsAction(.tryAddAccountWithCredentials): case .accountsAction(.tryAddAccountWithCredentials):
return Future<AppAction, Never> { [weak self] promise in return Future<AppAction, Never> { [weak self] promise in
self?.service.updateClients(for: state.accountsState.accounts) self?.service.updateClients(for: state.accountsState.accounts)
promise(.success(.empty)) promise(.success(.empty("XMPP clients updated in XMPP service")))
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()
case .accountsAction(.addAccountError): case .accountsAction(.addAccountError):
return Future<AppAction, Never> { [weak self] promise in return Future<AppAction, Never> { [weak self] promise in
self?.service.updateClients(for: state.accountsState.accounts) self?.service.updateClients(for: state.accountsState.accounts)
promise(.success(.empty)) promise(.success(.empty("XMPP clients updated in XMPP service")))
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()
case .databaseAction(.storedAccountsLoaded(let accounts)): case .databaseAction(.storedAccountsLoaded(let accounts)):
return Future<AppAction, Never> { [weak self] promise in return Future<AppAction, Never> { [weak self] promise in
self?.service.updateClients(for: accounts.filter { $0.isActive && !$0.isTemp }) self?.service.updateClients(for: accounts.filter { $0.isActive && !$0.isTemp })
promise(.success(.empty)) promise(.success(.empty("XMPP clients updated in XMPP service")))
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()
@ -78,7 +78,7 @@ final class XMPPMiddleware {
module.removeItem(jid: JID(contactJID), completionHandler: { result in module.removeItem(jid: JID(contactJID), completionHandler: { result in
switch result { switch result {
case .success: case .success:
promise(.success(.empty)) promise(.success(.empty("Roster item deleted")))
case .failure(let error): case .failure(let error):
promise(.success(.rostersAction(.rosterDeletingFailed(reason: error.localizedDescription)))) promise(.success(.rostersAction(.rosterDeletingFailed(reason: error.localizedDescription))))
@ -101,19 +101,19 @@ final class XMPPMiddleware {
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()
case .xmppAction(.xmppAttachmentTryUpload(let message)): case .xmppAction(.xmppSharingTryUpload(let message)):
return Future<AppAction, Never> { [weak self] promise in return Future<AppAction, Never> { [weak self] promise in
if self?.uploadingMessageIDs.contains(message.id) ?? false { if self?.uploadingMessageIDs.contains(message.id) ?? false {
return promise(.success(.empty)) return promise(.success(.empty("Attachment is already in uploading process")))
} else { } else {
self?.uploadingMessageIDs.insert(message.id) self?.uploadingMessageIDs.insert(message.id)
DispatchQueue.global().async { DispatchQueue.global().async {
self?.service.uploadAttachment(message: message) { error, remotePath in self?.service.uploadAttachment(message: message) { error, remotePath in
self?.uploadingMessageIDs.remove(message.id) self?.uploadingMessageIDs.remove(message.id)
if let error { if let error {
promise(.success(.xmppAction(.xmppAttachmentUploadFailed(msgId: message.id, reason: error.localizedDescription)))) promise(.success(.xmppAction(.xmppSharingUploadFailed(msgId: message.id, reason: error.localizedDescription))))
} else { } else {
promise(.success(.xmppAction(.xmppAttachmentUploadSuccess(msgId: message.id, attachmentRemotePath: remotePath)))) promise(.success(.xmppAction(.xmppSharingUploadSuccess(msgId: message.id, attachmentRemotePath: remotePath))))
} }
} }
} }