From def33cc092ae2c6defcc218b108b7c99cbfb8581 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sun, 2 Jul 2023 01:01:09 +0200 Subject: Prefetch room info --- MatrixRoomUtils.Bot/Bot/Commands/CmdCommand.cs | 7 +- MatrixRoomUtils.Bot/Bot/Commands/HelpCommand.cs | 4 +- MatrixRoomUtils.Bot/Bot/Commands/PingCommand.cs | 6 +- MatrixRoomUtils.Bot/Bot/FileStorageProvider.cs | 2 +- .../Bot/Interfaces/CommandContext.cs | 9 +- MatrixRoomUtils.Bot/Bot/Interfaces/ICommand.cs | 2 +- MatrixRoomUtils.Bot/Bot/MRUBot.cs | 57 +++-- MatrixRoomUtils.Bot/Bot/MRUBotConfiguration.cs | 2 +- MatrixRoomUtils.Bot/Program.cs | 3 +- MatrixRoomUtils.Core/AuthenticatedHomeServer.cs | 1 + MatrixRoomUtils.Core/CreateEvent.cs | 20 -- MatrixRoomUtils.Core/Interfaces/IHomeServer.cs | 18 +- .../Responses/CreateRoomRequest.cs | 3 +- MatrixRoomUtils.Core/RoomTypes/GenericRoom.cs | 20 +- .../Services/HomeserverResolverService.cs | 2 +- MatrixRoomUtils.Core/StateEvent.cs | 6 +- .../Common/MjolnirShortcodeEventData.cs | 2 +- .../StateEventTypes/Common/RoomEmotesEventData.cs | 2 +- .../Spec/CanonicalAliasEventData.cs | 2 +- .../StateEventTypes/Spec/GuestAccessData.cs | 16 -- .../StateEventTypes/Spec/GuestAccessEventData.cs | 16 ++ .../StateEventTypes/Spec/HistoryVisibilityData.cs | 11 - .../Spec/HistoryVisibilityEventData.cs | 11 + .../StateEventTypes/Spec/JoinRulesEventData.cs | 2 +- .../StateEventTypes/Spec/MessageEventData.cs | 17 -- .../Spec/PolicyRuleStateEventData.cs | 2 +- .../StateEventTypes/Spec/PowerLevelEvent.cs | 48 ---- .../StateEventTypes/Spec/PowerLevelEventData.cs | 48 ++++ .../StateEventTypes/Spec/PresenceStateEventData.cs | 2 +- .../StateEventTypes/Spec/ProfileResponse.cs | 13 -- .../Spec/ProfileResponseEventData.cs | 14 ++ .../StateEventTypes/Spec/RoomAliasEventData.cs | 2 +- .../StateEventTypes/Spec/RoomAvatarEventData.cs | 2 +- .../StateEventTypes/Spec/RoomCreateEventData.cs | 2 +- .../Spec/RoomEncryptionEventData.cs | 2 +- .../StateEventTypes/Spec/RoomMemberEventData.cs | 2 +- .../StateEventTypes/Spec/RoomMessageEventData.cs | 19 ++ .../StateEventTypes/Spec/RoomNameEventData.cs | 2 +- .../StateEventTypes/Spec/RoomPinnedEventData.cs | 2 +- .../StateEventTypes/Spec/RoomTopicEventData.cs | 2 +- .../StateEventTypes/Spec/RoomTypingEventData.cs | 2 +- .../StateEventTypes/Spec/ServerACLData.cs | 2 +- .../StateEventTypes/Spec/SpaceChildEventData.cs | 2 +- .../DefaultRoomCreationTemplate.cs | 9 +- MatrixRoomUtils.Web/Classes/RoomInfo.cs | 29 +++ .../Classes/SessionStorageProviderService.cs | 2 +- MatrixRoomUtils.Web/Pages/ModalTest.razor | 2 +- .../Pages/PolicyList/PolicyListEditorPage.razor | 249 -------------------- .../Pages/PolicyList/PolicyListRoomList.razor | 107 --------- .../Pages/RoomManager/RoomManager.razor | 96 -------- .../Pages/RoomManager/RoomManagerTimeline.razor | 11 +- MatrixRoomUtils.Web/Pages/Rooms/Index.razor | 9 +- MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor | 250 +++++++++++++++++++++ MatrixRoomUtils.Web/Shared/InlineUserItem.razor | 3 +- MatrixRoomUtils.Web/Shared/RoomList.razor | 33 ++- .../RoomListComponents/RoomListCategory.razor | 18 +- .../Shared/RoomListComponents/RoomListSpace.razor | 18 +- MatrixRoomUtils.Web/Shared/RoomListItem.razor | 32 ++- .../TimelineComponents/TimelineMemberItem.razor | 1 + MatrixRoomUtils.Web/Shared/UserListItem.razor | 3 +- 60 files changed, 552 insertions(+), 729 deletions(-) delete mode 100644 MatrixRoomUtils.Core/CreateEvent.cs delete mode 100644 MatrixRoomUtils.Core/StateEventTypes/Spec/GuestAccessData.cs create mode 100644 MatrixRoomUtils.Core/StateEventTypes/Spec/GuestAccessEventData.cs delete mode 100644 MatrixRoomUtils.Core/StateEventTypes/Spec/HistoryVisibilityData.cs create mode 100644 MatrixRoomUtils.Core/StateEventTypes/Spec/HistoryVisibilityEventData.cs delete mode 100644 MatrixRoomUtils.Core/StateEventTypes/Spec/MessageEventData.cs delete mode 100644 MatrixRoomUtils.Core/StateEventTypes/Spec/PowerLevelEvent.cs create mode 100644 MatrixRoomUtils.Core/StateEventTypes/Spec/PowerLevelEventData.cs delete mode 100644 MatrixRoomUtils.Core/StateEventTypes/Spec/ProfileResponse.cs create mode 100644 MatrixRoomUtils.Core/StateEventTypes/Spec/ProfileResponseEventData.cs create mode 100644 MatrixRoomUtils.Core/StateEventTypes/Spec/RoomMessageEventData.cs create mode 100644 MatrixRoomUtils.Web/Classes/RoomInfo.cs delete mode 100644 MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor delete mode 100644 MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor delete mode 100644 MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor create mode 100644 MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor diff --git a/MatrixRoomUtils.Bot/Bot/Commands/CmdCommand.cs b/MatrixRoomUtils.Bot/Bot/Commands/CmdCommand.cs index 66f3c4d..79757ae 100644 --- a/MatrixRoomUtils.Bot/Bot/Commands/CmdCommand.cs +++ b/MatrixRoomUtils.Bot/Bot/Commands/CmdCommand.cs @@ -1,9 +1,6 @@ -using System.Runtime.InteropServices; -using System.Text; -using MatrixRoomUtils.Bot.Interfaces; -using Microsoft.Extensions.DependencyInjection; +using MatrixRoomUtils.Bot.Bot.Interfaces; -namespace MatrixRoomUtils.Bot.Commands; +namespace MatrixRoomUtils.Bot.Bot.Commands; public class CmdCommand : ICommand { public string Name { get; } = "cmd"; diff --git a/MatrixRoomUtils.Bot/Bot/Commands/HelpCommand.cs b/MatrixRoomUtils.Bot/Bot/Commands/HelpCommand.cs index af41563..6db10ae 100644 --- a/MatrixRoomUtils.Bot/Bot/Commands/HelpCommand.cs +++ b/MatrixRoomUtils.Bot/Bot/Commands/HelpCommand.cs @@ -1,8 +1,8 @@ using System.Text; -using MatrixRoomUtils.Bot.Interfaces; +using MatrixRoomUtils.Bot.Bot.Interfaces; using Microsoft.Extensions.DependencyInjection; -namespace MatrixRoomUtils.Bot.Commands; +namespace MatrixRoomUtils.Bot.Bot.Commands; public class HelpCommand : ICommand { private readonly IServiceProvider _services; diff --git a/MatrixRoomUtils.Bot/Bot/Commands/PingCommand.cs b/MatrixRoomUtils.Bot/Bot/Commands/PingCommand.cs index a00cc8b..061ca53 100644 --- a/MatrixRoomUtils.Bot/Bot/Commands/PingCommand.cs +++ b/MatrixRoomUtils.Bot/Bot/Commands/PingCommand.cs @@ -1,8 +1,6 @@ -using System.Text; -using MatrixRoomUtils.Bot.Interfaces; -using Microsoft.Extensions.DependencyInjection; +using MatrixRoomUtils.Bot.Bot.Interfaces; -namespace MatrixRoomUtils.Bot.Commands; +namespace MatrixRoomUtils.Bot.Bot.Commands; public class PingCommand : ICommand { public PingCommand() { diff --git a/MatrixRoomUtils.Bot/Bot/FileStorageProvider.cs b/MatrixRoomUtils.Bot/Bot/FileStorageProvider.cs index 8b9e726..c38591d 100644 --- a/MatrixRoomUtils.Bot/Bot/FileStorageProvider.cs +++ b/MatrixRoomUtils.Bot/Bot/FileStorageProvider.cs @@ -3,7 +3,7 @@ using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces.Services; using Microsoft.Extensions.Logging; -namespace MatrixRoomUtils.Bot; +namespace MatrixRoomUtils.Bot.Bot; public class FileStorageProvider : IStorageProvider { private readonly ILogger _logger; diff --git a/MatrixRoomUtils.Bot/Bot/Interfaces/CommandContext.cs b/MatrixRoomUtils.Bot/Bot/Interfaces/CommandContext.cs index ab29554..94007a5 100644 --- a/MatrixRoomUtils.Bot/Bot/Interfaces/CommandContext.cs +++ b/MatrixRoomUtils.Bot/Bot/Interfaces/CommandContext.cs @@ -1,11 +1,12 @@ -using MatrixRoomUtils.Core; using MatrixRoomUtils.Core.Responses; +using MatrixRoomUtils.Core.RoomTypes; +using MatrixRoomUtils.Core.StateEventTypes.Spec; -namespace MatrixRoomUtils.Bot.Interfaces; +namespace MatrixRoomUtils.Bot.Bot.Interfaces; public class CommandContext { public GenericRoom Room { get; set; } public StateEventResponse MessageEvent { get; set; } - public string CommandName => (MessageEvent.TypedContent as MessageEventData).Body.Split(' ')[0][1..]; - public string[] Args => (MessageEvent.TypedContent as MessageEventData).Body.Split(' ')[1..]; + public string CommandName => (MessageEvent.TypedContent as RoomMessageEventData).Body.Split(' ')[0][1..]; + public string[] Args => (MessageEvent.TypedContent as RoomMessageEventData).Body.Split(' ')[1..]; } \ No newline at end of file diff --git a/MatrixRoomUtils.Bot/Bot/Interfaces/ICommand.cs b/MatrixRoomUtils.Bot/Bot/Interfaces/ICommand.cs index b57d8c9..20805b1 100644 --- a/MatrixRoomUtils.Bot/Bot/Interfaces/ICommand.cs +++ b/MatrixRoomUtils.Bot/Bot/Interfaces/ICommand.cs @@ -1,4 +1,4 @@ -namespace MatrixRoomUtils.Bot.Interfaces; +namespace MatrixRoomUtils.Bot.Bot.Interfaces; public interface ICommand { public string Name { get; } diff --git a/MatrixRoomUtils.Bot/Bot/MRUBot.cs b/MatrixRoomUtils.Bot/Bot/MRUBot.cs index 134019a..adf825d 100644 --- a/MatrixRoomUtils.Bot/Bot/MRUBot.cs +++ b/MatrixRoomUtils.Bot/Bot/MRUBot.cs @@ -1,16 +1,15 @@ -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using MatrixRoomUtils.Bot; -using MatrixRoomUtils.Bot.Interfaces; +using MatrixRoomUtils.Bot.Bot.Interfaces; using MatrixRoomUtils.Core; using MatrixRoomUtils.Core.Extensions; -using MatrixRoomUtils.Core.Helpers; using MatrixRoomUtils.Core.Services; -using MatrixRoomUtils.Core.StateEventTypes; +using MatrixRoomUtils.Core.StateEventTypes.Spec; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +namespace MatrixRoomUtils.Bot.Bot; + public class MRUBot : IHostedService { private readonly HomeserverProviderService _homeserverProviderService; private readonly ILogger _logger; @@ -75,32 +74,32 @@ public class MRUBot : IHostedService { var room = await hs.GetRoom(@event.RoomId); // _logger.LogInformation(eventResponse.ToJson(indent: false)); - if (@event is { Type: "m.room.message", TypedContent: MessageEventData message }) { + if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventData message }) { if (message is { MessageType: "m.text" } && message.Body.StartsWith(_configuration.Prefix)) { - var command = _commands.FirstOrDefault(x => x.Name == message.Body.Split(' ')[0][_configuration.Prefix.Length..]); - if (command == null) { - await room.SendMessageEventAsync("m.room.message", - new MessageEventData() { - MessageType = "m.text", - Body = "Command not found!" - }); - return; - } - var ctx = new CommandContext() { - Room = room, - MessageEvent = @event - }; - if (await command.CanInvoke(ctx)) { - await command.Invoke(ctx); - } - else { - await room.SendMessageEventAsync("m.room.message", - new MessageEventData() { - MessageType = "m.text", - Body = "You do not have permission to run this command!" - }); - } + var command = _commands.FirstOrDefault(x => x.Name == message.Body.Split(' ')[0][_configuration.Prefix.Length..]); + if (command == null) { + await room.SendMessageEventAsync("m.room.message", + new RoomMessageEventData() { + MessageType = "m.text", + Body = "Command not found!" + }); + return; + } + var ctx = new CommandContext() { + Room = room, + MessageEvent = @event + }; + if (await command.CanInvoke(ctx)) { + await command.Invoke(ctx); + } + else { + await room.SendMessageEventAsync("m.room.message", + new RoomMessageEventData() { + MessageType = "m.text", + Body = "You do not have permission to run this command!" + }); + } } } }); diff --git a/MatrixRoomUtils.Bot/Bot/MRUBotConfiguration.cs b/MatrixRoomUtils.Bot/Bot/MRUBotConfiguration.cs index c91698a..418eebb 100644 --- a/MatrixRoomUtils.Bot/Bot/MRUBotConfiguration.cs +++ b/MatrixRoomUtils.Bot/Bot/MRUBotConfiguration.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Configuration; -namespace MatrixRoomUtils.Bot; +namespace MatrixRoomUtils.Bot.Bot; public class MRUBotConfiguration { public MRUBotConfiguration(IConfiguration config) { diff --git a/MatrixRoomUtils.Bot/Program.cs b/MatrixRoomUtils.Bot/Program.cs index 0e27286..5dae843 100644 --- a/MatrixRoomUtils.Bot/Program.cs +++ b/MatrixRoomUtils.Bot/Program.cs @@ -1,7 +1,8 @@ // See https://aka.ms/new-console-template for more information using MatrixRoomUtils.Bot; -using MatrixRoomUtils.Bot.Interfaces; +using MatrixRoomUtils.Bot.Bot; +using MatrixRoomUtils.Bot.Bot.Interfaces; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Services; using Microsoft.Extensions.DependencyInjection; diff --git a/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs b/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs index 09da766..fbbb99f 100644 --- a/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs +++ b/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs @@ -9,6 +9,7 @@ using MatrixRoomUtils.Core.Helpers; using MatrixRoomUtils.Core.Interfaces; using MatrixRoomUtils.Core.Responses; using MatrixRoomUtils.Core.Responses.Admin; +using MatrixRoomUtils.Core.RoomTypes; using MatrixRoomUtils.Core.Services; namespace MatrixRoomUtils.Core; diff --git a/MatrixRoomUtils.Core/CreateEvent.cs b/MatrixRoomUtils.Core/CreateEvent.cs deleted file mode 100644 index a7022c5..0000000 --- a/MatrixRoomUtils.Core/CreateEvent.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Text.Json.Serialization; - -namespace MatrixRoomUtils.Core; - -public class CreateEvent { - [JsonPropertyName("creator")] - public string Creator { get; set; } - - [JsonPropertyName("room_version")] - public string RoomVersion { get; set; } - - [JsonPropertyName("type")] - public string? Type { get; set; } - - [JsonPropertyName("predecessor")] - public object? Predecessor { get; set; } - - [JsonPropertyName("m.federate")] - public bool Federate { get; set; } -} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs b/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs index 4ee2a3e..d41a6cd 100644 --- a/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs +++ b/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs @@ -2,6 +2,7 @@ using System.Net.Http.Json; using System.Text.Json; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.StateEventTypes; +using MatrixRoomUtils.Core.StateEventTypes.Spec; namespace MatrixRoomUtils.Core.Interfaces; @@ -12,27 +13,16 @@ public class IHomeServer { protected internal MatrixHttpClient _httpClient { get; set; } = new(); - public async Task GetProfile(string mxid, bool debounce = false, bool cache = true) { - // if (cache) { - // if (debounce) await Task.Delay(Random.Shared.Next(100, 500)); - // if (_profileCache.ContainsKey(mxid)) { - // while (_profileCache[mxid] == null) { - // Console.WriteLine($"Waiting for profile cache for {mxid}, currently {_profileCache[mxid]?.ToJson() ?? "null"} within {_profileCache.Count} profiles..."); - // await Task.Delay(Random.Shared.Next(50, 500)); - // } - // - // return _profileCache[mxid]; - // } - // } + public async Task GetProfile(string mxid) { if(mxid is null) throw new ArgumentNullException(nameof(mxid)); if (_profileCache.ContainsKey(mxid)) { if (_profileCache[mxid] is SemaphoreSlim s) await s.WaitAsync(); - if (_profileCache[mxid] is ProfileResponse p) return p; + if (_profileCache[mxid] is ProfileResponseEventData p) return p; } _profileCache[mxid] = new SemaphoreSlim(1); var resp = await _httpClient.GetAsync($"/_matrix/client/v3/profile/{mxid}"); - var data = await resp.Content.ReadFromJsonAsync(); + var data = await resp.Content.ReadFromJsonAsync(); if (!resp.IsSuccessStatusCode) Console.WriteLine("Profile: " + data); _profileCache[mxid] = data; diff --git a/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs b/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs index 8719b5a..334c05c 100644 --- a/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs +++ b/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs @@ -3,6 +3,7 @@ using System.Text.Json.Serialization; using System.Text.RegularExpressions; using MatrixRoomUtils.Core.Interfaces; using MatrixRoomUtils.Core.StateEventTypes; +using MatrixRoomUtils.Core.StateEventTypes.Spec; namespace MatrixRoomUtils.Core.Responses; @@ -28,7 +29,7 @@ public class CreateRoomRequest { public string Visibility { get; set; } = null!; [JsonPropertyName("power_level_content_override")] - public PowerLevelEvent PowerLevelContentOverride { get; set; } = null!; + public PowerLevelEventData PowerLevelContentOverride { get; set; } = null!; [JsonPropertyName("creation_content")] public JsonObject CreationContent { get; set; } = new(); diff --git a/MatrixRoomUtils.Core/RoomTypes/GenericRoom.cs b/MatrixRoomUtils.Core/RoomTypes/GenericRoom.cs index 879ae6b..db4d4ce 100644 --- a/MatrixRoomUtils.Core/RoomTypes/GenericRoom.cs +++ b/MatrixRoomUtils.Core/RoomTypes/GenericRoom.cs @@ -3,11 +3,9 @@ using System.Text.Json; using System.Web; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Responses; -using MatrixRoomUtils.Core.RoomTypes; -using MatrixRoomUtils.Core.StateEventTypes; -using Microsoft.Extensions.Logging; +using MatrixRoomUtils.Core.StateEventTypes.Spec; -namespace MatrixRoomUtils.Core; +namespace MatrixRoomUtils.Core.RoomTypes; public class GenericRoom { internal readonly AuthenticatedHomeServer _homeServer; @@ -111,14 +109,14 @@ public class GenericRoom { public async Task GetJoinRuleAsync() => await GetStateAsync("m.room.join_rules"); - public async Task GetHistoryVisibilityAsync() => - await GetStateAsync("m.room.history_visibility"); + public async Task GetHistoryVisibilityAsync() => + await GetStateAsync("m.room.history_visibility"); - public async Task GetGuestAccessAsync() => - await GetStateAsync("m.room.guest_access"); + public async Task GetGuestAccessAsync() => + await GetStateAsync("m.room.guest_access"); - public async Task GetCreateEventAsync() => - await GetStateAsync("m.room.create"); + public async Task GetCreateEventAsync() => + await GetStateAsync("m.room.create"); public async Task GetRoomType() { var res = await GetStateAsync("m.room.create"); @@ -149,7 +147,7 @@ public class GenericRoom { await (await _httpClient.PostAsJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/state/{eventType}", content)) .Content.ReadFromJsonAsync(); - public async Task SendMessageEventAsync(string eventType, MessageEventData content) { + public async Task SendMessageEventAsync(string eventType, RoomMessageEventData content) { var res = await _httpClient.PutAsJsonAsync( $"/_matrix/client/v3/rooms/{RoomId}/send/{eventType}/" + Guid.NewGuid(), content); var resu = await res.Content.ReadFromJsonAsync(); diff --git a/MatrixRoomUtils.Core/Services/HomeserverResolverService.cs b/MatrixRoomUtils.Core/Services/HomeserverResolverService.cs index 526a261..e4d8063 100644 --- a/MatrixRoomUtils.Core/Services/HomeserverResolverService.cs +++ b/MatrixRoomUtils.Core/Services/HomeserverResolverService.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging; namespace MatrixRoomUtils.Core.Services; public class HomeserverResolverService { - private readonly MatrixHttpClient _httpClient = new MatrixHttpClient(); + private readonly MatrixHttpClient _httpClient = new(); private readonly ILogger _logger; private static Dictionary _wellKnownCache = new(); diff --git a/MatrixRoomUtils.Core/StateEvent.cs b/MatrixRoomUtils.Core/StateEvent.cs index 18b4632..901a194 100644 --- a/MatrixRoomUtils.Core/StateEvent.cs +++ b/MatrixRoomUtils.Core/StateEvent.cs @@ -53,10 +53,6 @@ public class StateEvent { } } - public T1 GetContent() where T1 : IStateEventType { - return RawContent.Deserialize(); - } - [JsonIgnore] public Type GetType { get { @@ -81,7 +77,7 @@ public class StateEvent { RawContent.ToJson()); Console.WriteLine($"Saved to unknown_state_events/{Type}/{stateEventResponse.EventId}.json"); } - else if (RawContent.FindExtraJsonObjectFields(type)) { + else if (RawContent is not null && RawContent.FindExtraJsonObjectFields(type)) { Directory.CreateDirectory($"unknown_state_events/{Type}"); File.WriteAllText($"unknown_state_events/{Type}/{stateEventResponse.EventId}.json", RawContent.ToJson()); diff --git a/MatrixRoomUtils.Core/StateEventTypes/Common/MjolnirShortcodeEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Common/MjolnirShortcodeEventData.cs index efc946d..66dcdb9 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Common/MjolnirShortcodeEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Common/MjolnirShortcodeEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Common; [MatrixEvent(EventName = "org.matrix.mjolnir.shortcode")] public class MjolnirShortcodeEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Common/RoomEmotesEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Common/RoomEmotesEventData.cs index 4a75b98..633998c 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Common/RoomEmotesEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Common/RoomEmotesEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Common; [MatrixEvent(EventName = "im.ponies.room_emotes")] public class RoomEmotesEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/CanonicalAliasEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/CanonicalAliasEventData.cs index 4d6f9c3..354f99d 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/CanonicalAliasEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/CanonicalAliasEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.room.canonical_alias")] public class CanonicalAliasEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/GuestAccessData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/GuestAccessData.cs deleted file mode 100644 index 1727ce9..0000000 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/GuestAccessData.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Text.Json.Serialization; -using MatrixRoomUtils.Core.Extensions; -using MatrixRoomUtils.Core.Interfaces; - -namespace MatrixRoomUtils.Core.StateEventTypes; - -[MatrixEvent(EventName = "m.room.guest_access")] -public class GuestAccessData : IStateEventType { - [JsonPropertyName("guest_access")] - public string GuestAccess { get; set; } - - public bool IsGuestAccessEnabled { - get => GuestAccess == "can_join"; - set => GuestAccess = value ? "can_join" : "forbidden"; - } -} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/GuestAccessEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/GuestAccessEventData.cs new file mode 100644 index 0000000..c5b92ad --- /dev/null +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/GuestAccessEventData.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using MatrixRoomUtils.Core.Extensions; +using MatrixRoomUtils.Core.Interfaces; + +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; + +[MatrixEvent(EventName = "m.room.guest_access")] +public class GuestAccessEventData : IStateEventType { + [JsonPropertyName("guest_access")] + public string GuestAccess { get; set; } + + public bool IsGuestAccessEnabled { + get => GuestAccess == "can_join"; + set => GuestAccess = value ? "can_join" : "forbidden"; + } +} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/HistoryVisibilityData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/HistoryVisibilityData.cs deleted file mode 100644 index 2bae838..0000000 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/HistoryVisibilityData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using MatrixRoomUtils.Core.Extensions; -using MatrixRoomUtils.Core.Interfaces; - -namespace MatrixRoomUtils.Core.StateEventTypes; - -[MatrixEvent(EventName = "m.room.history_visibility")] -public class HistoryVisibilityData : IStateEventType { - [JsonPropertyName("history_visibility")] - public string HistoryVisibility { get; set; } -} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/HistoryVisibilityEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/HistoryVisibilityEventData.cs new file mode 100644 index 0000000..e0785b9 --- /dev/null +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/HistoryVisibilityEventData.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using MatrixRoomUtils.Core.Extensions; +using MatrixRoomUtils.Core.Interfaces; + +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; + +[MatrixEvent(EventName = "m.room.history_visibility")] +public class HistoryVisibilityEventData : IStateEventType { + [JsonPropertyName("history_visibility")] + public string HistoryVisibility { get; set; } +} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/JoinRulesEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/JoinRulesEventData.cs index 590835b..f5410dc 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/JoinRulesEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/JoinRulesEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.room.join_rules")] public class JoinRulesEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/MessageEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/MessageEventData.cs deleted file mode 100644 index bc1c52b..0000000 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/MessageEventData.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; -using MatrixRoomUtils.Core.Extensions; -using MatrixRoomUtils.Core.Interfaces; - -[MatrixEvent(EventName = "m.room.message")] -public class MessageEventData : IStateEventType { - [JsonPropertyName("body")] - public string Body { get; set; } - [JsonPropertyName("msgtype")] - public string MessageType { get; set; } = "m.notice"; - - [JsonPropertyName("formatted_body")] - public string FormattedBody { get; set; } - - [JsonPropertyName("format")] - public string Format { get; set; } -} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/PolicyRuleStateEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/PolicyRuleStateEventData.cs index debbef0..ef94cff 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/PolicyRuleStateEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/PolicyRuleStateEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.policy.rule.user")] [MatrixEvent(EventName = "m.policy.rule.server")] diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/PowerLevelEvent.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/PowerLevelEvent.cs deleted file mode 100644 index c6100bb..0000000 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/PowerLevelEvent.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Text.Json.Serialization; -using MatrixRoomUtils.Core.Extensions; -using MatrixRoomUtils.Core.Interfaces; - -namespace MatrixRoomUtils.Core.StateEventTypes; - -[MatrixEvent(EventName = "m.room.power_levels")] -public class PowerLevelEvent : IStateEventType { - [JsonPropertyName("ban")] - public int Ban { get; set; } // = 50; - - [JsonPropertyName("events_default")] - public int EventsDefault { get; set; } // = 0; - - [JsonPropertyName("events")] - public Dictionary Events { get; set; } // = null!; - - [JsonPropertyName("invite")] - public int Invite { get; set; } // = 50; - - [JsonPropertyName("kick")] - public int Kick { get; set; } // = 50; - - [JsonPropertyName("notifications")] - public NotificationsPL NotificationsPl { get; set; } // = null!; - - [JsonPropertyName("redact")] - public int Redact { get; set; } // = 50; - - [JsonPropertyName("state_default")] - public int StateDefault { get; set; } // = 50; - - [JsonPropertyName("users")] - public Dictionary Users { get; set; } // = null!; - - [JsonPropertyName("users_default")] - public int UsersDefault { get; set; } // = 0; - - [Obsolete("Historical was a key related to MSC2716, a spec change on backfill that was dropped!", true)] - [JsonIgnore] - [JsonPropertyName("historical")] - public int Historical { get; set; } // = 50; - - public class NotificationsPL { - [JsonPropertyName("room")] - public int Room { get; set; } = 50; - } -} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/PowerLevelEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/PowerLevelEventData.cs new file mode 100644 index 0000000..6846db4 --- /dev/null +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/PowerLevelEventData.cs @@ -0,0 +1,48 @@ +using System.Text.Json.Serialization; +using MatrixRoomUtils.Core.Extensions; +using MatrixRoomUtils.Core.Interfaces; + +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; + +[MatrixEvent(EventName = "m.room.power_levels")] +public class PowerLevelEventData : IStateEventType { + [JsonPropertyName("ban")] + public int Ban { get; set; } // = 50; + + [JsonPropertyName("events_default")] + public int EventsDefault { get; set; } // = 0; + + [JsonPropertyName("events")] + public Dictionary Events { get; set; } // = null!; + + [JsonPropertyName("invite")] + public int Invite { get; set; } // = 50; + + [JsonPropertyName("kick")] + public int Kick { get; set; } // = 50; + + [JsonPropertyName("notifications")] + public NotificationsPL NotificationsPl { get; set; } // = null!; + + [JsonPropertyName("redact")] + public int Redact { get; set; } // = 50; + + [JsonPropertyName("state_default")] + public int StateDefault { get; set; } // = 50; + + [JsonPropertyName("users")] + public Dictionary Users { get; set; } // = null!; + + [JsonPropertyName("users_default")] + public int UsersDefault { get; set; } // = 0; + + [Obsolete("Historical was a key related to MSC2716, a spec change on backfill that was dropped!", true)] + [JsonIgnore] + [JsonPropertyName("historical")] + public int Historical { get; set; } // = 50; + + public class NotificationsPL { + [JsonPropertyName("room")] + public int Room { get; set; } = 50; + } +} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/PresenceStateEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/PresenceStateEventData.cs index a17b6f9..c5eb2ea 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/PresenceStateEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/PresenceStateEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.presence")] public class PresenceStateEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/ProfileResponse.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/ProfileResponse.cs deleted file mode 100644 index d36ef74..0000000 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/ProfileResponse.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Text.Json.Serialization; -using MatrixRoomUtils.Core.Extensions; - -namespace MatrixRoomUtils.Core.StateEventTypes; - -[MatrixEvent(EventName = "m.room.member")] -public class ProfileResponse { - [JsonPropertyName("avatar_url")] - public string? AvatarUrl { get; set; } = ""; - - [JsonPropertyName("displayname")] - public string? DisplayName { get; set; } = ""; -} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/ProfileResponseEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/ProfileResponseEventData.cs new file mode 100644 index 0000000..4596de9 --- /dev/null +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/ProfileResponseEventData.cs @@ -0,0 +1,14 @@ +using System.Text.Json.Serialization; +using MatrixRoomUtils.Core.Extensions; +using MatrixRoomUtils.Core.Interfaces; + +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; + +[MatrixEvent(EventName = "m.room.member")] +public class ProfileResponseEventData : IStateEventType { + [JsonPropertyName("avatar_url")] + public string? AvatarUrl { get; set; } = ""; + + [JsonPropertyName("displayname")] + public string? DisplayName { get; set; } = ""; +} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomAliasEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomAliasEventData.cs index 5141ed2..611e8a2 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomAliasEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomAliasEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.room.alias")] public class RoomAliasEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomAvatarEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomAvatarEventData.cs index 03ce16b..bab297b 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomAvatarEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomAvatarEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.room.avatar")] public class RoomAvatarEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomCreateEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomCreateEventData.cs index 2e4bb5a..8b85d69 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomCreateEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomCreateEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.room.create")] public class RoomCreateEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomEncryptionEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomEncryptionEventData.cs index 8d0576d..c473082 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomEncryptionEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomEncryptionEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.room.encryption")] public class RoomEncryptionEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomMemberEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomMemberEventData.cs index 50d9dd2..a543a2f 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomMemberEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomMemberEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.room.member")] public class RoomMemberEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomMessageEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomMessageEventData.cs new file mode 100644 index 0000000..2c56b88 --- /dev/null +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomMessageEventData.cs @@ -0,0 +1,19 @@ +using System.Text.Json.Serialization; +using MatrixRoomUtils.Core.Extensions; +using MatrixRoomUtils.Core.Interfaces; + +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; + +[MatrixEvent(EventName = "m.room.message")] +public class RoomMessageEventData : IStateEventType { + [JsonPropertyName("body")] + public string Body { get; set; } + [JsonPropertyName("msgtype")] + public string MessageType { get; set; } = "m.notice"; + + [JsonPropertyName("formatted_body")] + public string FormattedBody { get; set; } + + [JsonPropertyName("format")] + public string Format { get; set; } +} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomNameEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomNameEventData.cs index 642b5f9..e5b7d59 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomNameEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomNameEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.room.name")] public class RoomNameEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomPinnedEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomPinnedEventData.cs index 05c0048..d84e962 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomPinnedEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomPinnedEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.room.pinned_events")] public class RoomPinnedEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomTopicEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomTopicEventData.cs index cc5b35b..cdd62a1 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomTopicEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomTopicEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.room.topic")] [MatrixEvent(EventName = "org.matrix.msc3765.topic", Legacy = true)] diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomTypingEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomTypingEventData.cs index eac4af2..017a117 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomTypingEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/RoomTypingEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.typing")] public class RoomTypingEventData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/ServerACLData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/ServerACLData.cs index 41bf0a8..1d56e9c 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/ServerACLData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/ServerACLData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.room.server_acl")] public class ServerACLData : IStateEventType { diff --git a/MatrixRoomUtils.Core/StateEventTypes/Spec/SpaceChildEventData.cs b/MatrixRoomUtils.Core/StateEventTypes/Spec/SpaceChildEventData.cs index f65cd5b..bb62d92 100644 --- a/MatrixRoomUtils.Core/StateEventTypes/Spec/SpaceChildEventData.cs +++ b/MatrixRoomUtils.Core/StateEventTypes/Spec/SpaceChildEventData.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; -namespace MatrixRoomUtils.Core.StateEventTypes; +namespace MatrixRoomUtils.Core.StateEventTypes.Spec; [MatrixEvent(EventName = "m.space.child")] public class SpaceChildEventData : IStateEventType { diff --git a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs index ca6345f..a519977 100644 --- a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs +++ b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs @@ -2,6 +2,7 @@ using System.Text.Json.Nodes; using MatrixRoomUtils.Core; using MatrixRoomUtils.Core.Responses; using MatrixRoomUtils.Core.StateEventTypes; +using MatrixRoomUtils.Core.StateEventTypes.Spec; namespace MatrixRoomUtils.Web.Classes.RoomCreationTemplates; @@ -9,7 +10,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { public string Name => "Default"; public CreateRoomRequest CreateRoomRequest => - new CreateRoomRequest { + new() { Name = "My new room", RoomAliasName = "myroom", InitialState = new List { @@ -21,7 +22,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { }, new() { Type = "m.room.guest_access", - TypedContent = new GuestAccessData { + TypedContent = new GuestAccessEventData { GuestAccess = "can_join" } }, @@ -47,7 +48,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { } }, Visibility = "public", - PowerLevelContentOverride = new PowerLevelEvent { + PowerLevelContentOverride = new PowerLevelEventData { UsersDefault = 0, EventsDefault = 100, StateDefault = 50, @@ -55,7 +56,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { Redact = 50, Kick = 50, Ban = 50, - NotificationsPl = new PowerLevelEvent.NotificationsPL { + NotificationsPl = new PowerLevelEventData.NotificationsPL { Room = 50 }, Events = new Dictionary { diff --git a/MatrixRoomUtils.Web/Classes/RoomInfo.cs b/MatrixRoomUtils.Web/Classes/RoomInfo.cs new file mode 100644 index 0000000..711bf55 --- /dev/null +++ b/MatrixRoomUtils.Web/Classes/RoomInfo.cs @@ -0,0 +1,29 @@ +using MatrixRoomUtils.Core; +using MatrixRoomUtils.Core.Responses; +using MatrixRoomUtils.Core.RoomTypes; + +namespace MatrixRoomUtils.Web.Classes; + +public class RoomInfo { + public GenericRoom Room { get; set; } + public List StateEvents { get; } = new(); + + public async Task GetStateEvent(string type, string stateKey = "") { + var @event = StateEvents.FirstOrDefault(x => x.Type == type && x.StateKey == stateKey); + if (@event is not null) return @event; + @event = new StateEventResponse() { + RoomId = Room.RoomId, + Type = type, + StateKey = stateKey, + }; + try { + @event.TypedContent = await Room.GetStateAsync(type, stateKey); + } + catch (MatrixException e) { + 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/Classes/SessionStorageProviderService.cs b/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs index 4a9c7d1..58466c7 100644 --- a/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs +++ b/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs @@ -1,7 +1,7 @@ using Blazored.SessionStorage; using MatrixRoomUtils.Core.Interfaces.Services; -namespace MatrixRoomUtils.Web; +namespace MatrixRoomUtils.Web.Classes; public class SessionStorageProviderService : IStorageProvider { private readonly ISessionStorageService _sessionStorage; diff --git a/MatrixRoomUtils.Web/Pages/ModalTest.razor b/MatrixRoomUtils.Web/Pages/ModalTest.razor index f32c672..79c7fcd 100644 --- a/MatrixRoomUtils.Web/Pages/ModalTest.razor +++ b/MatrixRoomUtils.Web/Pages/ModalTest.razor @@ -16,7 +16,7 @@ @code { - private Dictionary _windowInfos = new Dictionary(); + private Dictionary _windowInfos = new(); private class WindowInfo { public double X; diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor deleted file mode 100644 index 8e2609f..0000000 --- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor +++ /dev/null @@ -1,249 +0,0 @@ -@page "/PolicyListEditor/{RoomId}" -@using MatrixRoomUtils.Core.StateEventTypes -@using System.Text.Json -@using MatrixRoomUtils.Core.Helpers -@using MatrixRoomUtils.Core.Responses -

Policy list editor - Editing @RoomId

-
- -

- This policy list contains @PolicyEvents.Count(x => x.Type == "m.policy.rule.server") server bans, - @PolicyEvents.Count(x => x.Type == "m.policy.rule.room") room bans and - @PolicyEvents.Count(x => x.Type == "m.policy.rule.user") user bans. -

- - - -@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.server")) { -

No server policies

-} -else { -

Server policies

-
- - - - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { - var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; - - - - - - - } - -
ServerReasonExpiresActions
Entity: @policyData.Entity
State: @policyEvent.StateKey
@policyData.Reason - @policyData.ExpiryDateTime - - - @* *@ -
-
- Redacted events - - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { - var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; - - - - - } - -
State keySerialised Contents
@policyEvent.StateKey@policyEvent.RawContent.ToJson(false, true)
-
-} -@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.room")) { -

No room policies

-} -else { -

Room policies

-
- - - - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { - var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; - - - - - - - } - -
RoomReasonExpiresActions
Entity: @policyData.Entity
State: @policyEvent.StateKey
@policyData.Reason - @policyData.ExpiryDateTime - - -
-
- Redacted events - - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { - - - - - } - -
State keySerialised Contents
@policyEvent.StateKey@policyEvent.RawContent.ToJson(false, true)
-
-} -@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.user")) { -

No user policies

-} -else { -

User policies

-
- - - - @if (_enableAvatars) { - - } - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { - var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; - - @if (_enableAvatars) { - - } - - - - - - } - -
UserReasonExpiresActions
- - Entity: @string.Join("", policyData.Entity.Take(64))
State: @string.Join("", policyEvent.StateKey.Take(64))
@policyData.Reason - @policyData.ExpiryDateTime - - -
-
- Redacted events - - - - - - - - - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { - - - - - } - -
State keySerialised Contents
@policyEvent.StateKey@policyEvent.RawContent.ToJson(false, true)
-
-} - - - -@code { - //get room list - // - sync withroom list filter - // Type = support.feline.msc3784 - //support.feline.policy.lists.msc.v1 - - [Parameter] - public string? RoomId { get; set; } - - private bool _enableAvatars; - - static readonly Dictionary avatars = new(); - static readonly Dictionary servers = new(); - - public static List PolicyEvents { get; set; } = new(); - - protected override async Task OnInitializedAsync() { - await base.OnInitializedAsync(); - var hs = await MRUStorage.GetCurrentSessionOrNavigate(); - if (hs is null) return; - RoomId = RoomId.Replace('~', '.'); - await LoadStatesAsync(); - Console.WriteLine("Policy list editor initialized!"); - } - - private async Task LoadStatesAsync() { - var hs = await MRUStorage.GetCurrentSession(); - var room = await hs.GetRoom(RoomId); - - var states = room.GetFullStateAsync(); - await foreach (var state in states) { - if (!state.Type.StartsWith("m.policy.rule")) continue; - PolicyEvents.Add(state); - } - - - // var stateEventsQuery = await room.GetStateAsync(""); - // var stateEvents = stateEventsQuery.Value.Deserialize>(); - // PolicyEvents = stateEvents.Where(x => x.Type.StartsWith("m.policy.rule")) - // .Select(x => JsonSerializer.Deserialize(JsonSerializer.Serialize(x))).ToList(); - StateHasChanged(); - } - - private async Task GetAvatar(string userId) { - try { - if (avatars.ContainsKey(userId)) return; - var hs = userId.Split(':')[1]; - var server = servers.ContainsKey(hs) ? servers[hs] : new RemoteHomeServer(userId.Split(':')[1]); - if (!servers.ContainsKey(hs)) servers.Add(hs, server); - var profile = await server.GetProfile(userId); - avatars.Add(userId, MediaResolver.ResolveMediaUri(server.FullHomeServerDomain, profile.AvatarUrl)); - servers.Add(userId, server); - StateHasChanged(); - } - catch { - // ignored - } - } - - private async Task GetAllAvatars() { - foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { - await GetAvatar((policyEvent.TypedContent as PolicyRuleStateEventData).Entity); - } - StateHasChanged(); - } - -} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor deleted file mode 100644 index 4db2b5a..0000000 --- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor +++ /dev/null @@ -1,107 +0,0 @@ -@page "/PolicyListEditor" -@using System.Text.Json.Serialization -@using MatrixRoomUtils.Core.Interfaces -@using MatrixRoomUtils.Core.StateEventTypes -@inject ILocalStorageService LocalStorage -@inject NavigationManager NavigationManager -

Policy list editor - Room list

-
- -@if (PolicyRoomList.Count == 0) { -

No policy rooms found.

-

Loading progress: @checkedRoomCount/@totalRoomCount

-} -else { - @if (checkedRoomCount != totalRoomCount) { -

Loading progress: @checkedRoomCount/@totalRoomCount

- } - foreach (var s in PolicyRoomList) { - - -
- Shortcode: @s.Shortcode -
-
- @* [@s.Shortcode] @s.Name (@s.RoomId) *@ - @*
*@ - } -} - -
- - -@code { - //get room list - // - sync withroom list filter - // Type = support.feline.msc3784 - //support.feline.policy.lists.msc.v1 - - public List PolicyRoomList { get; set; } = new(); - - private int checkedRoomCount { get; set; } - private int totalRoomCount { get; set; } - - protected override async Task OnInitializedAsync() { - await base.OnInitializedAsync(); - var hs = await MRUStorage.GetCurrentSessionOrNavigate(); - if (hs is null) return; - await EnumeratePolicyRooms(); - Console.WriteLine("Policy list editor initialized!"); - } - - private async Task EnumeratePolicyRooms() { - var hs = await MRUStorage.GetCurrentSession(); - var rooms = await hs.GetJoinedRooms(); - totalRoomCount = rooms.Count; - StateHasChanged(); - - var semaphore = new SemaphoreSlim(8); - var tasks = new List>(); - foreach (var room in rooms) { - tasks.Add(GetPolicyRoomInfo(room.RoomId, semaphore)); - } - var results = await Task.WhenAll(tasks); - PolicyRoomList.AddRange(results.Where(x => x is not null).Select(x => x.Value)); - - Console.WriteLine($"Detected policy lists: {PolicyRoomList.ToJson()}"); - } - - private async Task GetPolicyRoomInfo(string room, SemaphoreSlim semaphore) { - try { - await semaphore.WaitAsync(); - var hs = await MRUStorage.GetCurrentSession(); - PolicyRoomInfo roomInfo = new() { - RoomId = room - }; - var r = await hs.GetRoom(room); - var shortcodeState = await r.GetStateAsync("org.matrix.mjolnir.shortcode"); - roomInfo.Shortcode = shortcodeState.Shortcode; - - if (roomInfo.Shortcode is not null) { - roomInfo.Name = await r.GetNameAsync(); - return roomInfo; - } - - return null; - } - finally { - checkedRoomCount++; - StateHasChanged(); - semaphore.Release(); - } - } - - - - public struct PolicyRoomInfo { - public - string RoomId { get; set; } - - public - string? Shortcode { get; set; } - - public - string? Name { get; set; } - } - -} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor deleted file mode 100644 index 087adf8..0000000 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor +++ /dev/null @@ -1,96 +0,0 @@ -@page "/RoomManager" -@inject ILocalStorageService LocalStorage -@inject NavigationManager NavigationManager -

Room manager

-
-@if (Rooms.Count == 0) { -

You are not in any rooms!

-} -else { -

You are in @Rooms.Count rooms and @Spaces.Count spaces

-

- Create room -

- -
- Space List - @foreach (var room in Spaces) { - - - - } -
-
- Room List - @foreach (var room in Rooms) { - - - - } -
-} - -
- - -@code { - public List Rooms { get; set; } = new(); - public List Spaces { get; set; } = new(); - - protected override async Task OnInitializedAsync() { - Console.WriteLine("Initializing room manager"); - Console.WriteLine("Loaded from local storage"); - await base.OnInitializedAsync(); - Console.WriteLine("Initialized base"); - var hs = await MRUStorage.GetCurrentSessionOrNavigate(); - if (hs is null) return; - Console.WriteLine("Fetching joined rooms"); - var _rooms = await hs.GetJoinedRooms(); - StateHasChanged(); - Console.WriteLine($"Got {_rooms.Count} rooms"); - var semaphore = new SemaphoreSlim(10); - var tasks = new List>(); - foreach (var room in _rooms) { - tasks.Add(CheckIfSpace(room, semaphore)); - } - await Task.WhenAll(tasks); - - Console.WriteLine("Fetched joined rooms!"); - } - - private async Task CheckIfSpace(GenericRoom room, SemaphoreSlim semaphore) { - await semaphore.WaitAsync(); - // Console.WriteLine($"Checking if {room.RoomId} is a space"); - try { - var state = await room.GetStateAsync("m.room.create"); - if (state is not null) { - //Console.WriteLine(state.Value.ToJson()); - if (state.Type is not null) { - if (state.Type == "m.space") { - Console.WriteLine($"Room {room.RoomId} is a space!"); - Spaces.Add(room); - StateHasChanged(); - return room; - } - else { - Console.WriteLine($"Encountered unknown room type {state.Type}"); - } - } - else { - Rooms.Add(room); - //this is fine, apprently... - // Console.WriteLine($"Room {room.RoomId} has no Content.type in m.room.create!"); - } - } - } - catch (Exception e) { - Console.WriteLine(e); - return null; - } - finally { - semaphore.Release(); - } - return null; - } - -} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor index e32b5cb..3225c15 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor @@ -14,13 +14,12 @@ @code { [Parameter] - public string RoomId { get; set; } = "invalid!!!!!!"; + public string RoomId { get; set; } private List Messages { get; } = new(); private List Events { get; } = new(); protected override async Task OnInitializedAsync() { - RoomId = RoomId.Replace('~', '.'); Console.WriteLine("RoomId: " + RoomId); var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; @@ -46,10 +45,10 @@ _ => typeof(TimelineUnknownItem) }; - private Dictionary ComponentParameters(Type ComponentType, StateEventResponse Event) => ComponentType switch { - Type t when t == typeof(TimelineMessageItem) => new Dictionary { { "Event", Event }, { "Events", Events } }, - Type t when t == typeof(TimelineMemberItem) => new Dictionary { { "Event", Event }, { "Events", Events } }, - _ => new Dictionary { { "Event", Event }, { "Events", Events } } + private Dictionary ComponentParameters(Type componentType, StateEventResponse @event) => componentType switch { + not null when componentType == typeof(TimelineMessageItem) => new Dictionary { { "Event", @event }, { "Events", Events } }, + not null when componentType == typeof(TimelineMemberItem) => new Dictionary { { "Event", @event }, { "Events", Events } }, + _ => new Dictionary { { "Event", @event }, { "Events", Events } } }; } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor index 932748d..d88d5b2 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor @@ -1,5 +1,6 @@ @page "/Rooms" @using MatrixRoomUtils.Core.StateEventTypes +@using MatrixRoomUtils.Core.StateEventTypes.Spec

Room list

@if (Rooms is not null) { @@ -9,14 +10,14 @@ @code { - private List Rooms { get; set; } - private ProfileResponse GlobalProfile { get; set; } - + private List Rooms { get; set; } + 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); - Rooms = await hs.GetJoinedRooms(); + Rooms = (await hs.GetJoinedRooms()).Select(x => new RoomInfo() { Room = x }).ToList(); await base.OnInitializedAsync(); } diff --git a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor new file mode 100644 index 0000000..4cb16b8 --- /dev/null +++ b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor @@ -0,0 +1,250 @@ +@page "/Rooms/{RoomId}/Policies" +@using MatrixRoomUtils.Core.StateEventTypes +@using System.Text.Json +@using MatrixRoomUtils.Core.Helpers +@using MatrixRoomUtils.Core.Responses +@using MatrixRoomUtils.Core.StateEventTypes.Spec +

Policy list editor - Editing @RoomId

+
+ +

+ This policy list contains @PolicyEvents.Count(x => x.Type == "m.policy.rule.server") server bans, + @PolicyEvents.Count(x => x.Type == "m.policy.rule.room") room bans and + @PolicyEvents.Count(x => x.Type == "m.policy.rule.user") user bans. +

+ + + +@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.server")) { +

No server policies

+} +else { +

Server policies

+
+ + + + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { + var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; + + + + + + + } + +
ServerReasonExpiresActions
Entity: @policyData.Entity
State: @policyEvent.StateKey
@policyData.Reason + @policyData.ExpiryDateTime + + + @* *@ +
+
+ Redacted events + + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { + var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; + + + + + } + +
State keySerialised Contents
@policyEvent.StateKey@policyEvent.RawContent.ToJson(false, true)
+
+} +@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.room")) { +

No room policies

+} +else { +

Room policies

+
+ + + + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { + var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; + + + + + + + } + +
RoomReasonExpiresActions
Entity: @policyData.Entity
State: @policyEvent.StateKey
@policyData.Reason + @policyData.ExpiryDateTime + + +
+
+ Redacted events + + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { + + + + + } + +
State keySerialised Contents
@policyEvent.StateKey@policyEvent.RawContent.ToJson(false, true)
+
+} +@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.user")) { +

No user policies

+} +else { +

User policies

+
+ + + + @if (_enableAvatars) { + + } + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { + var policyData = policyEvent.TypedContent as PolicyRuleStateEventData; + + @if (_enableAvatars) { + + } + + + + + + } + +
UserReasonExpiresActions
+ + Entity: @string.Join("", policyData.Entity.Take(64))
State: @string.Join("", policyEvent.StateKey.Take(64))
@policyData.Reason + @policyData.ExpiryDateTime + + +
+
+ Redacted events + + + + + + + + + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { + + + + + } + +
State keySerialised Contents
@policyEvent.StateKey@policyEvent.RawContent.ToJson(false, true)
+
+} + + + +@code { + //get room list + // - sync withroom list filter + // Type = support.feline.msc3784 + //support.feline.policy.lists.msc.v1 + + [Parameter] + public string? RoomId { get; set; } + + private bool _enableAvatars; + + static readonly Dictionary avatars = new(); + static readonly Dictionary servers = new(); + + public static List PolicyEvents { get; set; } = new(); + + protected override async Task OnInitializedAsync() { + await base.OnInitializedAsync(); + var hs = await MRUStorage.GetCurrentSessionOrNavigate(); + if (hs is null) return; + RoomId = RoomId.Replace('~', '.'); + await LoadStatesAsync(); + Console.WriteLine("Policy list editor initialized!"); + } + + private async Task LoadStatesAsync() { + var hs = await MRUStorage.GetCurrentSession(); + var room = await hs.GetRoom(RoomId); + + var states = room.GetFullStateAsync(); + await foreach (var state in states) { + if (!state.Type.StartsWith("m.policy.rule")) continue; + PolicyEvents.Add(state); + } + + + // var stateEventsQuery = await room.GetStateAsync(""); + // var stateEvents = stateEventsQuery.Value.Deserialize>(); + // PolicyEvents = stateEvents.Where(x => x.Type.StartsWith("m.policy.rule")) + // .Select(x => JsonSerializer.Deserialize(JsonSerializer.Serialize(x))).ToList(); + StateHasChanged(); + } + + private async Task GetAvatar(string userId) { + try { + if (avatars.ContainsKey(userId)) return; + var hs = userId.Split(':')[1]; + var server = servers.ContainsKey(hs) ? servers[hs] : new RemoteHomeServer(userId.Split(':')[1]); + if (!servers.ContainsKey(hs)) servers.Add(hs, server); + var profile = await server.GetProfile(userId); + avatars.Add(userId, MediaResolver.ResolveMediaUri(server.FullHomeServerDomain, profile.AvatarUrl)); + servers.Add(userId, server); + StateHasChanged(); + } + catch { + // ignored + } + } + + private async Task GetAllAvatars() { + foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && (x.TypedContent as PolicyRuleStateEventData).Entity is not null)) { + await GetAvatar((policyEvent.TypedContent as PolicyRuleStateEventData).Entity); + } + StateHasChanged(); + } + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor index a498c70..ffccc25 100644 --- a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor +++ b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor @@ -1,6 +1,7 @@ @using MatrixRoomUtils.Core.Responses @using MatrixRoomUtils.Core.StateEventTypes @using MatrixRoomUtils.Core.Helpers +@using MatrixRoomUtils.Core.StateEventTypes.Spec
@ProfileName @@ -19,7 +20,7 @@ public RenderFragment? ChildContent { get; set; } [Parameter] - public ProfileResponse User { get; set; } + public ProfileResponseEventData User { get; set; } [Parameter] public string? UserId { get; set; } diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor index 7e002ed..db2d059 100644 --- a/MatrixRoomUtils.Web/Shared/RoomList.razor +++ b/MatrixRoomUtils.Web/Shared/RoomList.razor @@ -1,5 +1,7 @@ @using MatrixRoomUtils.Web.Shared.RoomListComponents; @using MatrixRoomUtils.Core.StateEventTypes +@using MatrixRoomUtils.Core.StateEventTypes.Common +@using MatrixRoomUtils.Core.StateEventTypes.Spec

@Rooms.Count rooms total, @RoomsWithTypes.Sum(x=>x.Value.Count) fetched so far...

@if(Rooms.Count != RoomsWithTypes.Sum(x=>x.Value.Count)) {

Fetching more rooms...

@@ -16,14 +18,14 @@ else { @code { [Parameter] - public List Rooms { get; set; } + public List Rooms { get; set; } [Parameter] - public ProfileResponse? GlobalProfile { get; set; } + public ProfileResponseEventData? GlobalProfile { get; set; } - Dictionary> RoomsWithTypes = new(); + Dictionary> RoomsWithTypes = new(); protected override async Task OnInitializedAsync() { - GlobalProfile ??= await (await MRUStorage.GetCurrentSession()!).GetProfile((await MRUStorage.GetCurrentSession()!).WhoAmI.UserId); + GlobalProfile ??= await (await MRUStorage.GetCurrentSession())!.GetProfile((await MRUStorage.GetCurrentSession())!.WhoAmI.UserId); if (RoomsWithTypes.Any()) return; var tasks = Rooms.Select(AddRoom); @@ -35,35 +37,42 @@ else { private string GetRoomTypeName(string? roomType) => roomType switch { "m.space" => "Space", "msc3588.stories.stories-room" => "Story room", + "support.feline.policy.lists.msc.v1" => "MSC3784 Policy list (v1)", null => "Room", _ => roomType }; - private static SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(4, 4); - private async Task AddRoom(GenericRoom room) { + private static SemaphoreSlim _semaphoreSlim = new(8, 8); + private async Task AddRoom(RoomInfo room) { await _semaphoreSlim.WaitAsync(); string roomType; try { - var createEvent = await room.GetCreateEventAsync(); + RoomCreateEventData createEvent = (await room.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventData; roomType = GetRoomTypeName(createEvent.Type); if (roomType == "Room") { - var shortcodeState = await room.GetStateAsync("org.matrix.mjolnir.shortcode"); - if (shortcodeState is not null) roomType = "Legacy policy room"; + var mjolnirData = await room.GetStateEvent("org.matrix.mjolnir.shortcode"); + if(mjolnirData?.RawContent?.ToJson(ignoreNull: true) is not null and not "{}") + roomType = "Legacy policy room"; } + //prefetch some stuff + await Task.WhenAll( + room.GetStateEvent("m.room.name"), + room.GetStateEvent("m.room.name") + ); } catch (MatrixException e) { roomType = $"Error: {e.ErrorCode}"; } if (!RoomsWithTypes.ContainsKey(roomType)) { - RoomsWithTypes.Add(roomType, new List()); + RoomsWithTypes.Add(roomType, new List()); } RoomsWithTypes[roomType].Add(room); - // if (RoomsWithTypes.Count % 10 == 0) - StateHasChanged(); + // if (RoomsWithTypes[roomType].Count % 10 == 0) + StateHasChanged(); // await Task.Delay(100); _semaphoreSlim.Release(); } diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor index e860321..4be3c1f 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor @@ -1,12 +1,16 @@ @using MatrixRoomUtils.Core.StateEventTypes +@using MatrixRoomUtils.Core.StateEventTypes.Spec
@roomType (@rooms.Count) @foreach (var room in rooms) {
- - View timeline - View state - Edit state + + @if (room.StateEvents.Any(x => x.Type == "m.room.create")) { + + } + View timeline + View state + Edit state @if (roomType == "Space") { @@ -19,12 +23,12 @@ @code { [Parameter] - public KeyValuePair> Category { get; set; } + public KeyValuePair> Category { get; set; } [Parameter] - public ProfileResponse? GlobalProfile { get; set; } + public ProfileResponseEventData? GlobalProfile { get; set; } private string roomType => Category.Key; - private List rooms => Category.Value; + private List rooms => Category.Value; } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor index 73dc334..5153658 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor @@ -1,4 +1,4 @@ -Manage space +Manage space
@@ -14,23 +14,25 @@ @code { [Parameter] - public GenericRoom Space { get; set; } + public RoomInfo Space { get; set; } [Parameter, CascadingParameter] public string? Breadcrumbs { - get => _breadcrumbs + Space.RoomId; + get => _breadcrumbs + Space.Room.RoomId; set => _breadcrumbs = value; } - private List Children { get; set; } = new(); + private List Children { get; set; } = new(); protected override async Task OnInitializedAsync() { if (Breadcrumbs == null) throw new ArgumentNullException(nameof(Breadcrumbs)); await Task.Delay(Random.Shared.Next(1000, 10000)); - var rooms = Space.AsSpace.GetRoomsAsync(); + var rooms = Space.Room.AsSpace.GetRoomsAsync(); await foreach (var room in rooms) { - if(Breadcrumbs.Contains(room.RoomId)) continue; - Children.Add(room); + if (Breadcrumbs.Contains(room.RoomId)) continue; + Children.Add(new() { + Room = room + }); } await base.OnInitializedAsync(); } @@ -41,7 +43,7 @@ private async Task SpaceChildrenOpened() { if (_shouldRenderChildren) return; _shouldRenderChildren = true; - Console.WriteLine($"[RoomList] Rendering children of {Space.RoomId}"); + 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 13cc02d..d35c9ab 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor @@ -2,6 +2,7 @@ @using System.Text.Json @using MatrixRoomUtils.Core.Helpers @using MatrixRoomUtils.Core.StateEventTypes +@using MatrixRoomUtils.Core.StateEventTypes.Spec
@if (OwnMemberState != null) { ("m.room.member", hs.UserId); - GlobalProfile ??= await hs.GetProfile(hs.UserId, true); + OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.UserId)).TypedContent as RoomMemberEventData; + GlobalProfile ??= await hs.GetProfile(hs.UserId); } catch (MatrixException e) { if (e is { ErrorCode: "M_FORBIDDEN" }) { @@ -93,7 +105,7 @@ private async Task CheckRoomVersion() { try { - var ce = await Room.GetCreateEventAsync(); + var ce = (await RoomInfo.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventData; if (int.TryParse(ce.RoomVersion, out var rv)) { if (rv < 10) hasOldRoomVersion = true; @@ -115,9 +127,9 @@ private async Task GetRoomInfo() { try { - roomName ??= await Room.GetNameAsync(); + roomName ??= ((await RoomInfo.GetStateEvent("m.room.name"))?.TypedContent as RoomNameEventData)?.Name ?? RoomId; - var state = await Room.GetStateAsync("m.room.avatar"); + 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})"); diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor index b7e0220..519e0b2 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor @@ -1,5 +1,6 @@ @using MatrixRoomUtils.Core.Responses @using MatrixRoomUtils.Core.StateEventTypes +@using MatrixRoomUtils.Core.StateEventTypes.Spec @if (roomMemberData.Membership == "ban") { @Event.StateKey was banned diff --git a/MatrixRoomUtils.Web/Shared/UserListItem.razor b/MatrixRoomUtils.Web/Shared/UserListItem.razor index a41ce49..20b1c8c 100644 --- a/MatrixRoomUtils.Web/Shared/UserListItem.razor +++ b/MatrixRoomUtils.Web/Shared/UserListItem.razor @@ -1,6 +1,7 @@ @using MatrixRoomUtils.Core.Responses @using MatrixRoomUtils.Core.StateEventTypes @using MatrixRoomUtils.Core.Helpers +@using MatrixRoomUtils.Core.StateEventTypes.Spec
@profileName @@ -19,7 +20,7 @@ public RenderFragment? ChildContent { get; set; } [Parameter] - public ProfileResponse User { get; set; } + public ProfileResponseEventData User { get; set; } [Parameter] public string UserId { get; set; } -- cgit 1.4.1