This commit is contained in:
fmodf 2024-07-16 16:05:15 +02:00
parent 69de25593a
commit 6974ac5b7d
7 changed files with 31 additions and 31 deletions

View file

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

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("Account not found for jid \(jid)"))) promise(.success(.info("AccountsMiddleware: 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("Account disconnected with no error"))) promise(.success(.info("AccountsMiddleware: account \(jid) disconnected with no error")))
} }
default: default:
promise(.success(.empty("Account connection status changed to \(connectionStatus)"))) promise(.success(.info("AccountsMiddleware: account \(jid) connection status changed to \(connectionStatus)")))
} }
} else { } else {
promise(.success(.empty("Account is not temporary, ignoring"))) promise(.success(.info("AccountsMiddleware: account \(jid) 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("Roster marked as locally deleted"))) promise(.success(.info("DatabaseMiddleware: roster \(contactJID) for account \(ownerJID) 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("Roster unmarked as locally deleted"))) promise(.success(.info("DatabaseMiddleware: roster \(contactJID) for account \(ownerJID) 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("Typing message received or message body is nil"))) promise(.success(.info("DatabaseMiddleware: message \(message.id) received as 'typing...' 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("Message stored in db"))) promise(.success(.info("DatabaseMiddleware: message \(message.id) 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("Message marked in db as sent"))) promise(.success(.info("DatabaseMiddleware: message \(msgId) 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("Message marked in db as failed to send"))) promise(.success(.info("DatabaseMiddleware: message \(msgId) 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("Message marked in db as starting downloading attachment"))) promise(.success(.info("DatabaseMiddleware: message \(id) 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("Message marked in db as failed to download attachment"))) promise(.success(.info("DatabaseMiddleware: message \(id) 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("Message marked in db as downloaded attachment"))) promise(.success(.info("DatabaseMiddleware: message \(id) 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("Message marked in db as thumbnail created"))) promise(.success(.info("DatabaseMiddleware: message \(id) 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("Messages with sharings stored in db"))) promise(.success(.info("DatabaseMiddleware: 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("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 { } catch {
promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription))) promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription)))
) )
@ -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("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 { } catch {
promise(.success(.databaseAction(.updateAttachmentFailed(id: messageId, reason: error.localizedDescription))) promise(.success(.databaseAction(.updateAttachmentFailed(id: messageId, reason: error.localizedDescription)))
) )
@ -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("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 { } 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("FileMiddleware self is nil"))) promise(.success(.info("FileMiddleware: on checking attachments/shares messages, middleware self is nil")))
return 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() }.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("FileMiddleware started downloading attachment"))) promise(.success(.info("FileMiddleware: started downloading attachment for message \(id)")))
}.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("FileMiddleware failed to create thumbnail for \(localName)"))) promise(.success(.info("FileMiddleware: failed to create thumbnail from \(localName) for message \(id)")))
} }
} }
.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("FileMiddleware failed to copy camera captured"))) promise(.success(.info("FileMiddleware: failed to copy camera captured media for uploading")))
} }
} }
.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("Camera's captured file didn't copied"))) promise(.success(.info("SharingMiddleware: 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("XMPP clients updated in XMPP service"))) promise(.success(.info("XMPPMiddleware: 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("XMPP clients updated in XMPP service"))) promise(.success(.info("XMPPMiddleware: 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("XMPP clients updated in XMPP service"))) promise(.success(.info("XMPPMiddleware: 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("Roster item deleted"))) promise(.success(.info("XMPPMiddleware: roster \(contactJID) deleted from \(ownerJID)")))
case .failure(let error): case .failure(let error):
promise(.success(.rostersAction(.rosterDeletingFailed(reason: error.localizedDescription)))) promise(.success(.rostersAction(.rosterDeletingFailed(reason: error.localizedDescription))))
@ -104,7 +104,7 @@ final class XMPPMiddleware {
case .xmppAction(.xmppSharingTryUpload(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("Attachment is already in uploading process"))) return promise(.success(.info("XMPPMiddleware: attachment in message \(message.id) is already in uploading process")))
} else { } else {
self?.uploadingMessageIDs.insert(message.id) self?.uploadingMessageIDs.insert(message.id)
DispatchQueue.global().async { DispatchQueue.global().async {

View file

@ -13,7 +13,7 @@ extension AppState {
case .startAction(let action): case .startAction(let action):
StartState.reducer(state: &state.startState, action: 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 break // this actions are processed by other middlewares
case .accountsAction(let action): case .accountsAction(let action):