@inherits LocalizableComponentBase
@* The root's personas (/clientapi/avatar/private): each one used in turn, a new one made, and one deleted with the
login's password, asked first (everything public it had goes, with the groups it owns). One the server's staff
suspended or silenced says so; a suspended one can't be used until the suspension is lifted, but may be deleted.
Personas are never linked to one another: no server, PrivaPub's included, shows that they share a root. *@
@if (CascadingState.Personas.Count == 0)
{
@Localizer["This login has no persona to act as yet: make one below."]
}
@foreach (var persona in CascadingState.Personas)
{
@(persona.Name ?? persona.UserName) @persona.Handle
@if (persona.AccountState is ViewAvatarState.Suspended)
{
@Localizer["Suspended"]
}
else if (persona.AccountState is ViewAvatarState.Silenced)
{
@Localizer["Silenced"]
}
@if (persona.Id == CascadingState.PersonaId)
{
@Localizer["in use"]
}
else
{
@Localizer["Use"]
}
@Localizer["Delete"]
}
@if (deleting is not null)
{
}
@Localizer["A new persona"]
@Localizer["Make the persona"]
@code {
[Inject] AuthService AuthService { get; set; }
InsertAvatarForm form = new();
bool isSaving;
string switching;
// the persona whose deletion the dialog asks about
ViewAvatar deleting;
static string StateOf(ViewAvatar persona) => persona.AccountState switch
{
ViewAvatarState.Suspended => "suspended",
ViewAvatarState.Silenced => "silenced",
_ => "normal"
};
protected override void OnInitialized() => IsLoading = false;
async Task Use(ViewAvatar persona)
{
switching = persona.Id;
var result = await CascadingState.SwitchPersona(persona.Id);
switching = null;
if (result.IsInvalid)
Toast.AddResponseError(result);
}
async Task Delete(ActDialog.Answer answer)
{
var persona = deleting;
var result = await AuthService.DeletePersona(persona.Id, answer.Password);
if (result.IsInvalid)
return result;
// the session drops it, and acts as another persona when it was the current one (none left: make one below)
await CascadingState.PersonaDeleted(persona.Id);
Toast.AddResponseSuccess(Localizer["{0} is deleted.", persona.Name ?? "@" + persona.UserName]);
return result;
}
async Task Create()
{
isSaving = true;
form.UserName = form.UserName?.Trim().TrimStart('@').ToLowerInvariant();
var result = await AuthService.CreatePersona(form);
isSaving = false;
if (result.IsInvalid)
{
Toast.AddResponseError(result);
return;
}
form = new();
await CascadingState.ReloadPersonas();
Toast.AddResponseSuccess(Localizer["Persona made."]);
}
}