@page "/Rooms/{RoomId}/Timeline"
@using MatrixRoomUtils.Web.Shared.TimelineComponents
@using LibMatrix
@using LibMatrix.Homeservers
@using LibMatrix.Responses
@using LibMatrix.StateEventTypes.Spec
RoomManagerTimeline
Loaded @Events.Count events...
@foreach (var evt in Events) {
}
@code {
[Parameter]
public string RoomId { get; set; }
private List Messages { get; } = new();
private List Events { get; } = new();
private AuthenticatedHomeserverGeneric? HomeServer { get; set; }
protected override async Task OnInitializedAsync() {
Console.WriteLine("RoomId: " + RoomId);
HomeServer = await MRUStorage.GetCurrentSessionOrNavigate();
if (HomeServer is null) return;
var room = await HomeServer.GetRoom(RoomId);
MessagesResponse? msgs = null;
do {
msgs = await room.GetMessagesAsync(limit: 1000, from: msgs?.End, dir: "b");
Messages.Add(msgs);
Console.WriteLine($"Got {msgs.Chunk.Count} messages");
msgs.Chunk.Reverse();
Events.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 Type ComponentType(StateEvent Event) => Event.TypedContent switch {
RoomMessageEventContent => typeof(TimelineMessageItem),
RoomMemberEventContent => typeof(TimelineMemberItem),
RoomCreateEventContent => typeof(TimelineRoomCreateItem),
_ => typeof(TimelineUnknownItem)
};
}