about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web/Pages')
-rw-r--r--MatrixRoomUtils.Web/Pages/DevOptions.razor7
-rw-r--r--MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor86
-rw-r--r--MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor2
-rw-r--r--MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor1
-rw-r--r--MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor13
-rw-r--r--MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor59
6 files changed, 163 insertions, 5 deletions
diff --git a/MatrixRoomUtils.Web/Pages/DevOptions.razor b/MatrixRoomUtils.Web/Pages/DevOptions.razor
index c2894b3..3ca86b4 100644
--- a/MatrixRoomUtils.Web/Pages/DevOptions.razor
+++ b/MatrixRoomUtils.Web/Pages/DevOptions.razor
@@ -59,7 +59,12 @@
 
     protected async Task DropCaches()
     {
-        RuntimeCache.GenericResponseCache.Clear();
+        foreach (var (key, value) in RuntimeCache.GenericResponseCache)
+        {
+            value.Cache.Clear();
+        }
+        
+        //RuntimeCache.GenericResponseCache.Clear();
         RuntimeCache.HomeserverResolutionCache.Clear();
         await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage);
     }
diff --git a/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor
new file mode 100644
index 0000000..109ad7d
--- /dev/null
+++ b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor
@@ -0,0 +1,86 @@
+@page "/RoomQuery"
+@using MatrixRoomUtils.Core.Extensions
+@using System.Runtime.InteropServices
+@using System.ComponentModel
+@using MatrixRoomUtils.Core.Responses.Admin
+<h3>Homeserver Administration - Room Query</h3>
+
+<label>Search name: </label>
+<InputText @bind-Value="SearchTerm" /><br/>
+<label>Search id/name/creator (slow!): </label>
+<InputText @bind-Value="ContentSearchTerm" /><br/>
+<label>Order by: </label>
+<select @bind="OrderBy">
+    @foreach (var item in validOrderBy)
+    {
+        <option value="@item.Key">@item.Value</option>
+    }
+</select><br/>
+<label>Ascending: </label>
+<InputCheckbox @bind-Value="Ascending" /><br/>
+<button class="btn btn-primary" @onclick="Search">Search</button>
+<br/>
+
+@foreach (var res in Results)
+{
+    <div style="background-color: #ffffff11; border-radius: 0.5em; display: block; margin-top: 4px; padding: 4px;">
+        <RoomListItem RoomId="@res.RoomId"></RoomListItem> 
+        <p>@res.CanonicalAlias, created by <InlineUserItem UserId="@res.Creator"></InlineUserItem></p>
+        <p>@res.StateEvents state events</p>
+        <p>@res.JoinedMembers members, of which @res.JoinedLocalMembers are on this server</p>
+    </div>
+}
+
+@code {
+    
+    [Parameter, SupplyParameterFromQuery(Name = "order_by")]
+    public string? OrderBy { get; set; }
+    
+    [Parameter, SupplyParameterFromQuery(Name = "search_term")]
+    public string SearchTerm { get; set; }
+    
+    [Parameter, SupplyParameterFromQuery(Name = "content_search_term")]
+    public string ContentSearchTerm { get; set; }
+    
+    [Parameter, SupplyParameterFromQuery(Name = "ascending")]
+    public bool Ascending { get; set; }
+
+    public List<AdminRoomListingResult.AdminRoomListingResultRoom> Results { get; set; } = new();
+    
+    protected override async Task OnParametersSetAsync()
+    {
+        if(Ascending == null)
+            Ascending = true;
+        OrderBy ??= "name";
+    }
+    
+    private async Task Search()
+    {
+        Results.Clear();
+        var searchRooms = RuntimeCache.CurrentHomeServer.Admin.SearchRoomsAsync(orderBy: OrderBy!, dir: Ascending ? "f" : "b", searchTerm: SearchTerm, contentSearch: ContentSearchTerm).GetAsyncEnumerator();
+        while (await searchRooms.MoveNextAsync())
+        {
+            var room = searchRooms.Current;
+            Console.WriteLine("Hit: " + room.ToJson(indent: false));
+            Results.Add(room);
+        }
+    }
+
+    private Dictionary<string, string> validOrderBy = new Dictionary<string, string>()
+    {
+        { "name", "Room name" },
+        { "canonical_alias", "Main alias address" },
+        { "joined_members", "Number of members (reversed)" },
+        { "joined_local_members", "Number of local members (reversed)" },
+        { "version", "Room version" },
+        { "creator", "Creator of the room" },
+        { "encryption", "End-to-end encryption algorithm" },
+        { "federatable", "Is room federated" },
+        { "public", "Visibility in room list" },
+        { "join_rules", "Join rules" },
+        { "guest_access", "Guest access" },
+        { "history_visibility", "Visibility of history" },
+        { "state_events", "Number of state events" },
+    };
+
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
index 4b9c2f6..bf03ee3 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
+++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
@@ -200,7 +200,7 @@ else
     
     private bool _enableAvatars = false;
     
-    static Dictionary<string, string> avatars = new Dictionary<string, string>();
+    static Dictionary<string, string?> avatars = new Dictionary<string, string?>();
     static Dictionary<string, RemoteHomeServer> servers = new Dictionary<string, RemoteHomeServer>();
 
     public static List<StateEventResponse<PolicyRuleStateEventData>> PolicyEvents { get; set; } = new();
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor
index a8b8fd4..5daa97c 100644
--- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor
@@ -6,7 +6,6 @@
 @if (Rooms.Count == 0)
 {
     <p>You are not in any rooms!</p>
-    @* <p>Loading progress: @checkedRoomCount/@totalRoomCount</p> *@
 }
 else
 {
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor
index e9d1421..1e7e065 100644
--- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor
@@ -29,6 +29,7 @@
     
     private StateEventResponse<object>[] States { get; set; } = Array.Empty<StateEventResponse<object>>();
     private List<Room> Rooms { get; set; } = new();
+    private List<string> ServersInSpace { get; set; } = new();
     
     protected override async Task OnInitializedAsync()
     {
@@ -37,7 +38,7 @@
         var state = await Room.GetStateAsync("");
         if (state != null)
         {
-            Console.WriteLine(state.Value.ToJson());
+            // Console.WriteLine(state.Value.ToJson());
             States = state.Value.Deserialize<StateEventResponse<object>[]>()!;
             
             foreach (var stateEvent in States)
@@ -52,6 +53,14 @@
                         Rooms.Add(room);
                     }
                 }
+                else if (stateEvent.Type == "m.room.member")
+                {
+                    var serverName = stateEvent.StateKey.Split(':').Last();
+                    if (!ServersInSpace.Contains(serverName))
+                    {
+                        ServersInSpace.Add(serverName);
+                    }
+                }
             }
             
         // if(state.Value.TryGetProperty("Type", out var Type))
@@ -70,7 +79,7 @@
     {
         foreach (var room in Rooms)
         {
-            room.JoinAsync();
+            room.JoinAsync(ServersInSpace.ToArray());
         }
     }
 
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor
new file mode 100644
index 0000000..a8a7fc2
--- /dev/null
+++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor
@@ -0,0 +1,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 } }
+        };
+
+}
\ No newline at end of file