Ported from the owner's b2b.next and adapted from MudBlazor to the daisyUI
components:
- LocalizableComponentBase provides CascadingState, Navigation, Toast,
IsLoading/IsDefaultDisabled, WhenOnline/StartOnlinePolling, and after-render
jobs that actually run.
- CascadingState starts with initialised state and polls the online status
with a PeriodicTimer. It reports errors through ILoggingService plus a toast,
and disposes what it holds.
- New pieces:
- ToastService + ToastHost, the snackbar, with AddResponseError/Success/
Warning/Exception in SUtility;
- ErrorViewer, which shows the validation messages plus AdditionalError(s);
- LoggingService, which writes to the console and the IndexedDB client log.
- HttpService is rebuilt and registered:
- auth levels Get/Post/Delete, *Anon and *TotallyAnon;
- retry with backoff;
- classified failures (FailureCodes) instead of exceptions;
- HTTP 410 on cancel;
- the "default" client.
ReadWebResult and DefaultReadFromJsonAsync read its responses.
- ClientJsonContext is source-generated, and SUtility.DefaultSerializer and
Blazored.LocalStorage use it.
- WebResult gains a C# 14 IsInvalid extension property.
The code follows the imported rules:
- Every service and async helper takes a CancellationToken last.
- Primary constructors replace constructor-plus-fields.
- MessagesService and IStorage return Task<WebResult> / Task<List<T>>.
MessagesService is still mock, building its results in memory; the seed
feed and thread moved to Faker.
- Index and ExpandMessage follow the page pattern: an offline guard with
WhenOnline, LoadData, and early returns with toasts on the results they used
to ignore. ExpandMessage reloads on route change and shows "not found"
instead of a null message.
- Model and state collections are [], and the fake identity defaults moved
out of the models.
- Components:
- no ?. chains over initialised state;
- [Inject] instead of @inject;
- IsDefaultDisabled on the actions;
- autocomplete on every text input;
- Localizer[key, args] instead of string.Format;
- the localizer no longer leaks its inner _pLocalizer.
- Settings → General gains a language picker (English/Italiano), and
SetDefaultCulture limits the culture to those two.
Bugs fixed along the way:
- A compose with untouched (null) content passed the empty check.
- File errors were joined with <br/> and rendered as markup.
- ClientLogs.ErrorMessage() threw on warnings.
- CoalescingStringLocalizer[key, args] showed a raw "{0}" for missing keys.
- AppStatusService exposed a call to a JS function that doesn't exist.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
190 lines
6.0 KiB
Plaintext
190 lines
6.0 KiB
Plaintext
@page "/expand"
|
|
@page "/expand/{messageId}"
|
|
@inherits LocalizableComponentBase
|
|
|
|
<div class="flex w-full h-full flex-col gap-4">
|
|
|
|
<section class="block relative w-full h-full neo-inset neo-xs rounded-xl">
|
|
<div class="flex flex-col gap-4 p-4 md:p-5 w-full h-full absolute overflow-y-auto @SUtility.IfTrueThen(TimeSortingType is TimeSortingType.Descending, "flex-col-reverse")">
|
|
|
|
@if (IsLoading)
|
|
{
|
|
<p class="flex w-full items-center justify-center gap-2">
|
|
<DLoading Variant="DLoadingVariant.Dots" LabelText="@Localizer["loading"]" />
|
|
@Localizer["loading"]
|
|
</p>
|
|
}
|
|
else if (IsNotFound)
|
|
{
|
|
<p class="w-full text-center text-lg">
|
|
<i class="ion-ios-remove-circle-outline"></i> @Localizer["This message doesn't exist."]
|
|
</p>
|
|
}
|
|
else
|
|
{
|
|
@foreach (var message in Ancestors)
|
|
{
|
|
<Content CssContainer="ml-6 w-auto" IncludeExpand="false" Message="message"
|
|
OnMessageBoost="async (m) => await OnMessageBoost(m)" OnMessageDelete="async (m) => await OnMessageDelete(m)"
|
|
OnMessageFavourite="async (m) => await OnMessageFavourite(m)" OnMessageReply="async (m) => await OnMessageReply(m)"
|
|
OnMessageMediaDownload="async (m) => await OnMessageMediaDownload(m)"
|
|
OnUserBlock="async (u) => await OnUserBlock(u)" OnUserDirectMessage="async (u) => await OnUserDirectMessage(u)" OnUserSilence="async (u) => await OnUserSilence(u)" />
|
|
}
|
|
|
|
<Content Highlighted="true" IncludeExpand="false" Message="CurrentMessage"
|
|
OnMessageBoost="async (m) => await OnMessageBoost(m)" OnMessageDelete="async (m) => await OnMessageDelete(m)"
|
|
OnMessageFavourite="async (m) => await OnMessageFavourite(m)" OnMessageReply="async (m) => await OnMessageReply(m)"
|
|
OnMessageMediaDownload="async (m) => await OnMessageMediaDownload(m)"
|
|
OnUserBlock="async (u) => await OnUserBlock(u)" OnUserDirectMessage="async (u) => await OnUserDirectMessage(u)" OnUserSilence="async (u) => await OnUserSilence(u)" />
|
|
|
|
@foreach (var message in Descendants)
|
|
{
|
|
<Content CssContainer="ml-6 w-auto" IncludeExpand="false" Message="message"
|
|
OnMessageBoost="async (m) => await OnMessageBoost(m)" OnMessageDelete="async (m) => await OnMessageDelete(m)"
|
|
OnMessageFavourite="async (m) => await OnMessageFavourite(m)" OnMessageReply="async (m) => await OnMessageReply(m)"
|
|
OnMessageMediaDownload="async (m) => await OnMessageMediaDownload(m)"
|
|
OnUserBlock="async (u) => await OnUserBlock(u)" OnUserDirectMessage="async (u) => await OnUserDirectMessage(u)" OnUserSilence="async (u) => await OnUserSilence(u)" />
|
|
}
|
|
}
|
|
|
|
</div>
|
|
</section>
|
|
|
|
</div>
|
|
|
|
@code {
|
|
[Inject] IStorage DbStorage { get; set; }
|
|
[Inject] ILocalStorageService LocalStorage { get; set; }
|
|
[Inject] IBlazorDownloadFileService BlazorDownloadFileService { get; set; }
|
|
[Inject] MessagesService MessagesService { get; set; }
|
|
[Parameter] public string MessageId { get; set; }
|
|
|
|
List<Message> Ancestors { get; set; } = [];
|
|
Message CurrentMessage { get; set; } = new();
|
|
List<Message> Descendants { get; set; } = [];
|
|
bool IsNotFound { get; set; }
|
|
TimeSortingType TimeSortingType { get; set; } = TimeSortingType.Ascending;
|
|
|
|
// Parameters rather than initialization: following a link to another message reuses this page.
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (string.IsNullOrEmpty(MessageId))
|
|
{
|
|
Navigation.NavigateTo("");
|
|
return;
|
|
}
|
|
|
|
IsLoading = true;
|
|
var filters = await LocalStorage.GetItemAsync<ActionBarFilter>(nameof(ActionBarFilter)) ?? new();
|
|
TimeSortingType = filters.TimeSortingType;
|
|
|
|
if (CascadingState.IsOffline)
|
|
{
|
|
WhenOnline(LoadData);
|
|
StartOnlinePolling();
|
|
IsLoading = false;
|
|
return;
|
|
}
|
|
|
|
await LoadData();
|
|
IsLoading = false;
|
|
}
|
|
|
|
// The thread: the message from IndexedDB, the ones around it mock (Faker) until the app reads PrivaPub's context.
|
|
async Task LoadData()
|
|
{
|
|
var message = await DbStorage.GetMessage(MessageId);
|
|
IsNotFound = message is null;
|
|
if (IsNotFound)
|
|
return;
|
|
|
|
CurrentMessage = message;
|
|
(Ancestors, Descendants) = Faker.Thread(message);
|
|
}
|
|
|
|
async Task OnMessageReply(MessageForm messageForm)
|
|
{
|
|
var result = await MessagesService.SubmitMessage(messageForm, CascadingState.User);
|
|
if (result.IsInvalid)
|
|
{
|
|
Toast.AddResponseError(result);
|
|
return;
|
|
}
|
|
|
|
Descendants.Add(result.Data as Message);
|
|
}
|
|
|
|
async Task OnMessageBoost(Message message)
|
|
{
|
|
if (message.IsBoostedByCurrentUser)
|
|
return;
|
|
|
|
var result = await MessagesService.BoostUnboostMessage(message);
|
|
if (result.IsInvalid)
|
|
Toast.AddResponseError(result);
|
|
}
|
|
|
|
async Task OnMessageFavourite(Message message)
|
|
{
|
|
var result = await MessagesService.FavouriteUnfavouriteMessage(message);
|
|
if (result.IsInvalid)
|
|
Toast.AddResponseError(result);
|
|
}
|
|
|
|
async Task OnMessageDelete(Message message)
|
|
{
|
|
var result = await MessagesService.DeleteMessage(message);
|
|
if (result.IsInvalid)
|
|
{
|
|
Toast.AddResponseError(result);
|
|
return;
|
|
}
|
|
|
|
Toast.AddResponseSuccess(Localizer["Message deleted."]);
|
|
if (message == CurrentMessage)
|
|
{
|
|
Navigation.NavigateTo("");
|
|
return;
|
|
}
|
|
|
|
Ancestors.Remove(message);
|
|
Descendants.Remove(message);
|
|
}
|
|
|
|
async Task OnMessageMediaDownload(Media media)
|
|
{
|
|
await BlazorDownloadFileService.DownloadFileAsync(media.FileName, media.Blob, media.ContentType);
|
|
}
|
|
|
|
async Task OnUserBlock(MessageUser messageUser)
|
|
{
|
|
var result = await MessagesService.BlockUserFromMessage(messageUser);
|
|
if (result.IsInvalid)
|
|
{
|
|
Toast.AddResponseError(result);
|
|
return;
|
|
}
|
|
|
|
Toast.AddResponseSuccess(Localizer["{0} blocked.", messageUser.DisplayName]);
|
|
}
|
|
|
|
async Task OnUserDirectMessage(Message message)
|
|
{
|
|
var result = await MessagesService.ReplyMessage(message, MessageType.Direct);
|
|
if (result.IsInvalid)
|
|
Toast.AddResponseError(result);
|
|
}
|
|
|
|
async Task OnUserSilence(MessageUser messageUser)
|
|
{
|
|
var result = await MessagesService.SilenceUserFromMessage(messageUser);
|
|
if (result.IsInvalid)
|
|
{
|
|
Toast.AddResponseError(result);
|
|
return;
|
|
}
|
|
|
|
Toast.AddResponseSuccess(Localizer["{0} muted.", messageUser.DisplayName]);
|
|
}
|
|
}
|