blob: ca93fa619fd913f819196d83b6fdcc8fd59c4fc0 (
plain) (
blame)
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
|
@using MatrixRoomUtils.Web.Shared.RoomListComponents;
<p>@Rooms.Count rooms total, @RoomsWithTypes.Sum(x=>x.Value.Count) fetched so far...</p>
@foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) {
<RoomListCategory Category="@category"></RoomListCategory>
}
@code {
[Parameter]
public List<Room> Rooms { get; set; }
Dictionary<string, List<Room>> RoomsWithTypes = new();
protected override async Task OnInitializedAsync() {
if (RoomsWithTypes.Any()) return;
await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
var tasks = Rooms.Select(AddRoom);
await Task.WhenAll(tasks);
await base.OnInitializedAsync();
}
private string GetRoomTypeName(string? roomType) => roomType switch {
"m.space" => "Space",
"msc3588.stories.stories-room" => "Story room",
null => "Room",
_ => roomType
};
private static SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(8, 8);
private async Task AddRoom(Room room) {
await _semaphoreSlim.WaitAsync();
var roomType = GetRoomTypeName(await room.GetRoomType());
if (roomType == "Room") {
var shortcodeState = await room.GetStateAsync("org.matrix.mjolnir.shortcode");
if (shortcodeState.HasValue) roomType = "Legacy policy room";
}
if (!RoomsWithTypes.ContainsKey(roomType)) {
RoomsWithTypes.Add(roomType, new List<Room>());
}
RoomsWithTypes[roomType].Add(room);
// if (RoomsWithTypes.Count % 10 == 0)
StateHasChanged();
await Task.Delay(100);
_semaphoreSlim.Release();
}
private bool _isSpaceChildrenOpen = false;
}
|