RoomManagerSpace.razor (2346B)
1 @page "/RoomManager/Space/{RoomId}" 2 @using MatrixRoomUtils.Core.Extensions 3 @using System.Text.Json 4 <h3>Room manager - Viewing Space</h3> 5 6 <button onclick="@JoinAllRooms">Join all rooms</button> 7 @foreach (var room in Rooms) 8 { 9 <RoomListItem Room="room" ShowOwnProfile="true"></RoomListItem> 10 } 11 12 13 <br/> 14 <details style="background: #0002;"> 15 <summary style="background: #fff1;">State list</summary> 16 @foreach (var stateEvent in States.OrderBy(x => x.StateKey).ThenBy(x => x.Type)) 17 { 18 <p>@stateEvent.StateKey/@stateEvent.Type:</p> 19 <pre>@stateEvent.Content.ToJson()</pre> 20 } 21 </details> 22 23 @code { 24 25 [Parameter] 26 public string RoomId { get; set; } = "invalid!!!!!!"; 27 28 private Room? Room { get; set; } 29 30 private StateEventResponse<object>[] States { get; set; } = Array.Empty<StateEventResponse<object>>(); 31 private List<Room> Rooms { get; set; } = new(); 32 33 protected override async Task OnInitializedAsync() 34 { 35 await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); 36 Room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId.Replace('~', '.')); 37 var state = await Room.GetStateAsync(""); 38 if (state != null) 39 { 40 Console.WriteLine(state.Value.ToJson()); 41 States = state.Value.Deserialize<StateEventResponse<object>[]>()!; 42 43 foreach (var stateEvent in States) 44 { 45 if (stateEvent.Type == "m.space.child") 46 { 47 // if (stateEvent.Content.ToJson().Length < 5) return; 48 var roomId = stateEvent.StateKey; 49 var room = await RuntimeCache.CurrentHomeServer.GetRoom(roomId); 50 if (room != null) 51 { 52 Rooms.Add(room); 53 } 54 } 55 } 56 57 // if(state.Value.TryGetProperty("Type", out var Type)) 58 // { 59 // } 60 // else 61 // { 62 // //this is fine, apprently... 63 // //Console.WriteLine($"Room {room.RoomId} has no Content.Type in m.room.create!"); 64 // } 65 } 66 await base.OnInitializedAsync(); 67 } 68 69 private async Task JoinAllRooms() 70 { 71 foreach (var room in Rooms) 72 { 73 room.JoinAsync(); 74 } 75 } 76 77 }