mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-26 02:01:00 +00:00
30 lines
902 B
Swift
30 lines
902 B
Swift
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
import Foundation
|
|
import Combine
|
|
|
|
class PostingReadingPreferencesViewModel: ObservableObject {
|
|
@Published var preferences: Identity.Preferences
|
|
@Published var alertItem: AlertItem?
|
|
|
|
private let identityService: IdentityService
|
|
private var cancellables = Set<AnyCancellable>()
|
|
|
|
init(identityService: IdentityService) {
|
|
self.identityService = identityService
|
|
preferences = identityService.identity.preferences
|
|
|
|
identityService.$identity
|
|
.map(\.preferences)
|
|
.dropFirst()
|
|
.removeDuplicates()
|
|
.assign(to: &$preferences)
|
|
|
|
$preferences
|
|
.dropFirst()
|
|
.flatMap(identityService.updatePreferences)
|
|
.assignErrorsToAlertItem(to: \.alertItem, on: self)
|
|
.sink { _ in }
|
|
.store(in: &cancellables)
|
|
}
|
|
}
|