about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Tools/InviteCounter.razor
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixUtils.Web/Pages/Tools/InviteCounter.razor')
-rw-r--r--MatrixUtils.Web/Pages/Tools/InviteCounter.razor73
1 files changed, 73 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Pages/Tools/InviteCounter.razor b/MatrixUtils.Web/Pages/Tools/InviteCounter.razor
new file mode 100644
index 0000000..8f4b4dd
--- /dev/null
+++ b/MatrixUtils.Web/Pages/Tools/InviteCounter.razor
@@ -0,0 +1,73 @@
+@page "/Tools/InviteCounter"
+@using ArcaneLibs.Extensions
+@using LibMatrix.RoomTypes
+@using System.Collections.ObjectModel
+@using LibMatrix
+@using System.Collections.Frozen
+@using LibMatrix.EventTypes.Spec.State
+@using MatrixUtils.Abstractions
+<h3>User Trace</h3>
+<hr/>
+
+<br/>
+<span>Room ID: </span>
+<InputText @bind-Value="@roomId"></InputText>
+<LinkButton OnClick="@Execute">Execute</LinkButton>
+
+<br/>
+
+<details>
+    <summary>Results</summary>
+    @foreach (var (userId, events) in invites.OrderByDescending(x=>x.Value).ToList()) {
+        <p>@userId: @events</p>
+    }
+</details>
+
+<br/>
+@foreach (var line in log.Reverse()) {
+    <pre>@line</pre>
+}
+
+@code {
+    private ObservableCollection<string> log { get; set; } = new();
+    private Dictionary<string, int> invites { get; set; } = new();
+    private AuthenticatedHomeserverGeneric hs { get; set; }
+    
+    [Parameter, SupplyParameterFromQuery(Name = "room")]
+    public string roomId { get; set; }
+    
+
+    protected override async Task OnInitializedAsync() {
+        log.CollectionChanged += (sender, args) => StateHasChanged();
+        hs = await RMUStorage.GetCurrentSessionOrNavigate();
+        if (hs is null) return;
+       
+        StateHasChanged();
+        Console.WriteLine("Rerendered!");
+        await base.OnInitializedAsync();
+    }
+
+    private async Task<string> Execute() {
+        var room = hs.GetRoom(roomId);
+        var events = room.GetManyMessagesAsync(limit: int.MaxValue);
+        await foreach (var resp in events) {
+            var all = resp.State.Concat(resp.Chunk);
+            foreach (var evt in all) {
+                if(evt.Type != RoomMemberEventContent.EventId) continue;
+                var content = evt.TypedContent as RoomMemberEventContent;
+                if(content.Membership != "invite") continue;
+                if(!invites.ContainsKey(evt.Sender)) invites[evt.Sender] = 0;
+                invites[evt.Sender]++;
+            }
+
+            log.Add($"{resp.State.Count} state, {resp.Chunk.Count} timeline");
+        }
+        
+        
+        
+        StateHasChanged();
+
+        return "";
+    }
+
+}
\ No newline at end of file