@inherits LocalizableComponentBase @* How the current persona reads what others post: Mastodon's reading preferences (reading:expand:media and reading:expand:spoilers), which Mastodon's API only reads (/api/v1/preferences). PrivaPub keeps them for each persona and sets them through /clientapi/avatar/private/preferences, so other apps signed in as the persona read them too. The cards here follow them as soon as they are saved (CascadingState.Preferences): which media wait behind a button, and whether a content warning starts open. *@
@if (IsLoading) {

@Localizer["loading"]

} else if (CascadingState.PersonaId is null) {

@Localizer["No persona"]

} else {

@Localizer["Kept for this persona on the server: other apps signed in as it read them too."]

@Localizer["Reset"] @if (isSaving) { } @Localizer["Save"]
}
@code { [Inject] AuthService AuthService { get; set; } // what PrivaPub keeps, and the choices being made ViewPersonaPreferences saved = new(); ExpandMedia expandMedia = ExpandMedia.Default; bool expandSpoilers; bool isSaving; string loadedPersonaId; bool IsChanged => expandMedia != ExpandMediaModes.Of(saved.ExpandMedia) || expandSpoilers != saved.ExpandSpoilers; protected override async Task OnParametersSetAsync() { if (CascadingState.PersonaId == loadedPersonaId) return; loadedPersonaId = CascadingState.PersonaId; if (CascadingState.IsOffline) { saved = CascadingState.Preferences; Reset(); WhenOnline(LoadData); StartOnlinePolling(); IsLoading = false; return; } await LoadData(); IsLoading = false; } // read again: another device may have changed them since the persona was chosen here async Task LoadData() { if (CascadingState.PersonaId is null) return; var read = await AuthService.PersonaPreferences(CascadingState.PersonaId); saved = read ?? CascadingState.Preferences; if (read is not null && (read.ExpandMedia != CascadingState.Preferences.ExpandMedia || read.ExpandSpoilers != CascadingState.Preferences.ExpandSpoilers)) CascadingState.PreferencesChanged(read); Reset(); } void Reset() { expandMedia = ExpandMediaModes.Of(saved.ExpandMedia); expandSpoilers = saved.ExpandSpoilers; } async Task Save() { isSaving = true; var result = await AuthService.SavePersonaPreferences(new PersonaPreferencesForm { AvatarId = CascadingState.PersonaId, ExpandMedia = ExpandMediaModes.Name(expandMedia), ExpandSpoilers = expandSpoilers }); isSaving = false; if (result.IsInvalid) { Toast.AddResponseError(result); return; } saved = (ViewPersonaPreferences)result.Data ?? saved; CascadingState.PreferencesChanged(saved); Reset(); Toast.AddResponseSuccess(Localizer["Reading preferences saved."]); } }