From 712ad189c99570f686ab779782b2a873e172428e Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Tue, 13 Jun 2023 20:25:05 +0200 Subject: Change syntax style --- MatrixRoomUtils.Web/Shared/RoomListItem.razor | 91 ++++++++++----------------- 1 file changed, 34 insertions(+), 57 deletions(-) (limited to 'MatrixRoomUtils.Web/Shared/RoomListItem.razor') diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor index fb28c3c..f58ab3a 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor @@ -1,18 +1,15 @@ -@using MatrixRoomUtils.Core.Authentication -@using System.Text.Json @using MatrixRoomUtils.Core.Extensions +@using System.Text.Json
- @if (ShowOwnProfile) - { - + @if (ShowOwnProfile) { + @(profileName ?? "Loading...") -> } - +
- @roomName - @if (ChildContent != null) - { + @RoomName + @if (ChildContent != null) { @ChildContent }
@@ -33,103 +30,86 @@ [Parameter] public bool ShowOwnProfile { get; set; } = false; - private string roomName { get; set; } = "Loading..."; + [Parameter] + public string? RoomName { get; set; } + private string? roomIcon { get; set; } = "/icon-192.png"; private string? profileAvatar { get; set; } private string? profileName { get; set; } private bool hasCustomProfileAvatar { get; set; } = false; private bool hasCustomProfileName { get; set; } = false; - + private bool hasOldRoomVersion { get; set; } = false; private bool hasDangerousRoomVersion { get; set; } = false; - - + private static SemaphoreSlim _semaphoreSlim = new(128); - protected override async Task OnInitializedAsync() - { + protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); - + await _semaphoreSlim.WaitAsync(); var hs = RuntimeCache.CurrentHomeServer; //await new AuthenticatedHomeServer(RuntimeCache.CurrentHomeServer.UserId, RuntimeCache.CurrentHomeServer.AccessToken, RuntimeCache.CurrentHomeServer.HomeServerDomain).Configure(); - - if (Room == null) - { - if (RoomId == null) - { + + if (Room == null) { + if (RoomId == null) { throw new ArgumentNullException(nameof(RoomId)); } Room = await hs.GetRoom(RoomId); } - else - { + else { RoomId = Room.RoomId; } - roomName = await Room.GetNameAsync() ?? "Unnamed room: " + RoomId; + RoomName ??= await Room.GetNameAsync() ?? "Unnamed room: " + RoomId; var ce = await Room.GetCreateEventAsync(); - if (ce != null) - { - if (int.TryParse(ce.RoomVersion, out int rv) && rv < 10) - { + if (ce != null) { + if (int.TryParse(ce.RoomVersion, out var rv) && rv < 10) { hasOldRoomVersion = true; } - if (new[] { "1", "8" }.Contains(ce.RoomVersion)) - { + if (new[] { "1", "8" }.Contains(ce.RoomVersion)) { hasDangerousRoomVersion = true; - roomName = "Dangerous room: " + roomName; + RoomName = "Dangerous room: " + RoomName; } } - var state = await Room.GetStateAsync("m.room.avatar"); - if (state != null) - { - try - { + if (state != null) { + try { var url = state.Value.GetProperty("url").GetString(); - if (url != null) - { + if (url != null) { roomIcon = hs.ResolveMediaUri(url); Console.WriteLine($"Got avatar for room {RoomId}: {roomIcon} ({url})"); } } - catch (InvalidOperationException e) - { + catch (InvalidOperationException e) { Console.WriteLine($"Failed to get avatar for room {RoomId}: {e.Message}\n{state.Value.ToJson()}"); } } - if (ShowOwnProfile) - { - var profile = await hs.GetProfile(hs.UserId, debounce: true); + if (ShowOwnProfile) { + var profile = await hs.GetProfile(hs.UserId, true); var memberState = await Room.GetStateAsync("m.room.member", hs.UserId); - if (memberState.HasValue) - { + if (memberState.HasValue) { memberState.Value.TryGetProperty("avatar_url", out var _avatar); - if (_avatar.ValueKind == JsonValueKind.String) - { + if (_avatar.ValueKind == JsonValueKind.String) { hasCustomProfileAvatar = _avatar.GetString() != profile.AvatarUrl; profileAvatar = hs.ResolveMediaUri(_avatar.GetString()); } - else - { + else { profileAvatar = "/icon-192.png"; } memberState.Value.TryGetProperty("displayname", out var _name); - if (_name.ValueKind == JsonValueKind.String) - { + if (_name.ValueKind == JsonValueKind.String) { hasCustomProfileName = _name.GetString() != profile.DisplayName; profileName = _name.GetString(); // Console.WriteLine($"{profile.DisplayName} - {_name.GetString()}: {hasCustomProfileName}"); } - else - { + else { profileName = "Unnamed user"; } } @@ -139,9 +119,6 @@ await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage); } - private void Callback(ProgressEventArgs obj) - { - Console.WriteLine("prog: " + obj.ToJson(indent: false)); - } + private void Callback(ProgressEventArgs obj) => Console.WriteLine("prog: " + obj.ToJson(false)); } \ No newline at end of file -- cgit 1.4.1