2020-09-08 04:12:38 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import Foundation
|
|
|
|
import ServiceLayer
|
|
|
|
|
2021-01-26 01:06:35 +01:00
|
|
|
public final class IdentityContext: ObservableObject {
|
2020-09-10 00:48:56 +02:00
|
|
|
@Published private(set) public var identity: Identity
|
2021-03-21 20:56:42 +01:00
|
|
|
@Published private(set) public var authenticatedOtherIdentities = [Identity]()
|
2020-10-15 09:44:01 +02:00
|
|
|
@Published public var appPreferences: AppPreferences
|
2020-09-08 04:12:38 +02:00
|
|
|
let service: IdentityService
|
|
|
|
|
2020-10-15 09:44:01 +02:00
|
|
|
init(identity: Identity,
|
|
|
|
publisher: AnyPublisher<Identity, Never>,
|
|
|
|
service: IdentityService,
|
|
|
|
environment: AppEnvironment) {
|
2020-09-08 04:12:38 +02:00
|
|
|
self.identity = identity
|
2020-09-09 14:05:43 +02:00
|
|
|
self.service = service
|
2020-10-15 09:44:01 +02:00
|
|
|
appPreferences = AppPreferences(environment: environment)
|
2020-09-08 04:12:38 +02:00
|
|
|
|
2020-09-09 14:05:43 +02:00
|
|
|
DispatchQueue.main.async {
|
2020-10-06 22:44:22 +02:00
|
|
|
publisher.dropFirst().assign(to: &self.$identity)
|
2021-03-21 20:56:42 +01:00
|
|
|
service.otherAuthenticatedIdentitiesPublisher()
|
|
|
|
.replaceError(with: [])
|
|
|
|
.assign(to: &self.$authenticatedOtherIdentities)
|
2020-09-08 04:12:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|