25 lines
762 B
Swift
25 lines
762 B
Swift
|
|
||
|
import Combine
|
||
|
import Foundation
|
||
|
import GRDB
|
||
|
import Martin
|
||
|
|
||
|
final class ClientMartinDiscoManager {
|
||
|
private(set) var features: [ServerFeature] = []
|
||
|
private var cancellables: Set<AnyCancellable> = []
|
||
|
|
||
|
init(_ xmppConnection: XMPPClient) {
|
||
|
// subscribe to client server features
|
||
|
xmppConnection.module(DiscoveryModule.self).$serverDiscoResult
|
||
|
.sink { [weak self] disco in
|
||
|
let allFeatures = ServerFeature.allFeatures
|
||
|
let features = disco.features
|
||
|
.compactMap { featureId in
|
||
|
allFeatures.first(where: { $0.xmppId == featureId })
|
||
|
}
|
||
|
self?.features = features
|
||
|
}
|
||
|
.store(in: &cancellables)
|
||
|
}
|
||
|
}
|