about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Tools/Moderation/InviteCounter.razor
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-05-14 17:49:09 +0200
committerRory& <root@rory.gay>2024-05-14 17:49:09 +0200
commit41c5a84dacfd036b8d8f01f72226ac5a519995e3 (patch)
treea4bfc76541692cbbb0fc18f34463cf31a57440f5 /MatrixUtils.Web/Pages/Tools/Moderation/InviteCounter.razor
parentImprove the heatmap layout (diff)
downloadMatrixUtils-41c5a84dacfd036b8d8f01f72226ac5a519995e3.tar.xz
Organise tools somewhat, set proper icons for nav menu
Diffstat (limited to 'MatrixUtils.Web/Pages/Tools/Moderation/InviteCounter.razor')
-rw-r--r--MatrixUtils.Web/Pages/Tools/Moderation/InviteCounter.razor68
1 files changed, 68 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Pages/Tools/Moderation/InviteCounter.razor b/MatrixUtils.Web/Pages/Tools/Moderation/InviteCounter.razor
new file mode 100644

index 0000000..2123d4d --- /dev/null +++ b/MatrixUtils.Web/Pages/Tools/Moderation/InviteCounter.razor
@@ -0,0 +1,68 @@ +@page "/Tools/Moderation/InviteCounter" +@using System.Collections.ObjectModel +@using LibMatrix.EventTypes.Spec.State +<h3>Invite counter</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