diff --git a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs
index ca6345f..a519977 100644
--- a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs
+++ b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs
@@ -2,6 +2,7 @@ using System.Text.Json.Nodes;
using MatrixRoomUtils.Core;
using MatrixRoomUtils.Core.Responses;
using MatrixRoomUtils.Core.StateEventTypes;
+using MatrixRoomUtils.Core.StateEventTypes.Spec;
namespace MatrixRoomUtils.Web.Classes.RoomCreationTemplates;
@@ -9,7 +10,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate {
public string Name => "Default";
public CreateRoomRequest CreateRoomRequest =>
- new CreateRoomRequest {
+ new() {
Name = "My new room",
RoomAliasName = "myroom",
InitialState = new List<StateEvent> {
@@ -21,7 +22,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate {
},
new() {
Type = "m.room.guest_access",
- TypedContent = new GuestAccessData {
+ TypedContent = new GuestAccessEventData {
GuestAccess = "can_join"
}
},
@@ -47,7 +48,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate {
}
},
Visibility = "public",
- PowerLevelContentOverride = new PowerLevelEvent {
+ PowerLevelContentOverride = new PowerLevelEventData {
UsersDefault = 0,
EventsDefault = 100,
StateDefault = 50,
@@ -55,7 +56,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate {
Redact = 50,
Kick = 50,
Ban = 50,
- NotificationsPl = new PowerLevelEvent.NotificationsPL {
+ NotificationsPl = new PowerLevelEventData.NotificationsPL {
Room = 50
},
Events = new Dictionary<string, int> {
diff --git a/MatrixRoomUtils.Web/Classes/RoomInfo.cs b/MatrixRoomUtils.Web/Classes/RoomInfo.cs
new file mode 100644
index 0000000..711bf55
--- /dev/null
+++ b/MatrixRoomUtils.Web/Classes/RoomInfo.cs
@@ -0,0 +1,29 @@
+using MatrixRoomUtils.Core;
+using MatrixRoomUtils.Core.Responses;
+using MatrixRoomUtils.Core.RoomTypes;
+
+namespace MatrixRoomUtils.Web.Classes;
+
+public class RoomInfo {
+ public GenericRoom Room { get; set; }
+ public List<StateEventResponse?> StateEvents { get; } = new();
+
+ public async Task<StateEventResponse?> GetStateEvent(string type, string stateKey = "") {
+ var @event = StateEvents.FirstOrDefault(x => x.Type == type && x.StateKey == stateKey);
+ if (@event is not null) return @event;
+ @event = new StateEventResponse() {
+ RoomId = Room.RoomId,
+ Type = type,
+ StateKey = stateKey,
+ };
+ try {
+ @event.TypedContent = await Room.GetStateAsync<object>(type, stateKey);
+ }
+ catch (MatrixException e) {
+ if (e is { ErrorCode: "M_NOT_FOUND" }) @event.TypedContent = default!;
+ else throw;
+ }
+ StateEvents.Add(@event);
+ return @event;
+ }
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs b/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs
index 4a9c7d1..58466c7 100644
--- a/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs
+++ b/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs
@@ -1,7 +1,7 @@
using Blazored.SessionStorage;
using MatrixRoomUtils.Core.Interfaces.Services;
-namespace MatrixRoomUtils.Web;
+namespace MatrixRoomUtils.Web.Classes;
public class SessionStorageProviderService : IStorageProvider {
private readonly ISessionStorageService _sessionStorage;
diff --git a/MatrixRoomUtils.Web/Pages/ModalTest.razor b/MatrixRoomUtils.Web/Pages/ModalTest.razor
index f32c672..79c7fcd 100644
--- a/MatrixRoomUtils.Web/Pages/ModalTest.razor
+++ b/MatrixRoomUtils.Web/Pages/ModalTest.razor
@@ -16,7 +16,7 @@
@code {
- private Dictionary<int, WindowInfo> _windowInfos = new Dictionary<int, WindowInfo>();
+ private Dictionary<int, WindowInfo> _windowInfos = new();
private class WindowInfo {
public double X;
diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
deleted file mode 100644
index 4db2b5a..0000000
--- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
+++ /dev/null
@@ -1,107 +0,0 @@
-@page "/PolicyListEditor"
-@using System.Text.Json.Serialization
-@using MatrixRoomUtils.Core.Interfaces
-@using MatrixRoomUtils.Core.StateEventTypes
-@inject ILocalStorageService LocalStorage
-@inject NavigationManager NavigationManager
-<h3>Policy list editor - Room list</h3>
-<hr/>
-
-@if (PolicyRoomList.Count == 0) {
- <p>No policy rooms found.</p>
- <p>Loading progress: @checkedRoomCount/@totalRoomCount</p>
-}
-else {
- @if (checkedRoomCount != totalRoomCount) {
- <p>Loading progress: @checkedRoomCount/@totalRoomCount</p>
- }
- foreach (var s in PolicyRoomList) {
- <a style="color: unset; text-decoration: unset;" href="/PolicyListEditor/@s.RoomId.Replace('.', '~')">
- <RoomListItem RoomId="@s.RoomId">
- <br/>
- <span>Shortcode: @s.Shortcode</span>
- </RoomListItem>
- </a>
- @* <a href="@(NavigationManager.Uri + "/" + s.RoomId.Replace('.', '~'))">[@s.Shortcode] @s.Name (@s.RoomId)</a> *@
- @* <br/> *@
- }
-}
-
-<div style="margin-bottom: 4em;"></div>
-<LogView></LogView>
-
-@code {
- //get room list
- // - sync withroom list filter
- // Type = support.feline.msc3784
- //support.feline.policy.lists.msc.v1
-
- public List<PolicyRoomInfo> PolicyRoomList { get; set; } = new();
-
- private int checkedRoomCount { get; set; }
- private int totalRoomCount { get; set; }
-
- protected override async Task OnInitializedAsync() {
- await base.OnInitializedAsync();
- var hs = await MRUStorage.GetCurrentSessionOrNavigate();
- if (hs is null) return;
- await EnumeratePolicyRooms();
- Console.WriteLine("Policy list editor initialized!");
- }
-
- private async Task EnumeratePolicyRooms() {
- var hs = await MRUStorage.GetCurrentSession();
- var rooms = await hs.GetJoinedRooms();
- totalRoomCount = rooms.Count;
- StateHasChanged();
-
- var semaphore = new SemaphoreSlim(8);
- var tasks = new List<Task<PolicyRoomInfo?>>();
- foreach (var room in rooms) {
- tasks.Add(GetPolicyRoomInfo(room.RoomId, semaphore));
- }
- var results = await Task.WhenAll(tasks);
- PolicyRoomList.AddRange(results.Where(x => x is not null).Select(x => x.Value));
-
- Console.WriteLine($"Detected policy lists: {PolicyRoomList.ToJson()}");
- }
-
- private async Task<PolicyRoomInfo?> GetPolicyRoomInfo(string room, SemaphoreSlim semaphore) {
- try {
- await semaphore.WaitAsync();
- var hs = await MRUStorage.GetCurrentSession();
- PolicyRoomInfo roomInfo = new() {
- RoomId = room
- };
- var r = await hs.GetRoom(room);
- var shortcodeState = await r.GetStateAsync<MjolnirShortcodeEventData>("org.matrix.mjolnir.shortcode");
- roomInfo.Shortcode = shortcodeState.Shortcode;
-
- if (roomInfo.Shortcode is not null) {
- roomInfo.Name = await r.GetNameAsync();
- return roomInfo;
- }
-
- return null;
- }
- finally {
- checkedRoomCount++;
- StateHasChanged();
- semaphore.Release();
- }
- }
-
-
-
- public struct PolicyRoomInfo {
- public
- string RoomId { get; set; }
-
- public
- string? Shortcode { get; set; }
-
- public
- string? Name { get; set; }
- }
-
-}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor
deleted file mode 100644
index 087adf8..0000000
--- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor
+++ /dev/null
@@ -1,96 +0,0 @@
-@page "/RoomManager"
-@inject ILocalStorageService LocalStorage
-@inject NavigationManager NavigationManager
-<h3>Room manager</h3>
-<hr/>
-@if (Rooms.Count == 0) {
- <p>You are not in any rooms!</p>
-}
-else {
- <p>You are in @Rooms.Count rooms and @Spaces.Count spaces</p>
- <p>
- <a href="/RoomManagerCreateRoom">Create room</a>
- </p>
-
- <details open>
- <summary>Space List</summary>
- @foreach (var room in Spaces) {
- <a style="color: unset; text-decoration: unset;" href="/RoomManager/Space/@room.RoomId.Replace('.', '~')">
- <RoomListItem Room="@room" ShowOwnProfile="false"></RoomListItem>
- </a>
- }
- </details>
- <details open>
- <summary>Room List</summary>
- @foreach (var room in Rooms) {
- <a style="color: unset; text-decoration: unset;" href="/RoomManager/Room/@room.RoomId.Replace('.', '~')">
- <RoomListItem Room="@room" ShowOwnProfile="true"></RoomListItem>
- </a>
- }
- </details>
-}
-
-<div style="margin-bottom: 4em;"></div>
-<LogView></LogView>
-
-@code {
- public List<GenericRoom> Rooms { get; set; } = new();
- public List<GenericRoom> Spaces { get; set; } = new();
-
- protected override async Task OnInitializedAsync() {
- Console.WriteLine("Initializing room manager");
- Console.WriteLine("Loaded from local storage");
- await base.OnInitializedAsync();
- Console.WriteLine("Initialized base");
- var hs = await MRUStorage.GetCurrentSessionOrNavigate();
- if (hs is null) return;
- Console.WriteLine("Fetching joined rooms");
- var _rooms = await hs.GetJoinedRooms();
- StateHasChanged();
- Console.WriteLine($"Got {_rooms.Count} rooms");
- var semaphore = new SemaphoreSlim(10);
- var tasks = new List<Task<GenericRoom?>>();
- foreach (var room in _rooms) {
- tasks.Add(CheckIfSpace(room, semaphore));
- }
- await Task.WhenAll(tasks);
-
- Console.WriteLine("Fetched joined rooms!");
- }
-
- private async Task<GenericRoom?> CheckIfSpace(GenericRoom room, SemaphoreSlim semaphore) {
- await semaphore.WaitAsync();
- // Console.WriteLine($"Checking if {room.RoomId} is a space");
- try {
- var state = await room.GetStateAsync<CreateEvent>("m.room.create");
- if (state is not null) {
- //Console.WriteLine(state.Value.ToJson());
- if (state.Type is not null) {
- if (state.Type == "m.space") {
- Console.WriteLine($"Room {room.RoomId} is a space!");
- Spaces.Add(room);
- StateHasChanged();
- return room;
- }
- else {
- Console.WriteLine($"Encountered unknown room type {state.Type}");
- }
- }
- else {
- Rooms.Add(room);
- //this is fine, apprently...
- // Console.WriteLine($"Room {room.RoomId} has no Content.type in m.room.create!");
- }
- }
- }
- catch (Exception e) {
- Console.WriteLine(e);
- return null;
- }
- finally {
- semaphore.Release();
- }
- return null;
- }
-
-}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor
index e32b5cb..3225c15 100644
--- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor
@@ -14,13 +14,12 @@
@code {
[Parameter]
- public string RoomId { get; set; } = "invalid!!!!!!";
+ public string RoomId { get; set; }
private List<MessagesResponse> Messages { get; } = new();
private List<StateEventResponse> Events { get; } = new();
protected override async Task OnInitializedAsync() {
- RoomId = RoomId.Replace('~', '.');
Console.WriteLine("RoomId: " + RoomId);
var hs = await MRUStorage.GetCurrentSessionOrNavigate();
if (hs is null) return;
@@ -46,10 +45,10 @@
_ => 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 } }
+ private Dictionary<string, object> ComponentParameters(Type componentType, StateEventResponse @event) => componentType switch {
+ not null when componentType == typeof(TimelineMessageItem) => new Dictionary<string, object> { { "Event", @event }, { "Events", Events } },
+ not null when componentType == typeof(TimelineMemberItem) => new Dictionary<string, object> { { "Event", @event }, { "Events", Events } },
+ _ => new Dictionary<string, object> { { "Event", @event }, { "Events", Events } }
};
}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
index 932748d..d88d5b2 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
@@ -1,5 +1,6 @@
@page "/Rooms"
@using MatrixRoomUtils.Core.StateEventTypes
+@using MatrixRoomUtils.Core.StateEventTypes.Spec
<h3>Room list</h3>
@if (Rooms is not null) {
@@ -9,14 +10,14 @@
@code {
- private List<GenericRoom> Rooms { get; set; }
- private ProfileResponse GlobalProfile { get; set; }
-
+ private List<RoomInfo> Rooms { get; set; }
+ private ProfileResponseEventData GlobalProfile { get; set; }
+
protected override async Task OnInitializedAsync() {
var hs = await MRUStorage.GetCurrentSessionOrNavigate();
if (hs is null) return;
GlobalProfile = await hs.GetProfile(hs.WhoAmI.UserId);
- Rooms = await hs.GetJoinedRooms();
+ Rooms = (await hs.GetJoinedRooms()).Select(x => new RoomInfo() { Room = x }).ToList();
await base.OnInitializedAsync();
}
diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor
index 8e2609f..4cb16b8 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor
@@ -1,8 +1,9 @@
-@page "/PolicyListEditor/{RoomId}"
+@page "/Rooms/{RoomId}/Policies"
@using MatrixRoomUtils.Core.StateEventTypes
@using System.Text.Json
@using MatrixRoomUtils.Core.Helpers
@using MatrixRoomUtils.Core.Responses
+@using MatrixRoomUtils.Core.StateEventTypes.Spec
<h3>Policy list editor - Editing @RoomId</h3>
<hr/>
diff --git a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor
index a498c70..ffccc25 100644
--- a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor
+++ b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor
@@ -1,6 +1,7 @@
@using MatrixRoomUtils.Core.Responses
@using MatrixRoomUtils.Core.StateEventTypes
@using MatrixRoomUtils.Core.Helpers
+@using MatrixRoomUtils.Core.StateEventTypes.Spec
<div style="background-color: #ffffff11; border-radius: 0.5em; height: 1em; display: inline-block; vertical-align: middle;" alt="@UserId">
<img style="@(ChildContent is not null ? "vertical-align: baseline;" : "vertical-align: top;") width: 1em; height: 1em; border-radius: 50%;" src="@ProfileAvatar"/>
<span style="position: relative; top: -5px;">@ProfileName</span>
@@ -19,7 +20,7 @@
public RenderFragment? ChildContent { get; set; }
[Parameter]
- public ProfileResponse User { get; set; }
+ public ProfileResponseEventData User { get; set; }
[Parameter]
public string? UserId { get; set; }
diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor
index 7e002ed..db2d059 100644
--- a/MatrixRoomUtils.Web/Shared/RoomList.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomList.razor
@@ -1,5 +1,7 @@
@using MatrixRoomUtils.Web.Shared.RoomListComponents;
@using MatrixRoomUtils.Core.StateEventTypes
+@using MatrixRoomUtils.Core.StateEventTypes.Common
+@using MatrixRoomUtils.Core.StateEventTypes.Spec
<p>@Rooms.Count rooms total, @RoomsWithTypes.Sum(x=>x.Value.Count) fetched so far...</p>
@if(Rooms.Count != RoomsWithTypes.Sum(x=>x.Value.Count)) {
<p>Fetching more rooms...</p>
@@ -16,14 +18,14 @@ else {
@code {
[Parameter]
- public List<GenericRoom> Rooms { get; set; }
+ public List<RoomInfo> Rooms { get; set; }
[Parameter]
- public ProfileResponse? GlobalProfile { get; set; }
+ public ProfileResponseEventData? GlobalProfile { get; set; }
- Dictionary<string, List<GenericRoom>> RoomsWithTypes = new();
+ Dictionary<string, List<RoomInfo>> RoomsWithTypes = new();
protected override async Task OnInitializedAsync() {
- GlobalProfile ??= await (await MRUStorage.GetCurrentSession()!).GetProfile((await MRUStorage.GetCurrentSession()!).WhoAmI.UserId);
+ GlobalProfile ??= await (await MRUStorage.GetCurrentSession())!.GetProfile((await MRUStorage.GetCurrentSession())!.WhoAmI.UserId);
if (RoomsWithTypes.Any()) return;
var tasks = Rooms.Select(AddRoom);
@@ -35,35 +37,42 @@ else {
private string GetRoomTypeName(string? roomType) => roomType switch {
"m.space" => "Space",
"msc3588.stories.stories-room" => "Story room",
+ "support.feline.policy.lists.msc.v1" => "MSC3784 Policy list (v1)",
null => "Room",
_ => roomType
};
- private static SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(4, 4);
- private async Task AddRoom(GenericRoom room) {
+ private static SemaphoreSlim _semaphoreSlim = new(8, 8);
+ private async Task AddRoom(RoomInfo room) {
await _semaphoreSlim.WaitAsync();
string roomType;
try {
- var createEvent = await room.GetCreateEventAsync();
+ RoomCreateEventData createEvent = (await room.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventData;
roomType = GetRoomTypeName(createEvent.Type);
if (roomType == "Room") {
- var shortcodeState = await room.GetStateAsync<MjolnirShortcodeEventData>("org.matrix.mjolnir.shortcode");
- if (shortcodeState is not null) roomType = "Legacy policy room";
+ var mjolnirData = await room.GetStateEvent("org.matrix.mjolnir.shortcode");
+ if(mjolnirData?.RawContent?.ToJson(ignoreNull: true) is not null and not "{}")
+ roomType = "Legacy policy room";
}
+ //prefetch some stuff
+ await Task.WhenAll(
+ room.GetStateEvent("m.room.name"),
+ room.GetStateEvent("m.room.name")
+ );
}
catch (MatrixException e) {
roomType = $"Error: {e.ErrorCode}";
}
if (!RoomsWithTypes.ContainsKey(roomType)) {
- RoomsWithTypes.Add(roomType, new List<GenericRoom>());
+ RoomsWithTypes.Add(roomType, new List<RoomInfo>());
}
RoomsWithTypes[roomType].Add(room);
- // if (RoomsWithTypes.Count % 10 == 0)
- StateHasChanged();
+ // if (RoomsWithTypes[roomType].Count % 10 == 0)
+ StateHasChanged();
// await Task.Delay(100);
_semaphoreSlim.Release();
}
diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
index e860321..4be3c1f 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
@@ -1,12 +1,16 @@
@using MatrixRoomUtils.Core.StateEventTypes
+@using MatrixRoomUtils.Core.StateEventTypes.Spec
<details>
<summary>@roomType (@rooms.Count)</summary>
@foreach (var room in rooms) {
<div class="room-list-item">
- <RoomListItem Room="@room" ShowOwnProfile="@(roomType == "Room")"></RoomListItem>
- <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{room.RoomId}/Timeline")">View timeline</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton>
- <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{room.RoomId}/State/View")">View state</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton>
- <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{room.RoomId}/State/Edit")">Edit state</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton>
+ <RoomListItem RoomInfo="@room" ShowOwnProfile="@(roomType == "Room")"></RoomListItem>
+ @if (room.StateEvents.Any(x => x.Type == "m.room.create")) {
+
+ }
+ <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{room.Room.RoomId}/Timeline")">View timeline</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton>
+ <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/View")">View state</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton>
+ <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/Edit")">Edit state</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton>
@if (roomType == "Space") {
<RoomListSpace Space="@room"></RoomListSpace>
@@ -19,12 +23,12 @@
@code {
[Parameter]
- public KeyValuePair<string, List<GenericRoom>> Category { get; set; }
+ public KeyValuePair<string, List<RoomInfo>> Category { get; set; }
[Parameter]
- public ProfileResponse? GlobalProfile { get; set; }
+ public ProfileResponseEventData? GlobalProfile { get; set; }
private string roomType => Category.Key;
- private List<GenericRoom> rooms => Category.Value;
+ private List<RoomInfo> rooms => Category.Value;
}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor
index 73dc334..5153658 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor
@@ -1,4 +1,4 @@
-<LinkButton href="@($"/Rooms/{Space.RoomId}/Space")">Manage space</LinkButton>
+<LinkButton href="@($"/Rooms/{Space.Room.RoomId}/Space")">Manage space</LinkButton>
<br/>
<details @ontoggle="SpaceChildrenOpened">
@@ -14,23 +14,25 @@
@code {
[Parameter]
- public GenericRoom Space { get; set; }
+ public RoomInfo Space { get; set; }
[Parameter, CascadingParameter]
public string? Breadcrumbs {
- get => _breadcrumbs + Space.RoomId;
+ get => _breadcrumbs + Space.Room.RoomId;
set => _breadcrumbs = value;
}
- private List<GenericRoom> Children { get; set; } = new();
+ private List<RoomInfo> Children { get; set; } = new();
protected override async Task OnInitializedAsync() {
if (Breadcrumbs == null) throw new ArgumentNullException(nameof(Breadcrumbs));
await Task.Delay(Random.Shared.Next(1000, 10000));
- var rooms = Space.AsSpace.GetRoomsAsync();
+ var rooms = Space.Room.AsSpace.GetRoomsAsync();
await foreach (var room in rooms) {
- if(Breadcrumbs.Contains(room.RoomId)) continue;
- Children.Add(room);
+ if (Breadcrumbs.Contains(room.RoomId)) continue;
+ Children.Add(new() {
+ Room = room
+ });
}
await base.OnInitializedAsync();
}
@@ -41,7 +43,7 @@
private async Task SpaceChildrenOpened() {
if (_shouldRenderChildren) return;
_shouldRenderChildren = true;
- Console.WriteLine($"[RoomList] Rendering children of {Space.RoomId}");
+ Console.WriteLine($"[RoomList] Rendering children of {Space.Room.RoomId}");
}
}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
index 13cc02d..d35c9ab 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
@@ -2,6 +2,7 @@
@using System.Text.Json
@using MatrixRoomUtils.Core.Helpers
@using MatrixRoomUtils.Core.StateEventTypes
+@using MatrixRoomUtils.Core.StateEventTypes.Spec
<div class="roomListItem" id="@RoomId" style="background-color: #ffffff11; border-radius: 25px; margin: 8px; width: fit-Content; @(hasDangerousRoomVersion ? "border: red 4px solid;" : hasOldRoomVersion ? "border: #FF0 1px solid;" : "")">
@if (OwnMemberState != null) {
<img class="imageUnloaded @(string.IsNullOrWhiteSpace(OwnMemberState?.AvatarUrl ?? GlobalProfile?.AvatarUrl) ? "" : "imageLoaded")"
@@ -30,6 +31,9 @@
[Parameter]
public GenericRoom? Room { get; set; }
+
+ [Parameter]
+ public RoomInfo? RoomInfo { get; set; }
[Parameter]
public string? RoomId { get; set; }
@@ -40,8 +44,8 @@
[Parameter]
public RoomMemberEventData? OwnMemberState { get; set; }
- [Parameter]
- public ProfileResponse? GlobalProfile { get; set; }
+ [CascadingParameter]
+ public ProfileResponseEventData? GlobalProfile { get; set; }
private string? roomName { get; set; }
@@ -62,11 +66,19 @@
hs ??= await MRUStorage.GetCurrentSessionOrNavigate();
if (hs is null) return;
- if (Room is null && RoomId is null) {
+ if (Room is null && RoomId is null && RoomInfo is null) {
throw new ArgumentNullException(nameof(RoomId));
}
- Room ??= await hs.GetRoom(RoomId);
- RoomId = Room.RoomId;
+
+ // sweep from roominfo to id
+ if (RoomInfo is not null) Room = RoomInfo.Room;
+ if(Room is not null) RoomId = Room.RoomId;
+
+ //sweep from id to roominfo
+ if(RoomId is not null) Room ??= await hs.GetRoom(RoomId);
+ if(Room is not null) RoomInfo ??= new RoomInfo() {
+ Room = Room
+ };
await CheckRoomVersion();
await GetRoomInfo();
@@ -77,8 +89,8 @@
private async Task LoadOwnProfile() {
if (!ShowOwnProfile) return;
try {
- OwnMemberState ??= await Room.GetStateAsync<RoomMemberEventData>("m.room.member", hs.UserId);
- GlobalProfile ??= await hs.GetProfile(hs.UserId, true);
+ OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.UserId)).TypedContent as RoomMemberEventData;
+ GlobalProfile ??= await hs.GetProfile(hs.UserId);
}
catch (MatrixException e) {
if (e is { ErrorCode: "M_FORBIDDEN" }) {
@@ -93,7 +105,7 @@
private async Task CheckRoomVersion() {
try {
- var ce = await Room.GetCreateEventAsync();
+ var ce = (await RoomInfo.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventData;
if (int.TryParse(ce.RoomVersion, out var rv)) {
if (rv < 10)
hasOldRoomVersion = true;
@@ -115,9 +127,9 @@
private async Task GetRoomInfo() {
try {
- roomName ??= await Room.GetNameAsync();
+ roomName ??= ((await RoomInfo.GetStateEvent("m.room.name"))?.TypedContent as RoomNameEventData)?.Name ?? RoomId;
- var state = await Room.GetStateAsync<RoomAvatarEventData>("m.room.avatar");
+ var state = (await RoomInfo.GetStateEvent("m.room.avatar")).TypedContent as RoomAvatarEventData;
if (state?.Url is { } url) {
roomIcon = MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, url);
Console.WriteLine($"Got avatar for room {RoomId}: {roomIcon} ({url})");
diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor
index b7e0220..519e0b2 100644
--- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor
+++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor
@@ -1,5 +1,6 @@
@using MatrixRoomUtils.Core.Responses
@using MatrixRoomUtils.Core.StateEventTypes
+@using MatrixRoomUtils.Core.StateEventTypes.Spec
@if (roomMemberData.Membership == "ban") {
<i>@Event.StateKey was banned</i>
diff --git a/MatrixRoomUtils.Web/Shared/UserListItem.razor b/MatrixRoomUtils.Web/Shared/UserListItem.razor
index a41ce49..20b1c8c 100644
--- a/MatrixRoomUtils.Web/Shared/UserListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/UserListItem.razor
@@ -1,6 +1,7 @@
@using MatrixRoomUtils.Core.Responses
@using MatrixRoomUtils.Core.StateEventTypes
@using MatrixRoomUtils.Core.Helpers
+@using MatrixRoomUtils.Core.StateEventTypes.Spec
<div style="background-color: #ffffff11; border-radius: 25px; margin: 8px; width: fit-Content;">
<img style="@(ChildContent is not null ? "vertical-align: baseline;" : "") width: 32px; height: 32px; border-radius: 50%;" src="@profileAvatar"/>
<span style="vertical-align: middle; margin-right: 8px; border-radius: 75px;">@profileName</span>
@@ -19,7 +20,7 @@
public RenderFragment? ChildContent { get; set; }
[Parameter]
- public ProfileResponse User { get; set; }
+ public ProfileResponseEventData User { get; set; }
[Parameter]
public string UserId { get; set; }
|