@page "/" @page "/home" @page "/index" @inherits LocalizableComponentBase @Localizer["Index"]
@if (IsLoading) { } else if (Messages.Count == 0) {

@Localizer["Empty"]

} @foreach (var message in Messages) { } @* @foreach (var message in Messages) { } @foreach (var message in Messages) { } *@
@code { [CascadingParameter] Task AuthState { get; set; } [CascadingParameter] CascadingState CascadingState { get; set; } [Inject] IBlazorDownloadFileService BlazorDownloadFileService { get; set; } [Inject] IStorage Storage { get; set; } [Inject] ILocalStorageService LocalStorage { get; set; } [Inject] HttpClient Http { get; set; } [Inject] MessagesService MessagesService { get; set; } TimelineType TimelineType { get; set; } = TimelineType.Home; TimeSortingType TimeSortingType { get; set; } = TimeSortingType.Ascending; IReadOnlyList userClaim { get { var auth = AuthState.Result; if (auth.User.Identity?.IsAuthenticated ?? false) return auth.User.Claims.ToList(); return new List(); } } List IncomingMessages { get; set; } = new(); List Messages { get; set; } = new(); string Response { get; set; } protected override async Task OnInitializedAsync() { var filters = await LocalStorage.GetItemAsync(nameof(ActionBarFilter)); if (filters == default) await LocalStorage.SetItemAsync(nameof(ActionBarFilter), new ActionBarFilter()); else { TimelineType = filters.TimelineType; TimeSortingType = filters.TimeSortingType; } Messages = await Storage.GetMessages(); //try //{ // var response = await Http.GetAsync("api/test"); // Response = await response.Content.ReadAsStringAsync(); //} //catch //{ //} IsLoading = false; } void OnTimelineChanged(TimelineType timelineType) { TimelineType = timelineType; } void OnTimeSortingChanged(TimeSortingType timeSortingType) { TimeSortingType = timeSortingType; } async Task OnMessageSubmit(MessageForm messageForm) { await Task.Run(() => { }); var submitMessage = await MessagesService.SubmitMessage(messageForm); Messages.Insert(0, new() { MessageId = Guid.NewGuid().ToString(), Content = messageForm.Content?.ParseContent(messageForm.ContentType), CreatedAt = DateTime.UtcNow, MessageType = messageForm.MessageType, Medias = messageForm.Media.Select(m => new Media { FileName = m.FileName, AltText = m.AltText, ContentType = m.ContentType, Url = m.Base64Preview, Blob = m.Blob }).ToList(), Title = messageForm.Title, User = new MessageUser { UserId = CascadingState.User.Id, UserName = CascadingState.User.UserName, DisplayName = CascadingState.User.DisplayName, PictureUrl = CascadingState.User.PictureUrl, ProfileUrl = CascadingState.User.ProfileUrl, BackgroundUrl = CascadingState.User.BackgroundUrl }, }); } async Task OnMessageReply(MessageForm messageForm) { await Task.Run(() => { }); var replyMessage = await MessagesService.SubmitMessage(messageForm); Messages.Insert(0, new() { RootMessageId = messageForm.RootMessageId, MessageId = Guid.NewGuid().ToString(), Content = messageForm.Content?.ParseContent(messageForm.ContentType), CreatedAt = DateTime.UtcNow, MessageType = messageForm.MessageType, Medias = messageForm.Media.Select(m => new Media { FileName = m.FileName, AltText = m.AltText, ContentType = m.ContentType, Url = m.Base64Preview, Blob = m.Blob }).ToList(), Title = messageForm.Title, User = new MessageUser { UserId = CascadingState.User.Id, UserName = CascadingState.User.UserName, DisplayName = CascadingState.User.DisplayName, PictureUrl = CascadingState.User.PictureUrl, ProfileUrl = CascadingState.User.ProfileUrl, BackgroundUrl = CascadingState.User.BackgroundUrl } }); } async ValueTask OnMessageBoost(Message message) { var boostedMessageTemp = await MessagesService.BoostUnboostMessage(message); message.BoostsCounter = message.IsBoostedByCurrentUser ? message.BoostsCounter - 1 : message.BoostsCounter + 1; message.IsBoostedByCurrentUser = !message.IsBoostedByCurrentUser; if (message.IsBoostedByCurrentUser) { var boostedMessage = new Message { BoostingUser = new() { UserId = CascadingState.User.Id, DisplayName = CascadingState.User.DisplayName, PictureUrl = CascadingState.User.PictureUrl, ProfileUrl = CascadingState.User.ProfileUrl, UserName = CascadingState.User.UserName }, BoostsCounter = message.BoostsCounter, Content = message.Content, CreatedAt = message.CreatedAt, IsBoostedByCurrentUser = true, IsFavourite = message.IsFavourite, Medias = message.Medias, MessageId = message.MessageId, MessageType = message.MessageType, RootMessageId = message.RootMessageId, Title = message.Title, User = message.User }; Messages.Insert(0, boostedMessage); } else { Messages.RemoveAll(m => m.MessageId == message.MessageId && m.BoostingUser != null && m.BoostingUser.UserId == CascadingState.User.Id); } } async ValueTask OnMessageFavourite(Message message) { message.IsFavourite = !message.IsFavourite; var favouriteMessage = await MessagesService.FavouriteUnfavouriteMessage(message); } async ValueTask OnMessageDelete(Message message) { Messages.Remove(message); var deleteResult = await MessagesService.DeleteMessage(message); } async ValueTask OnMessageMediaDownload(Media media) { await Task.Run(() => { }); await BlazorDownloadFileService.DownloadFileAsync(media.FileName, media.Blob, media.ContentType); } async ValueTask OnUserBlock(MessageUser messageUser) { var blockResult = await MessagesService.BlockUserFromMessage(messageUser); } async ValueTask OnUserDirectMessage(Message message) { var directMessage = await MessagesService.ReplyMessage(message, MessageType.Direct); } async ValueTask OnUserSilence(MessageUser messageUser) { var silenceResult = await MessagesService.SilenceUserFromMessage(messageUser); } }