diff options
author | Rory& <root@rory.gay> | 2024-03-22 17:47:29 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-03-22 17:47:29 +0100 |
commit | c69e5c790b2b277d9b11265b8f0883e9f90fe3b9 (patch) | |
tree | a2ad72230772d7459605ebc4ba13337e70d3bda4 /MatrixUtils.Web/Pages/Rooms | |
parent | Changes (diff) | |
download | MatrixUtils-c69e5c790b2b277d9b11265b8f0883e9f90fe3b9.tar.xz |
Changes
Diffstat (limited to 'MatrixUtils.Web/Pages/Rooms')
5 files changed, 85 insertions, 25 deletions
diff --git a/MatrixUtils.Web/Pages/Rooms/Index.razor b/MatrixUtils.Web/Pages/Rooms/Index.razor index c44e23f..28c4de2 100644 --- a/MatrixUtils.Web/Pages/Rooms/Index.razor +++ b/MatrixUtils.Web/Pages/Rooms/Index.razor @@ -13,8 +13,9 @@ <p>@Status2</p> <LinkButton href="/Rooms/Create">Create new room</LinkButton> - -<RoomList Rooms="Rooms" GlobalProfile="@GlobalProfile" @bind-StillFetching="RenderContents"></RoomList> +<CascadingValue TValue="AuthenticatedHomeserverGeneric" Value="Homeserver"> + <RoomList Rooms="Rooms" GlobalProfile="@GlobalProfile" @bind-StillFetching="RenderContents"></RoomList> +</CascadingValue> @code { @@ -73,10 +74,9 @@ // SemaphoreSlim _semaphore = new(160, 160); GlobalProfile = await Homeserver.GetProfileAsync(Homeserver.WhoAmI.UserId); - // var filter = await Homeserver.NamedCaches.FilterCache.GetOrSetValueAsync(CommonSyncFilters.GetBasicRoomInfo); var filter = await Homeserver.NamedCaches.FilterCache.GetOrSetValueAsync(CommonSyncFilters.GetBasicRoomInfo); var filterData = await Homeserver.GetFilterAsync(filter); - + // Rooms = new ObservableCollection<RoomInfo>(rooms.Select(room => new RoomInfo(room))); // foreach (var stateType in filterData.Room?.State?.Types ?? []) { // var tasks = Rooms.Select(async room => { @@ -204,7 +204,7 @@ if (sync is null) continue; var filter = await Homeserver.GetFilterAsync(syncHelper.FilterId); - + Status = $"Got sync with {sync.Rooms?.Join?.Count ?? 0} room updates, next batch: {sync.NextBatch}!"; if (sync?.Rooms?.Join != null) foreach (var joinedRoom in sync.Rooms.Join) diff --git a/MatrixUtils.Web/Pages/Rooms/Index2.razor b/MatrixUtils.Web/Pages/Rooms/Index2.razor index ae31126..98b8a1d 100644 --- a/MatrixUtils.Web/Pages/Rooms/Index2.razor +++ b/MatrixUtils.Web/Pages/Rooms/Index2.razor @@ -27,9 +27,11 @@ break; case Tab.DMs: <h3>DMs tab</h3> + <RoomsIndex2DMsTab></RoomsIndex2DMsTab> break; case Tab.ByRoomType: <h3>By room type tab</h3> + <RoomsIndex2ByRoomTypeTab></RoomsIndex2ByRoomTypeTab> break; default: throw new InvalidEnumArgumentException(); diff --git a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2ByRoomTypeTab.razor b/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2ByRoomTypeTab.razor new file mode 100644 index 0000000..f4cf849 --- /dev/null +++ b/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2ByRoomTypeTab.razor @@ -0,0 +1,53 @@ +@using MatrixUtils.Abstractions +@using System.Security.Cryptography +@using ArcaneLibs.Extensions +<h3>RoomsIndex2MainTab</h3> + +<div> + <div class="row"> + <div class="col-3" style="background-color: #ffffff66;"> + <LinkButton>Uncategorised rooms</LinkButton> + @foreach (var space in Data.Rooms.Where(x => x.RoomType == "m.space")) { + <div style="@("width: 100%; height: 50px; background-color: #" + RandomNumberGenerator.GetBytes(3).Append((byte)0x11).ToArray().AsHexString().Replace(" ",""))"> + <p>@space.RoomName</p> + </div> + } + </div> + <div class="col-9" style="background-color: #ff00ff66;"> + <p>omae wa mou shindeiru</p> + </div> + </div> +</div> + +@code { + + [CascadingParameter] + public Index2.RoomListViewData Data { get; set; } = null!; + + protected override async Task OnInitializedAsync() { + Data.Rooms.CollectionChanged += (sender, args) => { + DebouncedStateHasChanged(); + if (args.NewItems is { Count: > 0 }) + foreach (var newItem in args.NewItems) { + (newItem as RoomInfo).PropertyChanged += (sender, args) => { DebouncedStateHasChanged(); }; + } + }; + await base.OnInitializedAsync(); + } + + //debounce StateHasChanged, we dont want to reredner on every key stroke + + private CancellationTokenSource _debounceCts = new CancellationTokenSource(); + + private async Task DebouncedStateHasChanged() { + _debounceCts.Cancel(); + _debounceCts = new CancellationTokenSource(); + try { + await Task.Delay(100, _debounceCts.Token); + Console.WriteLine("DebouncedStateHasChanged - Calling StateHasChanged!"); + StateHasChanged(); + } + catch (TaskCanceledException) { } + } + +} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2SyncContainer.razor b/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2SyncContainer.razor index 1fb3f89..418ee02 100644 --- a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2SyncContainer.razor +++ b/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2SyncContainer.razor @@ -50,7 +50,6 @@ ["Main"] = new SyncHelper(Data.Homeserver, logger) { Timeout = 30000, FilterId = await Data.Homeserver.NamedCaches.FilterCache.GetOrSetValueAsync(CommonSyncFilters.GetBasicRoomInfo), - // FilterId = await Data.Homeserver.NamedCaches.FilterCache.GetOrSetValueAsync(CommonSyncFilters.GetBasicRoomInfo), // MinimumDelay = TimeSpan.FromMilliseconds(5000) } }; diff --git a/MatrixUtils.Web/Pages/Rooms/Timeline.razor b/MatrixUtils.Web/Pages/Rooms/Timeline.razor index 3886c5b..e6b1248 100644 --- a/MatrixUtils.Web/Pages/Rooms/Timeline.razor +++ b/MatrixUtils.Web/Pages/Rooms/Timeline.razor @@ -8,9 +8,9 @@ <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 }, { "Homeserver", Homeserver!} })"> + <div type="@evt.Event.Type" key="@evt.Event.StateKey" itemid="@evt.Event.EventId"> + <DynamicComponent Type="@evt.Type" + Parameters="@(new Dictionary<string, object> { { "Event", evt.Event }, { "Events", RawEvents }, { "Homeserver", Homeserver! } })"> </DynamicComponent> </div> } @@ -20,8 +20,8 @@ [Parameter] public string RoomId { get; set; } - private List<MessagesResponse> Messages { get; } = new(); - private List<StateEventResponse> Events { get; } = new(); + private List<TimelineEventItem> Events { get; } = new(); + private List<StateEventResponse> RawEvents { get; } = new(); private AuthenticatedHomeserverGeneric? Homeserver { get; set; } @@ -32,28 +32,34 @@ var room = Homeserver.GetRoom(RoomId); MessagesResponse? msgs = null; do { - msgs = await room.GetMessagesAsync(limit: 1000, from: msgs?.End, dir: "b"); - Messages.Add(msgs); + msgs = await room.GetMessagesAsync(limit: 10000, from: msgs?.End, dir: "b"); Console.WriteLine($"Got {msgs.Chunk.Count} messages"); + StateHasChanged(); msgs.Chunk.Reverse(); - Events.InsertRange(0, msgs.Chunk); + Events.InsertRange(0, msgs.Chunk.Select(x => new TimelineEventItem { Event = x, Type = ComponentType(x) })); + RawEvents.InsertRange(0, msgs.Chunk); } while (msgs.End is not 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 StateEventResponse GetProfileEventBefore(StateEventResponse Event) => Events.TakeWhile(x => x != Event).Last(e => e.Type == RoomMemberEventContent.EventId && e.StateKey == Event.Sender); - private Type ComponentType(StateEvent Event) => Event.TypedContent switch { - RoomCanonicalAliasEventContent => typeof(TimelineCanonicalAliasItem), - RoomHistoryVisibilityEventContent => typeof(TimelineHistoryVisibilityItem), - RoomTopicEventContent => typeof(TimelineRoomTopicItem), - RoomMemberEventContent => typeof(TimelineMemberItem), - RoomMessageEventContent => typeof(TimelineMessageItem), - RoomCreateEventContent => typeof(TimelineRoomCreateItem), - RoomNameEventContent => typeof(TimelineRoomNameItem), + private Type ComponentType(StateEvent Event) => Event.Type switch { + RoomCanonicalAliasEventContent.EventId => typeof(TimelineCanonicalAliasItem), + RoomHistoryVisibilityEventContent.EventId => typeof(TimelineHistoryVisibilityItem), + RoomTopicEventContent.EventId => typeof(TimelineRoomTopicItem), + RoomMemberEventContent.EventId => typeof(TimelineMemberItem), + RoomMessageEventContent.EventId => typeof(TimelineMessageItem), + RoomCreateEventContent.EventId => typeof(TimelineRoomCreateItem), + RoomNameEventContent.EventId => typeof(TimelineRoomNameItem), + // RoomMessageReactionEventContent.EventId => typeof(ComponentBase), _ => typeof(TimelineUnknownItem) }; + + private class TimelineEventItem : ComponentBase { + public StateEventResponse Event { get; set; } + public Type Type { get; set; } + } -} +} \ No newline at end of file |