From 6974ac5b7da1db820437150224eeb22e5c6d2658 Mon Sep 17 00:00:00 2001 From: fmodf Date: Tue, 16 Jul 2024 16:05:15 +0200 Subject: [PATCH] wip --- .../AppCore/Actions/AppActions.swift | 2 +- .../Middlewares/AccountsMiddleware.swift | 8 +++--- .../Middlewares/DatabaseMiddleware.swift | 28 +++++++++---------- .../AppCore/Middlewares/FileMiddleware.swift | 10 +++---- .../Middlewares/SharingMiddleware.swift | 2 +- .../AppCore/Middlewares/XMPPMiddleware.swift | 10 +++---- .../AppCore/Reducers/AppReducer.swift | 2 +- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/ConversationsClassic/AppCore/Actions/AppActions.swift b/ConversationsClassic/AppCore/Actions/AppActions.swift index 0a3a0b4..2cb786d 100644 --- a/ConversationsClassic/AppCore/Actions/AppActions.swift +++ b/ConversationsClassic/AppCore/Actions/AppActions.swift @@ -1,5 +1,5 @@ enum AppAction: Codable { - case empty(String) + case info(String) case flushState case changeFlow(_ flow: AppFlow) diff --git a/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift index 397cdbc..f49d667 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("Account not found for jid \(jid)"))) + promise(.success(.info("AccountsMiddleware: 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("Account disconnected with no error"))) + promise(.success(.info("AccountsMiddleware: account \(jid) disconnected with no error"))) } default: - promise(.success(.empty("Account connection status changed to \(connectionStatus)"))) + promise(.success(.info("AccountsMiddleware: account \(jid) connection status changed to \(connectionStatus)"))) } } else { - promise(.success(.empty("Account is not temporary, ignoring"))) + promise(.success(.info("AccountsMiddleware: account \(jid) is not temporary, ignoring"))) } } .eraseToAnyPublisher() diff --git a/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift index 98fa6bd..3aa6353 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("Roster marked as locally deleted"))) + promise(.success(.info("DatabaseMiddleware: roster \(contactJID) for account \(ownerJID) 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("Roster unmarked as locally deleted"))) + promise(.success(.info("DatabaseMiddleware: roster \(contactJID) for account \(ownerJID) 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("Typing message received or message body is nil"))) + promise(.success(.info("DatabaseMiddleware: message \(message.id) received as 'typing...' or message body is nil"))) return } do { try database._db.write { db in try message.insert(db) } - promise(.success(.empty("Message stored in db"))) + promise(.success(.info("DatabaseMiddleware: message \(message.id) 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("Message marked in db as sent"))) + promise(.success(.info("DatabaseMiddleware: message \(msgId) 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("Message marked in db as failed to send"))) + promise(.success(.info("DatabaseMiddleware: message \(msgId) 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("Message marked in db as starting downloading attachment"))) + promise(.success(.info("DatabaseMiddleware: message \(id) 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("Message marked in db as failed to download attachment"))) + promise(.success(.info("DatabaseMiddleware: message \(id) 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("Message marked in db as downloaded attachment"))) + promise(.success(.info("DatabaseMiddleware: message \(id) 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("Message marked in db as thumbnail created"))) + promise(.success(.info("DatabaseMiddleware: message \(id) 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("Messages with sharings stored in db"))) + promise(.success(.info("DatabaseMiddleware: 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("Message with shares marked in db as pending to send"))) + promise(.success(.info("DatabaseMiddleware: message \(id) with shares marked in db as pending to send"))) } catch { promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription))) ) @@ -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("Shared file uploaded and message marked in db as sent"))) + promise(.success(.info("DatabaseMiddleware: shared file uploaded and message \(messageId) marked in db as sent"))) } catch { promise(.success(.databaseAction(.updateAttachmentFailed(id: messageId, reason: error.localizedDescription))) ) @@ -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("Shared file upload failed and message marked in db as failed to send"))) + promise(.success(.info("DatabaseMiddleware: shared file upload failed and message \(messageId) 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 e77a5fa..6008dd2 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("FileMiddleware self is nil"))) + promise(.success(.info("FileMiddleware: on checking attachments/shares messages, middleware self is nil"))) return } @@ -48,7 +48,7 @@ final class FileMiddleware { } } - promise(.success(.empty("FileMiddleware messages processed for attachments/sharings"))) + promise(.success(.info("FileMiddleware: attachments/shares messages processed"))) }.eraseToAnyPublisher() case .fileAction(.downloadAttachmentFile(let id, let attachmentRemotePath)): @@ -64,7 +64,7 @@ final class FileMiddleware { } } } - promise(.success(.empty("FileMiddleware started downloading attachment"))) + promise(.success(.info("FileMiddleware: started downloading attachment for message \(id)"))) }.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("FileMiddleware failed to create thumbnail for \(localName)"))) + promise(.success(.info("FileMiddleware: failed to create thumbnail from \(localName) for message \(id)"))) } } .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("FileMiddleware failed to copy camera captured"))) + promise(.success(.info("FileMiddleware: failed to copy camera captured media for uploading"))) } } .eraseToAnyPublisher() diff --git a/ConversationsClassic/AppCore/Middlewares/SharingMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/SharingMiddleware.swift index 5648284..e06b5c5 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("Camera's captured file didn't copied"))) + promise(.success(.info("SharingMiddleware: camera's captured file didn't copied"))) } } .eraseToAnyPublisher() diff --git a/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift index dd2822b..66b06df 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("XMPP clients updated in XMPP service"))) + promise(.success(.info("XMPPMiddleware: 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("XMPP clients updated in XMPP service"))) + promise(.success(.info("XMPPMiddleware: 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("XMPP clients updated in XMPP service"))) + promise(.success(.info("XMPPMiddleware: 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("Roster item deleted"))) + promise(.success(.info("XMPPMiddleware: roster \(contactJID) deleted from \(ownerJID)"))) case .failure(let error): promise(.success(.rostersAction(.rosterDeletingFailed(reason: error.localizedDescription)))) @@ -104,7 +104,7 @@ final class XMPPMiddleware { case .xmppAction(.xmppSharingTryUpload(let message)): return Future { [weak self] promise in if self?.uploadingMessageIDs.contains(message.id) ?? false { - return promise(.success(.empty("Attachment is already in uploading process"))) + return promise(.success(.info("XMPPMiddleware: attachment in message \(message.id) is already in uploading process"))) } else { self?.uploadingMessageIDs.insert(message.id) DispatchQueue.global().async { diff --git a/ConversationsClassic/AppCore/Reducers/AppReducer.swift b/ConversationsClassic/AppCore/Reducers/AppReducer.swift index 2696f89..ff67556 100644 --- a/ConversationsClassic/AppCore/Reducers/AppReducer.swift +++ b/ConversationsClassic/AppCore/Reducers/AppReducer.swift @@ -13,7 +13,7 @@ extension AppState { case .startAction(let action): StartState.reducer(state: &state.startState, action: action) - case .databaseAction, .xmppAction, .fileAction, .empty: + case .databaseAction, .xmppAction, .fileAction, .info: break // this actions are processed by other middlewares case .accountsAction(let action):