mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 17:50:59 +00:00
Refactoring
This commit is contained in:
parent
888604497c
commit
c64fa26b09
2 changed files with 11 additions and 16 deletions
|
@ -85,6 +85,11 @@ extension IdentityService {
|
|||
|
||||
func updatePreferences(_ preferences: Identity.Preferences) -> AnyPublisher<Void, Error> {
|
||||
identityDatabase.updatePreferences(preferences, forIdentityID: identity.id)
|
||||
.zip(Just(self).first().setFailureType(to: Error.self))
|
||||
.filter { $1.identity.preferences.useServerPostingReadingPreferences }
|
||||
.map { _ in () }
|
||||
.flatMap(refreshServerPreferences)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func createPushSubscription(deviceToken: String, alerts: PushSubscription.Alerts) -> AnyPublisher<Void, Error> {
|
||||
|
|
|
@ -4,19 +4,8 @@ import Foundation
|
|||
import Combine
|
||||
|
||||
class PostingReadingPreferencesViewModel: ObservableObject {
|
||||
@Published var preferences: Identity.Preferences {
|
||||
didSet {
|
||||
if preferences.useServerPostingReadingPreferences {
|
||||
identityService.refreshServerPreferences()
|
||||
.assignErrorsToAlertItem(to: \.alertItem, on: self)
|
||||
.sink(receiveValue: {})
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Published var preferences: Identity.Preferences
|
||||
@Published var alertItem: AlertItem?
|
||||
let handle: String
|
||||
|
||||
private let identityService: IdentityService
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
@ -24,17 +13,18 @@ class PostingReadingPreferencesViewModel: ObservableObject {
|
|||
init(identityService: IdentityService) {
|
||||
self.identityService = identityService
|
||||
preferences = identityService.identity.preferences
|
||||
handle = identityService.identity.handle
|
||||
|
||||
identityService.$identity.map(\.preferences)
|
||||
identityService.$identity
|
||||
.map(\.preferences)
|
||||
.dropFirst()
|
||||
.removeDuplicates()
|
||||
.assign(to: &$preferences)
|
||||
|
||||
$preferences.dropFirst()
|
||||
$preferences
|
||||
.dropFirst()
|
||||
.flatMap(identityService.updatePreferences)
|
||||
.assignErrorsToAlertItem(to: \.alertItem, on: self)
|
||||
.sink(receiveValue: {})
|
||||
.sink {}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue