mirror of
https://github.com/metabolist/metatext.git
synced 2025-02-18 06:55:13 +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> {
|
func updatePreferences(_ preferences: Identity.Preferences) -> AnyPublisher<Void, Error> {
|
||||||
identityDatabase.updatePreferences(preferences, forIdentityID: identity.id)
|
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> {
|
func createPushSubscription(deviceToken: String, alerts: PushSubscription.Alerts) -> AnyPublisher<Void, Error> {
|
||||||
|
|
|
@ -4,19 +4,8 @@ import Foundation
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
class PostingReadingPreferencesViewModel: ObservableObject {
|
class PostingReadingPreferencesViewModel: ObservableObject {
|
||||||
@Published var preferences: Identity.Preferences {
|
@Published var preferences: Identity.Preferences
|
||||||
didSet {
|
|
||||||
if preferences.useServerPostingReadingPreferences {
|
|
||||||
identityService.refreshServerPreferences()
|
|
||||||
.assignErrorsToAlertItem(to: \.alertItem, on: self)
|
|
||||||
.sink(receiveValue: {})
|
|
||||||
.store(in: &cancellables)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Published var alertItem: AlertItem?
|
@Published var alertItem: AlertItem?
|
||||||
let handle: String
|
|
||||||
|
|
||||||
private let identityService: IdentityService
|
private let identityService: IdentityService
|
||||||
private var cancellables = Set<AnyCancellable>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
|
@ -24,17 +13,18 @@ class PostingReadingPreferencesViewModel: ObservableObject {
|
||||||
init(identityService: IdentityService) {
|
init(identityService: IdentityService) {
|
||||||
self.identityService = identityService
|
self.identityService = identityService
|
||||||
preferences = identityService.identity.preferences
|
preferences = identityService.identity.preferences
|
||||||
handle = identityService.identity.handle
|
|
||||||
|
|
||||||
identityService.$identity.map(\.preferences)
|
identityService.$identity
|
||||||
|
.map(\.preferences)
|
||||||
.dropFirst()
|
.dropFirst()
|
||||||
.removeDuplicates()
|
.removeDuplicates()
|
||||||
.assign(to: &$preferences)
|
.assign(to: &$preferences)
|
||||||
|
|
||||||
$preferences.dropFirst()
|
$preferences
|
||||||
|
.dropFirst()
|
||||||
.flatMap(identityService.updatePreferences)
|
.flatMap(identityService.updatePreferences)
|
||||||
.assignErrorsToAlertItem(to: \.alertItem, on: self)
|
.assignErrorsToAlertItem(to: \.alertItem, on: self)
|
||||||
.sink(receiveValue: {})
|
.sink {}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue