diff options
author | Emma@Rory& <root@rory.gay> | 2023-07-24 20:56:42 +0200 |
---|---|---|
committer | Emma@Rory& <root@rory.gay> | 2023-07-24 20:56:42 +0200 |
commit | 5495a35403d285007d67f503042720302efdf94c (patch) | |
tree | 3db4dc545ce3ad252f82a577ecad4150320c1ba3 /MatrixRoomUtils.Web | |
parent | Change max line width from 120 to 180 (diff) | |
download | MatrixUtils-5495a35403d285007d67f503042720302efdf94c.tar.xz |
Code cleanup
Diffstat (limited to 'MatrixRoomUtils.Web')
13 files changed, 105 insertions, 105 deletions
diff --git a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs index a519977..f895173 100644 --- a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs +++ b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs @@ -48,7 +48,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { } }, Visibility = "public", - PowerLevelContentOverride = new PowerLevelEventData { + PowerLevelContentOverride = new RoomPowerLevelEventData { UsersDefault = 0, EventsDefault = 100, StateDefault = 50, @@ -56,7 +56,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { Redact = 50, Kick = 50, Ban = 50, - NotificationsPl = new PowerLevelEventData.NotificationsPL { + NotificationsPl = new RoomPowerLevelEventData.NotificationsPL { Room = 50 }, Events = new Dictionary<string, int> { diff --git a/MatrixRoomUtils.Web/Classes/RoomInfo.cs b/MatrixRoomUtils.Web/Classes/RoomInfo.cs index 5ecc431..f9d5452 100644 --- a/MatrixRoomUtils.Web/Classes/RoomInfo.cs +++ b/MatrixRoomUtils.Web/Classes/RoomInfo.cs @@ -1,13 +1,14 @@ using MatrixRoomUtils.Core; +using MatrixRoomUtils.Core.Interfaces; using MatrixRoomUtils.Core.Responses; using MatrixRoomUtils.Core.RoomTypes; -namespace MatrixRoomUtils.Web.Classes; +namespace MatrixRoomUtils.Web.Classes; public class RoomInfo { public GenericRoom Room { get; set; } public List<StateEventResponse?> StateEvents { get; init; } = new(); - + public async Task<StateEventResponse?> GetStateEvent(string type, string stateKey = "") { var @event = StateEvents.FirstOrDefault(x => x.Type == type && x.StateKey == stateKey); if (@event is not null) return @event; @@ -23,7 +24,8 @@ public class RoomInfo { if (e is { ErrorCode: "M_NOT_FOUND" }) @event.TypedContent = default!; else throw; } + StateEvents.Add(@event); return @event; } -} \ No newline at end of file +} diff --git a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj index 13a120c..4b874c9 100644 --- a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj +++ b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj @@ -11,7 +11,6 @@ <PackageReference Include="Blazored.SessionStorage" Version="2.3.0" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.7" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.7" PrivateAssets="all" /> - <PackageReference Include="XtermBlazor" Version="1.9.0" /> </ItemGroup> <ItemGroup> diff --git a/MatrixRoomUtils.Web/Pages/About.razor b/MatrixRoomUtils.Web/Pages/About.razor index 971bd9b..48c7686 100644 --- a/MatrixRoomUtils.Web/Pages/About.razor +++ b/MatrixRoomUtils.Web/Pages/About.razor @@ -3,7 +3,6 @@ @using System.Net.Sockets @inject NavigationManager NavigationManager @inject ILocalStorageService LocalStorage -@using XtermBlazor <PageTitle>About</PageTitle> @@ -22,10 +21,6 @@ <p>This deployment also serves a copy of the compiled, hosting-ready binaries at <a href="MRU-SRC.tar.xz">/MRU-SRC.tar.xz</a>!</p> } -<Xterm @ref="_terminal" Options="_options" OnFirstRender="@OnFirstRender" style="max-width: fit-content; overflow-x: hidden;"/> - - - @code { private bool showBinDownload { get; set; } private bool showSrcDownload { get; set; } @@ -39,29 +34,4 @@ await base.OnInitializedAsync(); } - - private Xterm _terminal; - - private TerminalOptions _options = new TerminalOptions - { - CursorBlink = true, - CursorStyle = CursorStyle.Block, - Theme = - { - Background = "#17615e", - }, - }; - - private async Task OnFirstRender() { - var message = "Hello, World!\nThis is a terminal emulator!\n\nYou can type stuff here, and it will be sent to the server!\n\nThis is a test of the emergency broadcast system.\n\nThis is only a t"; - _terminal.Options.RendererType = RendererType.Dom; - _terminal.Options.ScreenReaderMode = true; -// TcpClient. - for (var i = 0; i < message.Length; i++) { - await _terminal.Write(message[i].ToString()); - - await Task.Delay(50); - _terminal.Options.Theme.Background = $"#{(i * 2):X6}"; - } - } } diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor index 816299f..6d12dc2 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor @@ -13,45 +13,54 @@ @code { + public List<RoomInfo> KnownRooms { get; set; } = new(); + private List<RoomInfo> Rooms { get; set; } = new(); private ProfileResponseEventData GlobalProfile { get; set; } - protected override async Task OnInitializedAsync() { - var hs = await MRUStorage.GetCurrentSessionOrNavigate(); - if (hs is null) return; - GlobalProfile = await hs.GetProfile(hs.WhoAmI.UserId); - var filter = new SyncFilter() { + private SyncFilter filter = new() { + AccountData = new() { + NotTypes = new() { "*" }, + Limit = 1 + }, + Presence = new() { + NotTypes = new() { "*" }, + Limit = 1 + }, + Room = new() { AccountData = new() { - NotTypes = new() { "*" } + NotTypes = new() { "*" }, + Limit = 1 }, - Presence = new() { - NotTypes = new() { "*" } + Ephemeral = new() { + NotTypes = new() { "*" }, + Limit = 1 }, - Room = new RoomFilter() { - AccountData = new() { - NotTypes = new() { "*" } - }, - Ephemeral = new() { - NotTypes = new() { "*" } - }, - State = new RoomFilter.StateFilter() { - Types = new List<string>() { - "m.room.name", - "m.room.avatar", - "m.room.create", - "org.matrix.mjolnir.shortcode", - } - }, - Timeline = new() { - NotTypes = new() { "*" }, - Limit = 1 + State = new() { + Types = new List<string>() { + "m.room.name", + "m.room.avatar", + "m.room.create", + "org.matrix.mjolnir.shortcode", + "m.room.power_levels" } + }, + Timeline = new() { + NotTypes = new() { "*" }, + Limit = 1 } - }; + } + }; + + protected override async Task OnInitializedAsync() { + var hs = await MRUStorage.GetCurrentSessionOrNavigate(); + if (hs is null) return; + GlobalProfile = await hs.GetProfile(hs.WhoAmI.UserId); + Status = "Syncing..."; SyncResult? sync = null; string? nextBatch = null; - while (sync is null or { Rooms.Join.Count: > 10}) { + while (sync is null or { Rooms.Join.Count: >= 1}) { sync = await hs.SyncHelper.Sync(since: nextBatch, filter: filter, timeout: 0); nextBatch = sync?.NextBatch ?? nextBatch; if (sync is null) continue; @@ -70,11 +79,13 @@ StateEvents = new() }; Rooms.Add(room); + KnownRooms.Add(room); } room.StateEvents.AddRange(roomData.State.Events); } - Status = $"Got {Rooms.Count} rooms so far!"; + Status = $"Got {Rooms.Count} rooms so far! Next batch: {nextBatch}"; StateHasChanged(); + await Task.Delay(100); } Console.WriteLine("Sync done!"); Status = "Sync complete!"; @@ -103,8 +114,10 @@ } Console.WriteLine("Set stub data!"); Status = "Set stub data!"; + SemaphoreSlim semaphore = new(8, 8); var memberTasks = Rooms.Select(async roomInfo => { if (!roomInfo.StateEvents.Any(x => x.Type == "m.room.member" && x.StateKey == hs.WhoAmI.UserId)) { + await semaphore.WaitAsync(); roomInfo.StateEvents.Add(new StateEventResponse() { Type = "m.room.member", StateKey = hs.WhoAmI.UserId, @@ -112,6 +125,7 @@ Membership = "unknown" } }); + semaphore.Release(); } }).ToList(); await Task.WhenAll(memberTasks); diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor b/MatrixRoomUtils.Web/Pages/Rooms/Space.razor index afa39b9..91f97d0 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Space.razor @@ -1,4 +1,4 @@ -@page "/RoomManager/Space/{RoomId}" +@page "/Rooms/{RoomId}/Space" @using System.Text.Json @using MatrixRoomUtils.Core.Responses <h3>Room manager - Viewing Space</h3> @@ -93,4 +93,4 @@ } } -} \ No newline at end of file +} diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor b/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor index 8b2ff0c..8b2ff0c 100644 --- a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor b/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor index 09b38f0..09b38f0 100644 --- a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor index 709f2d7..b798d49 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor @@ -6,13 +6,14 @@ @foreach (var room in rooms) { <div class="room-list-item"> <RoomListItem RoomInfo="@room" ShowOwnProfile="@(roomType == "Room")"></RoomListItem> - @if (RoomVersionDangerLevel(room) != 0) { - <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton Color="@(RoomVersionDangerLevel(room) == 2 ? "#ff0000" : "#ff8800")" href="@($"/Rooms/Create?Import={room.Room.RoomId}")">Upgrade room</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton> - } + @* @if (RoomVersionDangerLevel(room) != 0 && *@ + @* (room.StateEvents.FirstOrDefault(x=>x.Type == "m.room.power_levels")?.TypedContent is RoomPowerLevelEventData powerLevels && powerLevels.UserHasPermission(HomeServer.UserId, "m.room.tombstone"))) { *@ + @* <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton Color="@(RoomVersionDangerLevel(room) == 2 ? "#ff0000" : "#ff8800")" href="@($"/Rooms/Create?Import={room.Room.RoomId}")">Upgrade room</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton> *@ + @* } *@ <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{room.Room.RoomId}/Timeline")">View timeline</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton> <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/View")">View state</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton> <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/Edit")">Edit state</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton> - + @if (roomType == "Space") { <RoomListSpace Space="@room"></RoomListSpace> } @@ -25,10 +26,13 @@ [Parameter] public KeyValuePair<string, List<RoomInfo>> Category { get; set; } - + [Parameter] public ProfileResponseEventData? GlobalProfile { get; set; } + [CascadingParameter] + public AuthenticatedHomeServer HomeServer { get; set; } = null!; + private string roomType => Category.Key; private List<RoomInfo> rooms => Category.Value; @@ -42,4 +46,4 @@ return 0; } -} \ No newline at end of file +} diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor index 5153658..a113f0b 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor @@ -1,4 +1,4 @@ -<LinkButton href="@($"/Rooms/{Space.Room.RoomId}/Space")">Manage space</LinkButton> +<MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{Space.Room.RoomId}/Space")">Manage space</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton> <br/> <details @ontoggle="SpaceChildrenOpened"> @@ -17,6 +17,9 @@ public RoomInfo Space { get; set; } [Parameter, CascadingParameter] + public List<RoomInfo> KnownRooms { get; set; } = new(); + + [Parameter, CascadingParameter] public string? Breadcrumbs { get => _breadcrumbs + Space.Room.RoomId; set => _breadcrumbs = value; @@ -30,9 +33,14 @@ var rooms = Space.Room.AsSpace.GetRoomsAsync(); await foreach (var room in rooms) { if (Breadcrumbs.Contains(room.RoomId)) continue; - Children.Add(new() { - Room = room - }); + RoomInfo roomInfo = KnownRooms.FirstOrDefault(x => x.Room.RoomId == room.RoomId); + if (roomInfo is null) { + roomInfo = new() { + Room = room + }; + KnownRooms.Add(roomInfo); + } + Children.Add(roomInfo); } await base.OnInitializedAsync(); } @@ -46,4 +54,4 @@ Console.WriteLine($"[RoomList] Rendering children of {Space.Room.RoomId}"); } -} \ No newline at end of file +} diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor index b89fb18..e12f622 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor @@ -32,7 +32,7 @@ [Parameter] public GenericRoom? Room { get; set; } - + [Parameter] public RoomInfo? RoomInfo { get; set; } @@ -69,20 +69,32 @@ if (Room is null && RoomId is null && RoomInfo is null) { throw new ArgumentNullException(nameof(RoomId)); } - + // sweep from roominfo to id if (RoomInfo is not null) Room = RoomInfo.Room; if(Room is not null) RoomId = Room.RoomId; - + //sweep from id to roominfo if(RoomId is not null) Room ??= await hs.GetRoom(RoomId); if(Room is not null) RoomInfo ??= new RoomInfo() { Room = Room }; - await CheckRoomVersion(); - await GetRoomInfo(); - await LoadOwnProfile(); + try { + await CheckRoomVersion(); + await GetRoomInfo(); + await LoadOwnProfile(); + } + catch (MatrixException e) { + if (e is not { ErrorCode: "M_FORBIDDEN" }) { + throw; + } + roomName = "Error: " + e.Message; + roomIcon = "/blobfox_outage.gif"; + } + catch (Exception e) { + Console.WriteLine($"Failed to load room info for {RoomId}: {e.Message}"); + } _semaphoreSlim.Release(); } @@ -104,24 +116,17 @@ } private async Task CheckRoomVersion() { - try { - var ce = (await RoomInfo.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventData; - if (int.TryParse(ce.RoomVersion, out var rv)) { - if (rv < 10) - hasOldRoomVersion = true; - } - else // treat unstable room versions as dangerous - hasDangerousRoomVersion = true; - - if (RoomConstants.DangerousRoomVersions.Contains(ce.RoomVersion)) { - hasDangerousRoomVersion = true; - roomName = "Dangerous room: " + roomName; - } + var ce = (await RoomInfo.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventData; + if (int.TryParse(ce.RoomVersion, out var rv)) { + if (rv < 10) + hasOldRoomVersion = true; } - catch (MatrixException e) { - if (e is not { ErrorCode: "M_FORBIDDEN" }) { - throw; - } + else // treat unstable room versions as dangerous + hasDangerousRoomVersion = true; + + if (RoomConstants.DangerousRoomVersions.Contains(ce.RoomVersion)) { + hasDangerousRoomVersion = true; + roomName = "Dangerous room: " + roomName; } } @@ -132,7 +137,7 @@ var state = (await RoomInfo.GetStateEvent("m.room.avatar")).TypedContent as RoomAvatarEventData; if (state?.Url is { } url) { roomIcon = MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, url); - Console.WriteLine($"Got avatar for room {RoomId}: {roomIcon} ({url})"); + // Console.WriteLine($"Got avatar for room {RoomId}: {roomIcon} ({url})"); } } catch (MatrixException e) { @@ -142,4 +147,4 @@ } } -} \ No newline at end of file +} diff --git a/MatrixRoomUtils.Web/wwwroot/blobfox_outage.gif b/MatrixRoomUtils.Web/wwwroot/blobfox_outage.gif new file mode 100644 index 0000000..6f1e2ae --- /dev/null +++ b/MatrixRoomUtils.Web/wwwroot/blobfox_outage.gif Binary files differdiff --git a/MatrixRoomUtils.Web/wwwroot/index.html b/MatrixRoomUtils.Web/wwwroot/index.html index 9a85530..0439e62 100644 --- a/MatrixRoomUtils.Web/wwwroot/index.html +++ b/MatrixRoomUtils.Web/wwwroot/index.html @@ -10,8 +10,6 @@ <link href="css/app.css" rel="stylesheet"/> <link href="favicon.png" rel="icon" type="image/png"/> <link href="MatrixRoomUtils.Web.styles.css" rel="stylesheet"/> - <link href="_content/XtermBlazor/XtermBlazor.css" rel="stylesheet" /> - <script src="_content/XtermBlazor/XtermBlazor.min.js"></script> </head> <body> |