@using Microsoft.AspNetCore.Components.Rendering
@inherits LocalizableComponentBase
@* The persona's notification policy (/api/v2/notifications/policy): what notifications from people it does not follow,
people who do not follow it, new accounts, private mentions it did not ask for and accounts this server limits become.
Filtered ones wait in a request per account (/api/v1/notifications/requests), let in (with that account from then
on) or dismissed here. *@
@if (IsLoading)
{
@Localizer["loading"]
}
else
{
@Localizer["People you don't follow"]
@Actions
@Localizer["People who don't follow you"]
@Actions
@Localizer["New accounts"]
@Actions
@Localizer["Private mentions you did not ask for"]
@Actions
@Localizer["Accounts this server limits"]
@Actions
@Localizer["Filtered notifications wait below, one request per account; dropped ones are never kept."]
@Localizer["Save"]
@Localizer["Filtered notifications"]
@if (requests.Count == 0)
{
@Localizer["No filtered notifications."]
}
@foreach (var request in requests)
{
@if (request.LastStatus?.Content is { Length: > 0 } content)
{
@((MarkupString)CustomEmojis.Html(content, request.LastStatus.Emojis))
}
}
}
@code {
[Inject] TimelineService TimelineService { get; set; }
NotificationPolicy policy = new();
// what a notification can become, the same for every rule
void Actions(RenderTreeBuilder __builder)
{
@Localizer["Accept"]
@Localizer["Filter"]
@Localizer["Drop"]
}
List requests = [];
// the requests whose answer is on its way
HashSet busy = [];
bool isSaving;
string loadedPersonaId;
protected override async Task OnParametersSetAsync()
{
if (CascadingState.PersonaId == loadedPersonaId)
return;
loadedPersonaId = CascadingState.PersonaId;
if (CascadingState.IsOffline)
{
WhenOnline(LoadData);
StartOnlinePolling();
IsLoading = false;
return;
}
await LoadData();
IsLoading = false;
}
async Task LoadData()
{
policy = await TimelineService.NotificationPolicy() ?? new();
requests = await TimelineService.NotificationRequests();
}
async Task Save()
{
isSaving = true;
var result = await TimelineService.SetNotificationPolicy(policy);
isSaving = false;
if (result.IsInvalid)
{
Toast.AddResponseError(result);
return;
}
policy = (NotificationPolicy)result.Data ?? policy;
Toast.AddResponseSuccess(Localizer["Notification policy saved."]);
}
async Task Answer(NotificationRequest request, bool accept)
{
busy.Add(request.Id);
var result = await TimelineService.AnswerNotificationRequest(request.Id, accept);
busy.Remove(request.Id);
if (result.IsInvalid)
{
Toast.AddResponseError(result);
return;
}
requests.Remove(request);
}
}