diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-13 01:49:10 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-13 01:49:10 +0200 |
commit | fc749b3e57098740377e6eabd5d010d133256fa5 (patch) | |
tree | cc97267a3d4222c910769e46bdb37c96c7c31531 /MatrixRoomUtils.Web/Pages/RoomManager | |
parent | unknown changes (diff) | |
download | MatrixUtils-fc749b3e57098740377e6eabd5d010d133256fa5.tar.xz |
Improved many features
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/RoomManager')
3 files changed, 70 insertions, 3 deletions
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor index a8b8fd4..5daa97c 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor @@ -6,7 +6,6 @@ @if (Rooms.Count == 0) { <p>You are not in any rooms!</p> - @* <p>Loading progress: @checkedRoomCount/@totalRoomCount</p> *@ } else { diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor index e9d1421..1e7e065 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor @@ -29,6 +29,7 @@ private StateEventResponse<object>[] States { get; set; } = Array.Empty<StateEventResponse<object>>(); private List<Room> Rooms { get; set; } = new(); + private List<string> ServersInSpace { get; set; } = new(); protected override async Task OnInitializedAsync() { @@ -37,7 +38,7 @@ var state = await Room.GetStateAsync(""); if (state != null) { - Console.WriteLine(state.Value.ToJson()); + // Console.WriteLine(state.Value.ToJson()); States = state.Value.Deserialize<StateEventResponse<object>[]>()!; foreach (var stateEvent in States) @@ -52,6 +53,14 @@ Rooms.Add(room); } } + else if (stateEvent.Type == "m.room.member") + { + var serverName = stateEvent.StateKey.Split(':').Last(); + if (!ServersInSpace.Contains(serverName)) + { + ServersInSpace.Add(serverName); + } + } } // if(state.Value.TryGetProperty("Type", out var Type)) @@ -70,7 +79,7 @@ { foreach (var room in Rooms) { - room.JoinAsync(); + room.JoinAsync(ServersInSpace.ToArray()); } } diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor new file mode 100644 index 0000000..a8a7fc2 --- /dev/null +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor @@ -0,0 +1,59 @@ +@page "/RoomManager/Timeline/{RoomId}" +@using MatrixRoomUtils.Web.Shared.TimelineComponents +@using MatrixRoomUtils.Core.Extensions +<h3>RoomManagerTimeline</h3> +<hr/> +<p>Loaded @Events.Count events...</p> + +@foreach (var evt in Events) +{ + <div type="@evt.Type" key="@evt.StateKey" itemid="@evt.EventId"> + <DynamicComponent Type="@ComponentType(evt)" Parameters="@(new Dictionary<string, object> { { "Event", evt }, { "Events", Events } })"></DynamicComponent> + </div> +} + +@code { + + [Parameter] + public string RoomId { get; set; } = "invalid!!!!!!"; + + private List<MessagesResponse> Messages { get; set; } = new(); + private List<StateEventResponse> Events { get; set; } = new(); + + protected override async Task OnInitializedAsync() + { + await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); + RoomId = RoomId.Replace('~', '.'); + Console.WriteLine("RoomId: " + RoomId); + var room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId); + MessagesResponse? msgs = null; + do + { + msgs = await room.GetMessagesAsync(limit: 250, from: msgs?.End, dir: "b"); + Messages.Add(msgs); + Console.WriteLine($"Got {msgs.Chunk.Count} messages"); + msgs.Chunk.Reverse(); + Events.InsertRange(0, msgs.Chunk); + StateHasChanged(); + } while (msgs.End != null); + + + await base.OnInitializedAsync(); + } + + private StateEventResponse GetProfileEventBefore(StateEventResponse Event) => Events.TakeWhile(x => x != Event).Last(e => e.Type == "m.room.member" && e.StateKey == Event.Sender); + + + private Type ComponentType(StateEventResponse Event) => Event.Type switch { + "m.room.message" => typeof(TimelineMessageItem), + "m.room.member" => typeof(TimelineMemberItem), + _ => typeof(TimelineUnknownItem) + }; + + private Dictionary<string, object> ComponentParameters(Type ComponentType, StateEventResponse Event) => ComponentType switch { + Type t when t == typeof(TimelineMessageItem) => new Dictionary<string, object> { { "Event", Event }, { "Events", Events } }, + Type t when t == typeof(TimelineMemberItem) => new Dictionary<string, object> { { "Event", Event }, { "Events", Events } }, + _ => new Dictionary<string, object> { { "Event", Event }, { "Events", Events } } + }; + +} \ No newline at end of file |