From 7ada932664d29b0a7c119906b1a35d805835d18d Mon Sep 17 00:00:00 2001 From: fmodf Date: Mon, 22 Jul 2024 20:53:26 +0200 Subject: [PATCH] wip --- ConversationsClassic/AppCore/AppStore.swift | 13 +------------ .../AppCore/Middlewares/AccountsMiddleware.swift | 2 +- .../AppCore/Middlewares/LoggerMiddleware.swift | 2 +- .../AppCore/Middlewares/XMPPMiddleware.swift | 10 ++++------ .../AppCore/Reducers/AccountsReducer.swift | 1 - ConversationsClassic/AppCore/XMPP/XMPPService.swift | 6 ++++-- 6 files changed, 11 insertions(+), 23 deletions(-) diff --git a/ConversationsClassic/AppCore/AppStore.swift b/ConversationsClassic/AppCore/AppStore.swift index 761d9e3..adb7451 100644 --- a/ConversationsClassic/AppCore/AppStore.swift +++ b/ConversationsClassic/AppCore/AppStore.swift @@ -9,18 +9,7 @@ typealias Reducer = (inout State, Action) -> typealias Middleware = (State, Action) -> AnyPublisher? final class Store: ObservableObject { - // Fake variable for be able to trigger SwiftUI redraw after app state completely changed - // this hack is needed because @Published wrapper sends signals on "willSet:" - @Published private var dumbVar: UUID = .init() - - // State is read-only (changes only over reducers) - private(set) var state: State { - didSet { - DispatchQueue.main.async { [weak self] in - self?.dumbVar = UUID() - } - } // signal to SwiftUI only when new state did set - } + @Published private(set) var state: State // Serial queue for performing any actions sequentially private let serialQueue = DispatchQueue(label: "im.narayana.conversations.classic.serial.queue", qos: .userInteractive) diff --git a/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift index 4038b6d..1f0097c 100644 --- a/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift @@ -52,7 +52,7 @@ final class AccountsMiddleware { return Future { [weak self] promise in let serverFeatures = features .compactMap { featureId in - self?.allFeatures.first(where: { $0.xep == featureId }) + self?.allFeatures.first(where: { $0.xmppId == featureId }) } promise(.success(.accountsAction(.clientServerFeaturesUpdated(jid: jid, features: serverFeatures)))) } diff --git a/ConversationsClassic/AppCore/Middlewares/LoggerMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/LoggerMiddleware.swift index 2c9d5ed..eeeb308 100644 --- a/ConversationsClassic/AppCore/Middlewares/LoggerMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/LoggerMiddleware.swift @@ -5,7 +5,7 @@ import SwiftUI let isConsoleLoggingEnabled = false #if DEBUG - let prefixLength = 2000 + let prefixLength = 200 func loggerMiddleware() -> Middleware { { state, action in let timeStr = dateFormatter.string(from: Date()) diff --git a/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift index 27bf8ea..95bc587 100644 --- a/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift @@ -27,13 +27,11 @@ final class XMPPMiddleware { } .store(in: &cancellables) - service.clientFeatures.sink { client, _ in + service.clientFeatures.sink { client, features in let jid = client.userBareJid.stringValue - - // TODO: Fix this (BAD_ACCESS error in runtime) - // DispatchQueue.main.async { - // store.dispatch(.xmppAction(.serverFeaturesLoaded(jid: jid, features: features))) - // } + DispatchQueue.main.async { + store.dispatch(.xmppAction(.serverFeaturesLoaded(jid: jid, features: features))) + } } .store(in: &cancellables) } diff --git a/ConversationsClassic/AppCore/Reducers/AccountsReducer.swift b/ConversationsClassic/AppCore/Reducers/AccountsReducer.swift index 0616b0f..f5a7c56 100644 --- a/ConversationsClassic/AppCore/Reducers/AccountsReducer.swift +++ b/ConversationsClassic/AppCore/Reducers/AccountsReducer.swift @@ -17,7 +17,6 @@ extension AccountsState { case .clientServerFeaturesUpdated(let jid, let features): state.discoFeatures[jid] = features - print(features) default: break diff --git a/ConversationsClassic/AppCore/XMPP/XMPPService.swift b/ConversationsClassic/AppCore/XMPP/XMPPService.swift index 52a4e04..1b9b405 100644 --- a/ConversationsClassic/AppCore/XMPP/XMPPService.swift +++ b/ConversationsClassic/AppCore/XMPP/XMPPService.swift @@ -78,8 +78,7 @@ final class XMPPService: ObservableObject { client?.module(.messageCarbons).enable() }).store(in: &clientMessagesCancellables) - client.login() - + // MAM client.module(.mam).$availableVersions.sink(receiveValue: { [weak client] versions in guard !versions.isEmpty, let client = client else { return @@ -96,6 +95,9 @@ final class XMPPService: ObservableObject { // } // DBChatHistoryStore.instance.append(for: conversation, message: archived.message, source: .archive(source: archived.source, version: archived.query.version, messageId: archived.messageId, timestamp: archived.timestamp)) }).store(in: &clientMessagesCancellables) + + // finally, do login + client.login() } // remove clients