1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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 } }
};
}
|