wip
This commit is contained in:
parent
8568b1afa6
commit
7ada932664
|
@ -9,18 +9,7 @@ typealias Reducer<State: Stateable, Action: Codable> = (inout State, Action) ->
|
||||||
typealias Middleware<State: Stateable, Action: Codable> = (State, Action) -> AnyPublisher<Action, Never>?
|
typealias Middleware<State: Stateable, Action: Codable> = (State, Action) -> AnyPublisher<Action, Never>?
|
||||||
|
|
||||||
final class Store<State: Stateable, Action: Codable>: ObservableObject {
|
final class Store<State: Stateable, Action: Codable>: ObservableObject {
|
||||||
// Fake variable for be able to trigger SwiftUI redraw after app state completely changed
|
@Published private(set) var state: State
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Serial queue for performing any actions sequentially
|
// Serial queue for performing any actions sequentially
|
||||||
private let serialQueue = DispatchQueue(label: "im.narayana.conversations.classic.serial.queue", qos: .userInteractive)
|
private let serialQueue = DispatchQueue(label: "im.narayana.conversations.classic.serial.queue", qos: .userInteractive)
|
||||||
|
|
|
@ -52,7 +52,7 @@ final class AccountsMiddleware {
|
||||||
return Future<AppAction, Never> { [weak self] promise in
|
return Future<AppAction, Never> { [weak self] promise in
|
||||||
let serverFeatures = features
|
let serverFeatures = features
|
||||||
.compactMap { featureId in
|
.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))))
|
promise(.success(.accountsAction(.clientServerFeaturesUpdated(jid: jid, features: serverFeatures))))
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import SwiftUI
|
||||||
let isConsoleLoggingEnabled = false
|
let isConsoleLoggingEnabled = false
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
let prefixLength = 2000
|
let prefixLength = 200
|
||||||
func loggerMiddleware() -> Middleware<AppState, AppAction> {
|
func loggerMiddleware() -> Middleware<AppState, AppAction> {
|
||||||
{ state, action in
|
{ state, action in
|
||||||
let timeStr = dateFormatter.string(from: Date())
|
let timeStr = dateFormatter.string(from: Date())
|
||||||
|
|
|
@ -27,13 +27,11 @@ final class XMPPMiddleware {
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
service.clientFeatures.sink { client, _ in
|
service.clientFeatures.sink { client, features in
|
||||||
let jid = client.userBareJid.stringValue
|
let jid = client.userBareJid.stringValue
|
||||||
|
DispatchQueue.main.async {
|
||||||
// TODO: Fix this (BAD_ACCESS error in runtime)
|
store.dispatch(.xmppAction(.serverFeaturesLoaded(jid: jid, features: features)))
|
||||||
// DispatchQueue.main.async {
|
}
|
||||||
// store.dispatch(.xmppAction(.serverFeaturesLoaded(jid: jid, features: features)))
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ extension AccountsState {
|
||||||
|
|
||||||
case .clientServerFeaturesUpdated(let jid, let features):
|
case .clientServerFeaturesUpdated(let jid, let features):
|
||||||
state.discoFeatures[jid] = features
|
state.discoFeatures[jid] = features
|
||||||
print(features)
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
|
|
@ -78,8 +78,7 @@ final class XMPPService: ObservableObject {
|
||||||
client?.module(.messageCarbons).enable()
|
client?.module(.messageCarbons).enable()
|
||||||
}).store(in: &clientMessagesCancellables)
|
}).store(in: &clientMessagesCancellables)
|
||||||
|
|
||||||
client.login()
|
// MAM
|
||||||
|
|
||||||
client.module(.mam).$availableVersions.sink(receiveValue: { [weak client] versions in
|
client.module(.mam).$availableVersions.sink(receiveValue: { [weak client] versions in
|
||||||
guard !versions.isEmpty, let client = client else {
|
guard !versions.isEmpty, let client = client else {
|
||||||
return
|
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))
|
// 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)
|
}).store(in: &clientMessagesCancellables)
|
||||||
|
|
||||||
|
// finally, do login
|
||||||
|
client.login()
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove clients
|
// remove clients
|
||||||
|
|
Loading…
Reference in a new issue