From 226c6291551c8f07b2f67914d2b28577b1df7244 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Thu, 14 Dec 2023 07:21:04 +0100 Subject: Cleanup --- LibMatrix | 2 +- .../Components/RoomListEntry.axaml.cs | 1 + MatrixRoomUtils.Desktop/RoomInfo.cs | 5 ++++- .../DefaultRoomCreationTemplate.cs | 3 ++- MatrixRoomUtils.Web/Classes/RoomInfo.cs | 21 +++++++++++++------- MatrixRoomUtils.Web/Pages/About.razor | 2 +- MatrixRoomUtils.Web/Pages/Index.razor | 2 +- .../ModerationUtilities/UserRoomHistory.razor | 3 ++- MatrixRoomUtils.Web/Pages/Rooms/Create.razor | 7 ++++--- MatrixRoomUtils.Web/Pages/Rooms/Index.razor | 2 +- MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor | 1 + MatrixRoomUtils.Web/Pages/Tools/MassJoinRoom.razor | 2 +- MatrixRoomUtils.Web/Pages/User/DMManager.razor | 3 ++- .../Pages/User/DMSpaceStages/DMSpaceStage1.razor | 2 +- MatrixRoomUtils.Web/Program.cs | 9 +++++++-- MatrixRoomUtils.Web/Shared/MainLayout.razor | 2 +- .../RoomListComponents/RoomListCategory.razor | 23 ++++++++++++++++------ MatrixRoomUtils.Web/Shared/RoomListItem.razor | 6 ++++-- MatrixRoomUtils.sln | 7 +++++++ MatrixRoomUtils.sln.DotSettings.user | 2 ++ 20 files changed, 74 insertions(+), 31 deletions(-) create mode 100644 MatrixRoomUtils.sln.DotSettings.user diff --git a/LibMatrix b/LibMatrix index 83f9a4d..5affd9f 160000 --- a/LibMatrix +++ b/LibMatrix @@ -1 +1 @@ -Subproject commit 83f9a4df147ef58c884f43092527f5cb6fa2f0a9 +Subproject commit 5affd9f061e75f6575a2fe6715f9e8757cfe87e8 diff --git a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs index aaa1bee..69458aa 100644 --- a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs +++ b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs @@ -3,6 +3,7 @@ using Avalonia.Interactivity; using Avalonia.Media.Imaging; using LibMatrix; using LibMatrix.EventTypes.Spec.State; +using LibMatrix.EventTypes.Spec.State.RoomInfo; using LibMatrix.Helpers; using LibMatrix.Interfaces.Services; using LibMatrix.Services; diff --git a/MatrixRoomUtils.Desktop/RoomInfo.cs b/MatrixRoomUtils.Desktop/RoomInfo.cs index ebd80ab..a562086 100644 --- a/MatrixRoomUtils.Desktop/RoomInfo.cs +++ b/MatrixRoomUtils.Desktop/RoomInfo.cs @@ -1,4 +1,5 @@ using LibMatrix; +using LibMatrix.EventTypes; using LibMatrix.Interfaces; using LibMatrix.Responses; using LibMatrix.RoomTypes; @@ -21,7 +22,9 @@ public class RoomInfo { @event = new StateEventResponse { RoomId = Room.RoomId, Type = type, - StateKey = stateKey + StateKey = stateKey, + Sender = null, //TODO: implement + EventId = null }; try { @event.TypedContent = await Room.GetStateAsync(type, stateKey); diff --git a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs index 44cd988..a6831d4 100644 --- a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs +++ b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs @@ -1,6 +1,7 @@ using System.Text.Json.Nodes; using LibMatrix; using LibMatrix.EventTypes.Spec.State; +using LibMatrix.EventTypes.Spec.State.RoomInfo; using LibMatrix.Responses; namespace MatrixRoomUtils.Web.Classes.RoomCreationTemplates; @@ -28,7 +29,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { new() { Type = "m.room.join_rules", TypedContent = new RoomJoinRulesEventContent { - JoinRule = "public" + JoinRule = RoomJoinRulesEventContent.JoinRules.Public } }, new() { diff --git a/MatrixRoomUtils.Web/Classes/RoomInfo.cs b/MatrixRoomUtils.Web/Classes/RoomInfo.cs index a8c3848..9d0cd59 100644 --- a/MatrixRoomUtils.Web/Classes/RoomInfo.cs +++ b/MatrixRoomUtils.Web/Classes/RoomInfo.cs @@ -3,13 +3,14 @@ using System.Text.Json.Nodes; using ArcaneLibs; using LibMatrix; using LibMatrix.EventTypes.Spec.State; +using LibMatrix.EventTypes.Spec.State.RoomInfo; using LibMatrix.Interfaces; using LibMatrix.RoomTypes; namespace MatrixRoomUtils.Web.Classes; public class RoomInfo : NotifyPropertyChanged { - public GenericRoom? Room { get; set; } + public required GenericRoom Room { get; set; } public ObservableCollection StateEvents { get; } = new(); public async Task GetStateEvent(string type, string stateKey = "") { @@ -18,9 +19,11 @@ public class RoomInfo : NotifyPropertyChanged { @event = new StateEventResponse { RoomId = Room.RoomId, Type = type, - StateKey = stateKey + StateKey = stateKey, + Sender = null, //TODO implement + EventId = null }; - if (Room is null) return null; + // if (Room is null) return null; try { @event.RawContent = await Room.GetStateAsync(type, stateKey); } @@ -32,7 +35,11 @@ public class RoomInfo : NotifyPropertyChanged { StateKey = stateKey, TypedContent = new RoomNameEventContent() { Name = await Room.GetNameOrFallbackAsync() - } + }, + //TODO implement + RoomId = null, + Sender = null, + EventId = null }; else @event.RawContent = default!; @@ -78,11 +85,11 @@ public class RoomInfo : NotifyPropertyChanged { StateEvents.CollectionChanged += (_, args) => { if (args.NewItems is { Count: > 0 }) foreach (StateEventResponse newState in args.NewItems) { - if (newState.TypedContent is RoomNameEventContent roomNameContent) + if (newState.GetType == typeof(RoomNameEventContent) && newState.TypedContent is RoomNameEventContent roomNameContent) RoomName = roomNameContent.Name; - else if (newState.TypedContent is RoomAvatarEventContent roomAvatarContent) + else if (newState.GetType == typeof(RoomAvatarEventContent) && newState.TypedContent is RoomAvatarEventContent roomAvatarContent) RoomIcon = roomAvatarContent.Url; - else if (newState.TypedContent is RoomCreateEventContent roomCreateContent) { + else if (newState.GetType == typeof(RoomCreateEventContent) && newState.TypedContent is RoomCreateEventContent roomCreateContent) { CreationEventContent = roomCreateContent; RoomCreator = newState.Sender; } diff --git a/MatrixRoomUtils.Web/Pages/About.razor b/MatrixRoomUtils.Web/Pages/About.razor index df6e6c2..a5864ab 100644 --- a/MatrixRoomUtils.Web/Pages/About.razor +++ b/MatrixRoomUtils.Web/Pages/About.razor @@ -11,7 +11,7 @@

These range from joining rooms on dead homeservers, to managing your accounts and rooms, and creating rooms based on templates.



-

You can find the source code on my git server.

+

You can find the source code on my git server.

You can also join the Matrix room for this project.

@if (ShowBinDownload) {

This deployment also serves a copy of the compiled, hosting-ready binaries at /MRU-BIN.tar.xz!

diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor index 68a4f26..2d1d6c0 100644 --- a/MatrixRoomUtils.Web/Pages/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Index.razor @@ -92,7 +92,7 @@ Small collection of tools to do not-so-everyday things. throw; } catch (HttpRequestException e) { - logger.LogError(e, $"Failed to instantiate AuthenticatedHomeserver for {_auth}, homeserver may be offline?", token.UserId); + logger.LogError(e, $"Failed to instantiate AuthenticatedHomeserver for {token.ToJson()}, homeserver may be offline?", token.UserId); return; } var roomCountTask = hs.GetJoinedRooms(); diff --git a/MatrixRoomUtils.Web/Pages/ModerationUtilities/UserRoomHistory.razor b/MatrixRoomUtils.Web/Pages/ModerationUtilities/UserRoomHistory.razor index 02dfe44..d33756b 100644 --- a/MatrixRoomUtils.Web/Pages/ModerationUtilities/UserRoomHistory.razor +++ b/MatrixRoomUtils.Web/Pages/ModerationUtilities/UserRoomHistory.razor @@ -91,7 +91,8 @@ else { Type = RoomNameEventContent.EventId, TypedContent = new RoomNameEventContent() { Name = await room.GetNameOrFallbackAsync(4) - } + }, + RoomId = null, Sender = null, EventId = null //TODO implement }); StateHasChanged(); if (mxid != UserId) { diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor index 08b21dd..e477f4c 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor @@ -4,6 +4,7 @@ @using ArcaneLibs.Extensions @using LibMatrix @using LibMatrix.EventTypes.Spec.State +@using LibMatrix.EventTypes.Spec.State.RoomInfo @using LibMatrix.Homeservers @using LibMatrix.Responses @using MatrixRoomUtils.Web.Classes.RoomCreationTemplates @@ -49,15 +50,15 @@ Room type: - @if (creationEvent._creationContentBaseType is null) { + @if (creationEvent.CreationContentBaseType is null) {

creationEvent._creationContentBaseType is null!

} else { - + - + } diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor index e137b6c..fb44337 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor @@ -161,7 +161,7 @@ } RenderContents |= queue.Count == 0; if (queue.Count > 10) RenderContents = false; - await Task.Delay(RenderContents ? 25 : 25); + await Task.Delay(RenderContents ? 25 : 12); } // else { // Console.WriteLine("Failed to dequeue item"); diff --git a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor index adedbd3..846d1cb 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor @@ -3,6 +3,7 @@ @using LibMatrix.Homeservers @using ArcaneLibs.Extensions @using LibMatrix.EventTypes.Spec.State +@using LibMatrix.EventTypes.Spec.State.Policy

