Tweak how InstanceFeatures is updated
This commit is contained in:
parent
811aac35d7
commit
0485400c1f
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import Pachyderm
|
import Pachyderm
|
||||||
|
import Combine
|
||||||
|
|
||||||
class MastodonController: ObservableObject {
|
class MastodonController: ObservableObject {
|
||||||
|
|
||||||
|
@ -47,7 +48,9 @@ class MastodonController: ObservableObject {
|
||||||
@Published private(set) var nodeInfo: NodeInfo!
|
@Published private(set) var nodeInfo: NodeInfo!
|
||||||
@Published private(set) var instanceFeatures = InstanceFeatures()
|
@Published private(set) var instanceFeatures = InstanceFeatures()
|
||||||
@Published private(set) var lists: [List] = []
|
@Published private(set) var lists: [List] = []
|
||||||
private(set) var customEmojis: [Emoji]?
|
@Published private(set) var customEmojis: [Emoji]?
|
||||||
|
|
||||||
|
private var cancellables = Set<AnyCancellable>()
|
||||||
|
|
||||||
private var pendingOwnInstanceRequestCallbacks = [(Result<Instance, Client.Error>) -> Void]()
|
private var pendingOwnInstanceRequestCallbacks = [(Result<Instance, Client.Error>) -> Void]()
|
||||||
private var ownInstanceRequest: URLSessionTask?
|
private var ownInstanceRequest: URLSessionTask?
|
||||||
|
@ -61,6 +64,20 @@ class MastodonController: ObservableObject {
|
||||||
self.accountInfo = nil
|
self.accountInfo = nil
|
||||||
self.client = Client(baseURL: instanceURL, session: .appDefault)
|
self.client = Client(baseURL: instanceURL, session: .appDefault)
|
||||||
self.transient = transient
|
self.transient = transient
|
||||||
|
|
||||||
|
$instance
|
||||||
|
.combineLatest($nodeInfo)
|
||||||
|
.compactMap { (instance, nodeInfo) in
|
||||||
|
if let instance {
|
||||||
|
return (instance, nodeInfo)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.sink { [unowned self] (instance, nodeInfo) in
|
||||||
|
self.instanceFeatures.update(instance: instance, nodeInfo: nodeInfo)
|
||||||
|
}
|
||||||
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
|
@ -230,7 +247,6 @@ class MastodonController: ObservableObject {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.ownInstanceRequest = nil
|
self.ownInstanceRequest = nil
|
||||||
self.instance = instance
|
self.instance = instance
|
||||||
self.instanceFeatures.update(instance: instance, nodeInfo: self.nodeInfo)
|
|
||||||
|
|
||||||
for completion in self.pendingOwnInstanceRequestCallbacks {
|
for completion in self.pendingOwnInstanceRequestCallbacks {
|
||||||
completion(.success(instance))
|
completion(.success(instance))
|
||||||
|
@ -248,9 +264,6 @@ class MastodonController: ObservableObject {
|
||||||
case let .success(nodeInfo, _):
|
case let .success(nodeInfo, _):
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.nodeInfo = nodeInfo
|
self.nodeInfo = nodeInfo
|
||||||
if let instance = self.instance {
|
|
||||||
self.instanceFeatures.update(instance: instance, nodeInfo: nodeInfo)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue