This commit is contained in:
fmodf 2024-07-22 20:53:26 +02:00
parent 8568b1afa6
commit 7ada932664
6 changed files with 11 additions and 23 deletions

View file

@ -9,18 +9,7 @@ typealias Reducer<State: Stateable, Action: Codable> = (inout State, Action) ->
typealias Middleware<State: Stateable, Action: Codable> = (State, Action) -> AnyPublisher<Action, Never>?
final class Store<State: Stateable, Action: Codable>: 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)

View file

@ -52,7 +52,7 @@ final class AccountsMiddleware {
return Future<AppAction, Never> { [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))))
}

View file

@ -5,7 +5,7 @@ import SwiftUI
let isConsoleLoggingEnabled = false
#if DEBUG
let prefixLength = 2000
let prefixLength = 200
func loggerMiddleware() -> Middleware<AppState, AppAction> {
{ state, action in
let timeStr = dateFormatter.string(from: Date())

View file

@ -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)
}

View file

@ -17,7 +17,6 @@ extension AccountsState {
case .clientServerFeaturesUpdated(let jid, let features):
state.discoFeatures[jid] = features
print(features)
default:
break

View file

@ -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