Policy list editor - Editing @RoomId


diff --git a/MatrixRoomUtils.Web/Pages/Tools/MassJoinRoom.razor b/MatrixRoomUtils.Web/Pages/Tools/MassJoinRoom.razor index bcf8095..816b7db 100644 --- a/MatrixRoomUtils.Web/Pages/Tools/MassJoinRoom.razor +++ b/MatrixRoomUtils.Web/Pages/Tools/MassJoinRoom.razor @@ -69,7 +69,7 @@ try { try { var joinRule = await room.GetJoinRuleAsync(); - if (joinRule.JoinRule == "public") return "Room is public, no invite needed"; + if (joinRule.JoinRule == RoomJoinRulesEventContent.JoinRules.Public) return "Room is public, no invite needed"; } catch { } var pls = await room.GetPowerLevelsAsync(); diff --git a/MatrixRoomUtils.Web/Pages/User/DMManager.razor b/MatrixRoomUtils.Web/Pages/User/DMManager.razor index f753f18..1b28516 100644 --- a/MatrixRoomUtils.Web/Pages/User/DMManager.razor +++ b/MatrixRoomUtils.Web/Pages/User/DMManager.razor @@ -46,7 +46,8 @@ Type = RoomNameEventContent.EventId, TypedContent = new RoomNameEventContent() { Name = await Homeserver.GetRoom(room).GetNameOrFallbackAsync(4) - } + }, + RoomId = room, Sender = null, EventId = null }); } StateHasChanged(); diff --git a/MatrixRoomUtils.Web/Pages/User/DMSpaceStages/DMSpaceStage1.razor b/MatrixRoomUtils.Web/Pages/User/DMSpaceStages/DMSpaceStage1.razor index f953f76..5958fc5 100644 --- a/MatrixRoomUtils.Web/Pages/User/DMSpaceStages/DMSpaceStage1.razor +++ b/MatrixRoomUtils.Web/Pages/User/DMSpaceStages/DMSpaceStage1.razor @@ -84,7 +84,7 @@ else { private async Task Execute() { if (string.IsNullOrWhiteSpace(DmSpace.DmSpaceConfiguration.DMSpaceId)) { var crr = CreateRoomRequest.CreatePrivate(DmSpace.Homeserver, "Direct Messages"); - crr._creationContentBaseType.Type = "m.space"; + crr.CreationContentBaseType.Type = "m.space"; DmSpace.DmSpaceConfiguration.DMSpaceId = (await DmSpace.Homeserver.CreateRoom(crr)).RoomId; } await DmSpace.Homeserver!.SetAccountDataAsync(DMSpaceConfiguration.EventId, DmSpace.DmSpaceConfiguration); diff --git a/MatrixRoomUtils.Web/Program.cs b/MatrixRoomUtils.Web/Program.cs index a7a0105..277e4d1 100644 --- a/MatrixRoomUtils.Web/Program.cs +++ b/MatrixRoomUtils.Web/Program.cs @@ -16,10 +16,15 @@ builder.RootComponents.Add("head::after"); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); -builder.Configuration.AddJsonStream(await new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }.GetStreamAsync("/appsettings.json")); +try { + builder.Configuration.AddJsonStream(await new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }.GetStreamAsync("/appsettings.json")); #if DEBUG -builder.Configuration.AddJsonStream(await new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }.GetStreamAsync("/appsettings.Development.json")); + builder.Configuration.AddJsonStream(await new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }.GetStreamAsync("/appsettings.Development.json")); #endif +} +catch (Exception e) { + Console.WriteLine("Could not load appsettings: " + e); +} builder.Services.AddBlazoredLocalStorage(config => { config.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase; diff --git a/MatrixRoomUtils.Web/Shared/MainLayout.razor b/MatrixRoomUtils.Web/Shared/MainLayout.razor index 691acbb..74db805 100644 --- a/MatrixRoomUtils.Web/Shared/MainLayout.razor +++ b/MatrixRoomUtils.Web/Shared/MainLayout.razor @@ -9,7 +9,7 @@
- Git + Git Matrix @if (showDownload) { Download diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor index cbe542a..55ffc1e 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor @@ -4,10 +4,10 @@ @using LibMatrix.Homeservers @using LibMatrix.Responses
- @roomType (@rooms.Count) - @foreach (var room in rooms) { + @RoomType (@Rooms.Count) + @foreach (var room in Rooms) {
- + @* @if (RoomVersionDangerLevel(room) != 0 && *@ @* (room.StateEvents.FirstOrDefault(x=>x.Type == "m.room.power_levels")?.TypedContent is RoomPowerLevelEventContent powerLevels && powerLevels.UserHasPermission(Homeserver.UserId, "m.room.tombstone"))) { *@ @* Upgrade room *@ @@ -16,9 +16,12 @@ View state Edit state - @if (roomType == "Space") { + @if (room.CreationEventContent?.Type == "m.space") { } + else if (room.CreationEventContent?.Type == "support.feline.policy.lists.msc.v1" || RoomType == "org.matrix.mjolnir.policy") { + Manage policies + }
}
@@ -35,8 +38,8 @@ [CascadingParameter] public AuthenticatedHomeserverGeneric Homeserver { get; set; } = null!; - private string roomType => Category.Key; - private List rooms => Category.Value; + private string RoomType => Category.Key; + private List Rooms => Category.Value; private int RoomVersionDangerLevel(RoomInfo room) { var roomVersion = room.StateEvents.FirstOrDefault(x => x.Type == "m.room.create"); @@ -45,5 +48,13 @@ : RoomConstants.DangerousRoomVersions.Contains(roomVersionContent.RoomVersion) ? 2 : roomVersionContent.RoomVersion != RoomConstants.RecommendedRoomVersion ? 1 : 0; } + + public static string GetRoomTypeName(string roomType) { + return roomType switch { + "Room" => "Rooms", + "org.matrix.mjolnir.policy" => "Policies", + _ => roomType + }; + } } diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor index c5c3cfe..3aa28e6 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor @@ -91,13 +91,15 @@ else { LoadData = false; RoomInfo.StateEvents.Add(new() { Type = "m.room.create", - TypedContent = new RoomCreateEventContent() { RoomVersion = "0" } + TypedContent = new RoomCreateEventContent() { RoomVersion = "0" }, + RoomId = null, Sender = null, EventId = null //TODO: implement }); RoomInfo.StateEvents.Add(new() { Type = "m.room.name", TypedContent = new RoomNameEventContent() { Name = "M_FORBIDDEN: Are you a member of this room? " + RoomInfo.Room.RoomId - } + }, + RoomId = null, Sender = null, EventId = null //TODO: implement }); } } diff --git a/MatrixRoomUtils.sln b/MatrixRoomUtils.sln index d3ddab1..58379b3 100644 --- a/MatrixRoomUtils.sln +++ b/MatrixRoomUtils.sln @@ -46,6 +46,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestDataGenerator", "LibMat EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatrixRoomUtils.LibDMSpace", "MatrixRoomUtils.LibDMSpace\MatrixRoomUtils.LibDMSpace.csproj", "{EDD2FBAB-2DEC-4527-AE9C-20E21D0D6B14}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.EventTypes", "LibMatrix\LibMatrix.EventTypes\LibMatrix.EventTypes.csproj", "{1CAA2B6D-0365-4C8B-96EE-26026514FEE2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -120,6 +122,10 @@ Global {EDD2FBAB-2DEC-4527-AE9C-20E21D0D6B14}.Debug|Any CPU.Build.0 = Debug|Any CPU {EDD2FBAB-2DEC-4527-AE9C-20E21D0D6B14}.Release|Any CPU.ActiveCfg = Release|Any CPU {EDD2FBAB-2DEC-4527-AE9C-20E21D0D6B14}.Release|Any CPU.Build.0 = Release|Any CPU + {1CAA2B6D-0365-4C8B-96EE-26026514FEE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1CAA2B6D-0365-4C8B-96EE-26026514FEE2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1CAA2B6D-0365-4C8B-96EE-26026514FEE2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1CAA2B6D-0365-4C8B-96EE-26026514FEE2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {F4E241C3-0300-4B87-8707-BCBDEF1F0185} = {8F4F6BEC-0C66-486B-A21A-1C35B2EDAD33} @@ -138,5 +144,6 @@ Global {7D2C9959-8309-4110-A67F-DEE64E97C1D8} = {8F4F6BEC-0C66-486B-A21A-1C35B2EDAD33} {E37B78F1-D7A5-4F79-ADBA-E12DF7D0F881} = {7D2C9959-8309-4110-A67F-DEE64E97C1D8} {F3312DE9-4335-4E85-A4CF-2616427A651E} = {7D2C9959-8309-4110-A67F-DEE64E97C1D8} + {1CAA2B6D-0365-4C8B-96EE-26026514FEE2} = {8F4F6BEC-0C66-486B-A21A-1C35B2EDAD33} EndGlobalSection EndGlobal diff --git a/MatrixRoomUtils.sln.DotSettings.user b/MatrixRoomUtils.sln.DotSettings.user new file mode 100644 index 0000000..6daed5b --- /dev/null +++ b/MatrixRoomUtils.sln.DotSettings.user @@ -0,0 +1,2 @@ + + DoNotShowAndRun \ No newline at end of file -- cgit 1.4.1