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 {
case empty
case empty(String)
case flushState
case changeFlow(_ flow: AppFlow)

View file

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

View file

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

View file

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

View file

@ -12,7 +12,7 @@ final class FileMiddleware {
case .conversationAction(.messagesUpdated(let messages)):
return Future { [weak self] promise in
guard let wSelf = self else {
promise(.success(.empty))
promise(.success(.empty("FileMiddleware self is nil")))
return
}
@ -35,7 +35,7 @@ final class FileMiddleware {
}
wSelf.downloadingMessageIDs.insert(message.id)
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()
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()
case .fileAction(.attachmentFileDownloaded(let id, let localName)):
@ -81,7 +81,7 @@ final class FileMiddleware {
promise(.success(.fileAction(.attachmentThumbnailCreated(messageId: id, thumbnailName: thumbnailName))))
} else {
self?.downloadingMessageIDs.remove(id)
promise(.success(.empty))
promise(.success(.empty("FileMiddleware failed to create thumbnail")))
}
}
.eraseToAnyPublisher()
@ -113,7 +113,7 @@ final class FileMiddleware {
if let (id, localName) = FileProcessing.shared.copyCameraCapturedForUploading(media: media, type: type) {
promise(.success(.fileAction(.itemsCopiedForUploading(newMessageIds: [id], localNames: [localName]))))
} else {
promise(.success(.empty))
promise(.success(.empty("FileMiddleware failed to copy camera captured")))
}
}
.eraseToAnyPublisher()

View file

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

View file

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