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/RoomManagerTimeline.razor | |
parent | unknown changes (diff) | |
download | MatrixUtils-fc749b3e57098740377e6eabd5d010d133256fa5.tar.xz |
Improved many features
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor')
-rw-r--r-- | MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor | 59 |
1 files changed, 59 insertions, 0 deletions
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 |