From d726e1fbdd4406eb4252e537eb7f315b68f2d900 Mon Sep 17 00:00:00 2001 From: fmodf Date: Tue, 16 Jul 2024 15:01:27 +0200 Subject: [PATCH] wip --- .../AppCore/Actions/AppActions.swift | 2 +- .../AppCore/Actions/XMPPActions.swift | 6 ++-- .../Middlewares/AccountsMiddleware.swift | 8 ++--- .../Middlewares/DatabaseMiddleware.swift | 32 +++++++++---------- .../AppCore/Middlewares/FileMiddleware.swift | 12 +++---- .../Middlewares/SharingMiddleware.swift | 2 +- .../AppCore/Middlewares/XMPPMiddleware.swift | 16 +++++----- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/ConversationsClassic/AppCore/Actions/AppActions.swift b/ConversationsClassic/AppCore/Actions/AppActions.swift index 917f518..0a3a0b4 100644 --- a/ConversationsClassic/AppCore/Actions/AppActions.swift +++ b/ConversationsClassic/AppCore/Actions/AppActions.swift @@ -1,5 +1,5 @@ enum AppAction: Codable { - case empty + case empty(String) case flushState case changeFlow(_ flow: AppFlow) diff --git a/ConversationsClassic/AppCore/Actions/XMPPActions.swift b/ConversationsClassic/AppCore/Actions/XMPPActions.swift index 9195638..5b02b6d 100644 --- a/ConversationsClassic/AppCore/Actions/XMPPActions.swift +++ b/ConversationsClassic/AppCore/Actions/XMPPActions.swift @@ -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) } diff --git a/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift index 9e1b9e2..397cdbc 100644 --- a/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift @@ -12,7 +12,7 @@ final class AccountsMiddleware { case .xmppAction(.clientConnectionChanged(let jid, let connectionStatus)): return Future { 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() diff --git a/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift index b95185a..98fa6bd 100644 --- a/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift @@ -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 { 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 { 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))) ) diff --git a/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift index 3261c9b..df5c754 100644 --- a/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift @@ -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() diff --git a/ConversationsClassic/AppCore/Middlewares/SharingMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/SharingMiddleware.swift index 5caab81..5648284 100644 --- a/ConversationsClassic/AppCore/Middlewares/SharingMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/SharingMiddleware.swift @@ -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() diff --git a/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift index a3f677e..dd2822b 100644 --- a/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift @@ -33,21 +33,21 @@ final class XMPPMiddleware { case .accountsAction(.tryAddAccountWithCredentials): return Future { [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 { [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 { [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 { [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)))) } } }