Fix preferences when browsing

This commit is contained in:
Justin Mazzocchi 2021-01-31 08:10:34 -08:00
parent e50b2bddad
commit cdec2e0082
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
3 changed files with 21 additions and 13 deletions

View File

@ -190,10 +190,10 @@ public extension IdentityService {
contentDatabase.pickerEmojisPublisher()
}
func updatePreferences(_ preferences: Identity.Preferences) -> AnyPublisher<Never, Error> {
func updatePreferences(_ preferences: Identity.Preferences, authenticated: Bool) -> AnyPublisher<Never, Error> {
identityDatabase.updatePreferences(preferences, id: id)
.collect()
.filter { _ in preferences.useServerPostingReadingPreferences }
.filter { _ in preferences.useServerPostingReadingPreferences && authenticated }
.flatMap { _ in refreshServerPreferences() }
.eraseToAnyPublisher()
}

View File

@ -26,7 +26,11 @@ public final class PreferencesViewModel: ObservableObject {
$preferences
.dropFirst()
.flatMap(identityContext.service.updatePreferences)
.flatMap {
identityContext.service.updatePreferences(
$0,
authenticated: identityContext.identity.authenticated)
}
.assignErrorsToAlertItem(to: \.alertItem, on: self)
.sink { _ in }
.store(in: &cancellables)

View File

@ -59,7 +59,8 @@ struct PreferencesView: View {
Toggle("preferences.reading-expand-spoilers",
isOn: $viewModel.preferences.readingExpandSpoilers)
}
.disabled(viewModel.preferences.useServerPostingReadingPreferences)
.disabled(viewModel.preferences.useServerPostingReadingPreferences
&& viewModel.identityContext.identity.authenticated)
}
Section(header: Text("preferences.app")) {
Picker("preferences.status-word",
@ -100,6 +101,8 @@ struct PreferencesView: View {
.disabled(reduceMotion)
Toggle("preferences.show-reblog-and-favorite-counts",
isOn: $identityContext.appPreferences.showReblogAndFavoriteCounts)
if viewModel.identityContext.identity.authenticated
&& !viewModel.identityContext.identity.pending {
Picker("preferences.home-timeline-position-on-startup",
selection: $identityContext.appPreferences.homeTimelineBehavior) {
ForEach(AppPreferences.PositionBehavior.allCases) { option in
@ -114,6 +117,7 @@ struct PreferencesView: View {
}
}
}
}
.navigationTitle("preferences")
.alertItem($viewModel.alertItem)
}