diff --git a/MatrixRoomUtils.Web/Pages/DataExportPage.razor b/MatrixRoomUtils.Web/Pages/DataExportPage.razor
index 6e1b5ec..58e4111 100644
--- a/MatrixRoomUtils.Web/Pages/DataExportPage.razor
+++ b/MatrixRoomUtils.Web/Pages/DataExportPage.razor
@@ -15,7 +15,7 @@
{
@foreach (var (token, user) in RuntimeCache.LoginSessions)
{
- <IndexUserItem User="@user"/>
+ @* <IndexUserItem User="@user"/> *@
<pre>
@user.LoginResponse.UserId[1..].Split(":")[0]\auth\access_token=@token
@user.LoginResponse.UserId[1..].Split(":")[0]\auth\device_id=@user.LoginResponse.DeviceId
@@ -45,32 +45,31 @@ else
if (!RuntimeCache.WasLoaded)
{
await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
-
- var homeservers = RuntimeCache.LoginSessions.Values.Select(x => x.LoginResponse.HomeServer).Distinct();
- totalHomeservers = homeservers.Count();
- StateHasChanged();
- foreach (var hs in homeservers)
+ }
+ var homeservers = RuntimeCache.LoginSessions.Values.Select(x => x.LoginResponse.HomeServer).Distinct();
+ totalHomeservers = homeservers.Count();
+ StateHasChanged();
+ foreach (var hs in homeservers)
+ {
+ if (RuntimeCache.HomeserverResolutionCache.ContainsKey(hs))
{
- if (RuntimeCache.HomeserverResolutionCache.ContainsKey(hs))
- {
- resolvedHomeservers++;
- continue;
- }
- var resolvedHomeserver = (await new RemoteHomeServer(hs).Configure()).FullHomeServerDomain;
-
- RuntimeCache.HomeserverResolutionCache.Add(hs, new() { Result = resolvedHomeserver, ResolutionTime = DateTime.Now });
- await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
-
- Console.WriteLine("Saved to local storage:");
- Console.WriteLine(JsonSerializer.Serialize(RuntimeCache.HomeserverResolutionCache, new JsonSerializerOptions()
- {
- WriteIndented = true
- }));
resolvedHomeservers++;
- StateHasChanged();
+ continue;
}
+ var resolvedHomeserver = (await new RemoteHomeServer(hs).Configure()).FullHomeServerDomain;
+
+ RuntimeCache.HomeserverResolutionCache.Add(hs, new() { Result = resolvedHomeserver, ResolutionTime = DateTime.Now });
+ await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
+
+ Console.WriteLine("Saved to local storage:");
+ Console.WriteLine(JsonSerializer.Serialize(RuntimeCache.HomeserverResolutionCache, new JsonSerializerOptions()
+ {
+ WriteIndented = true
+ }));
+ resolvedHomeservers++;
StateHasChanged();
}
+ StateHasChanged();
_isLoaded = true;
}
diff --git a/MatrixRoomUtils.Web/Pages/DebugTools.razor b/MatrixRoomUtils.Web/Pages/DebugTools.razor
index ffa2134..c8fabaa 100644
--- a/MatrixRoomUtils.Web/Pages/DebugTools.razor
+++ b/MatrixRoomUtils.Web/Pages/DebugTools.razor
@@ -40,7 +40,7 @@ else
public List<string> Rooms { get; set; } = new();
protected override async Task OnInitializedAsync()
{
- if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
if (RuntimeCache.CurrentHomeServer == null)
{
diff --git a/MatrixRoomUtils.Web/Pages/DevOptions.razor b/MatrixRoomUtils.Web/Pages/DevOptions.razor
index e1b6ac0..9ade1b8 100644
--- a/MatrixRoomUtils.Web/Pages/DevOptions.razor
+++ b/MatrixRoomUtils.Web/Pages/DevOptions.razor
@@ -23,7 +23,6 @@
{
<li>
@item.Key: @item.Value.Cache.Count entries<br/>
- Default expiry: @item.Value.DefaultExpiry<br/>
@if (item.Value.Cache.Count > 0)
{
<p>Earliest expiry: @(item.Value.Cache.Min(x => x.Value.ExpiryTime)) (@string.Format("{0:g}", item.Value.Cache.Min(x => x.Value.ExpiryTime).Value.Subtract(DateTime.Now)) from now)</p>
@@ -45,7 +44,7 @@
{
while (true)
{
- await Task.Delay(100);
+ await Task.Delay(1000);
StateHasChanged();
}
});
diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor
index 7be4149..8be8570 100644
--- a/MatrixRoomUtils.Web/Pages/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Index.razor
@@ -9,7 +9,7 @@
Small collection of tools to do not-so-everyday things.
<br/><br/>
-<h5>Signed in accounts - <a href="/Login">Add new account</a> or <a href="/ImportUsers">Import from TSV</a></h5>
+<h5>Signed in accounts - <a href="/Login">Add new account</a></h5>
<hr/>
<form>
@foreach (var (token, user) in RuntimeCache.LoginSessions)
diff --git a/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor b/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor
index 882dd1e..13b717d 100644
--- a/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor
+++ b/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor
@@ -84,8 +84,8 @@ else
await semaphore.WaitAsync();
progress.ProcessedUsers.Add(room, new());
Console.WriteLine($"Fetching states for room ({rooms.IndexOf(room)}/{rooms.Count}) ({room.RoomId})");
- var states = (await room.GetStateAsync("")).Value.Deserialize<List<StateEvent>>();
- states.RemoveAll(x => x.type != "m.room.member" || x.content.GetProperty("membership").GetString() != "join");
+ var states = (await room.GetStateAsync("")).Value.Deserialize<List<StateEventResponse>>();
+ states.RemoveAll(x => x.Type != "m.room.member" || x.Content.GetProperty("membership").GetString() != "join");
Console.WriteLine($"Room {room.RoomId} has {states.Count} members");
if (states.Count > memberLimit)
{
@@ -119,13 +119,13 @@ else
{
progress.ProcessedUsers[room].Slowmode = false;
}
- if (!homeServers.Any(x => x.Server == state.state_key.Split(':')[1]))
+ if (!homeServers.Any(x => x.Server == state.StateKey.Split(':')[1]))
{
- homeServers.Add(new HomeServerInfo() { Server = state.state_key.Split(':')[1] });
+ homeServers.Add(new HomeServerInfo() { Server = state.StateKey.Split(':')[1] });
}
- var hs = homeServers.First(x => x.Server == state.state_key.Split(':')[1]);
- if (!hs.KnownUsers.Contains(state.state_key.Split(':')[0]))
- hs.KnownUsers.Add(state.state_key.Split(':')[0]);
+ var hs = homeServers.First(x => x.Server == state.StateKey.Split(':')[1]);
+ if (!hs.KnownUsers.Contains(state.StateKey.Split(':')[0]))
+ hs.KnownUsers.Add(state.StateKey.Split(':')[0]);
if (++progress.ProcessedUsers[room].Processed % updateInterval == 0 && progressCallback != null)
{
await semLock.WaitAsync();
diff --git a/MatrixRoomUtils.Web/Pages/LoginPage.razor b/MatrixRoomUtils.Web/Pages/LoginPage.razor
index c986d40..9fcedd1 100644
--- a/MatrixRoomUtils.Web/Pages/LoginPage.razor
+++ b/MatrixRoomUtils.Web/Pages/LoginPage.razor
@@ -1,42 +1,123 @@
@page "/Login"
+@using System.Text.Json
@using MatrixRoomUtils.Core.Authentication
@inject ILocalStorageService LocalStorage
+@inject IJSRuntime JsRuntime
<h3>Login</h3>
+<hr/>
-<label>Homeserver:</label>
-<input @bind="homeserver"/>
-<br/>
-<label>Username:</label>
-<input @bind="username"/>
+<span>
+ <label>@@</label>
+ @if (inputVisible.username)
+ {
+ <input autofocus @bind="newRecordInput.username" @onfocusout="() => inputVisible.username = false" @ref="elementToFocus"/>
+ }
+ else
+ {
+ <span tabindex="0" style="border-bottom: #ccc solid 1px; min-width: 50px; display: inline-block; height: 1.4em;" @onfocusin="() => inputVisible.username = true">@newRecordInput.username</span>
+ }
+ <label>:</label>
+ @if (inputVisible.homeserver)
+ {
+ <input autofocus @bind="newRecordInput.homeserver" @onfocusout="() => inputVisible.homeserver = false" @ref="elementToFocus"/>
+ }
+ else
+ {
+ <span tabindex="0" style="border-bottom: #ccc solid 1px; min-width: 50px; display: inline-block; margin-left: 2px; height: 1.4em;" @onfocusin="() => inputVisible.homeserver = true">@newRecordInput.homeserver</span>
+ }
+</span>
+<span style="display: block;">
+ <label>Password:</label>
+ @if (inputVisible.password)
+ {
+ <input autofocus="true" @bind="newRecordInput.password" @onfocusout="() => inputVisible.password = false" @ref="elementToFocus" type="password"/>
+ }
+ else
+ {
+ <span tabindex="0" style="border-bottom: #ccc solid 1px; min-width: 50px; display: inline-block; height: 1.4em;" @onfocusin="() => inputVisible.password = true">@string.Join("", newRecordInput.password.Select(x => '*'))</span>
+ }
+</span>
+<button @onclick="AddRecord">Add account to queue</button>
<br/>
-<label>Password:</label>
-<input @bind="password" type="password"/>
+
+<InputFile OnChange="@FileChanged" accept=".tsv"></InputFile>
<br/>
<button @onclick="Login">Login</button>
+<br/><br/>
+<h4>Parsed records</h4>
+<hr/>
+<table border="1">
+ @foreach (var (homeserver, username, password) in records)
+ {
+ <tr style="background-color: @(RuntimeCache.LoginSessions.Any(x => x.Value.LoginResponse.UserId == $"@{username}:{homeserver}") ? "green" : "unset")">
+ <td style="border-width: 1px;">@username</td>
+ <td style="border-width: 1px;">@homeserver</td>
+ <td style="border-width: 1px;">@password.Length chars</td>
+ </tr>
+ }
+</table>
<br/>
<br/>
<LogView></LogView>
@code {
- string homeserver = "";
- string username = "";
- string password = "";
+ List<(string homeserver, string username, string password)> records = new();
+ (string homeserver, string username, string password) newRecordInput = ("", "", "");
+ (bool homeserver, bool username, bool password) inputVisible = (false, false, false);
async Task Login()
{
- var result = await MatrixAuth.Login(homeserver, username, password);
- Console.WriteLine($"Obtained access token for {result.UserId}!");
+ foreach (var (homeserver, username, password) in records)
+ {
+ if (RuntimeCache.LoginSessions.Any(x => x.Value.LoginResponse.UserId == $"@{username}:{homeserver}")) continue;
+ var result = await MatrixAuth.Login(homeserver, username, password);
+ Console.WriteLine($"Obtained access token for {result.UserId}!");
- RuntimeCache.LastUsedToken = result.AccessToken;
+ var userinfo = new UserInfo()
+ {
+ LoginResponse = result
+ };
+ userinfo.Profile = await (await new AuthenticatedHomeServer(result.UserId, result.AccessToken, result.HomeServer).Configure()).GetProfile(result.UserId);
+ RuntimeCache.LastUsedToken = result.AccessToken;
- var userinfo = new UserInfo()
- {
- LoginResponse = result,
- Profile = await (await new RemoteHomeServer(result.HomeServer).Configure()).GetProfile(result.UserId)
- };
- RuntimeCache.LoginSessions.Add(userinfo.AccessToken, userinfo);
+ RuntimeCache.LoginSessions.Add(result.AccessToken, userinfo);
+ StateHasChanged();
+ }
await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
}
+ private async Task FileChanged(InputFileChangeEventArgs obj)
+ {
+ Console.WriteLine(JsonSerializer.Serialize(obj, new JsonSerializerOptions()
+ {
+ WriteIndented = true
+ }));
+ await using var rs = obj.File.OpenReadStream();
+ using var sr = new StreamReader(rs);
+ string TsvData = await sr.ReadToEndAsync();
+ records.Clear();
+ foreach (var line in TsvData.Split('\n'))
+ {
+ var parts = line.Split('\t');
+ if (parts.Length != 3)
+ continue;
+ records.Add((parts[0], parts[1], parts[2]));
+ }
+ }
+
+
+ private ElementReference elementToFocus;
+
+ protected override async Task OnAfterRenderAsync(bool firstRender)
+ {
+ await JsRuntime.InvokeVoidAsync("BlazorFocusElement", elementToFocus);
+ }
+
+ private void AddRecord()
+ {
+ records.Add(newRecordInput);
+ newRecordInput = ("", "", "");
+ }
+
}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
index d0f9b87..08cdc2c 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
+++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor
@@ -8,13 +8,14 @@
<hr/>
<p>
- This policy list contains @PolicyEvents.Count(x => x.type == "m.policy.rule.server") server bans,
- @PolicyEvents.Count(x => x.type == "m.policy.rule.room") room bans and
- @PolicyEvents.Count(x => x.type == "m.policy.rule.user") user bans.
+ This policy list contains @PolicyEvents.Count(x => x.Type == "m.policy.rule.server") server bans,
+ @PolicyEvents.Count(x => x.Type == "m.policy.rule.room") room bans and
+ @PolicyEvents.Count(x => x.Type == "m.policy.rule.user") user bans.
</p>
+<InputCheckbox @bind-Value="_enableAvatars" @oninput="GetAllAvatars"></InputCheckbox><label>Enable avatars (WILL EXPOSE YOUR IP TO TARGET HOMESERVERS!)</label>
-@if (!PolicyEvents.Any(x => x.type == "m.policy.rule.server"))
+@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.server"))
{
<p>No server policies</p>
}
@@ -22,7 +23,7 @@ else
{
<h3>Server policies</h3>
<hr/>
- <table class="table table-striped table-hover" style="width: fit-content;">
+ <table class="table table-striped table-hover" style="width: fit-Content;">
<thead>
<tr>
<th scope="col" style="max-width: 50vw;">Server</th>
@@ -32,10 +33,10 @@ else
</tr>
</thead>
<tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.server" && x.content.Entity != null))
+ @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && x.content.Entity != null))
{
<tr>
- <td>Entity: @policyEvent.content.Entity<br/>State: @policyEvent.state_key</td>
+ <td>Entity: @policyEvent.content.Entity<br/>State: @policyEvent.StateKey</td>
<td>@policyEvent.content.Reason</td>
<td>
@policyEvent.content.ExpiryDateTime
@@ -50,18 +51,18 @@ else
</table>
<details>
<summary>Invalid events</summary>
- <table class="table table-striped table-hover" style="width: fit-content;">
+ <table class="table table-striped table-hover" style="width: fit-Content;">
<thead>
<tr>
<th scope="col" style="max-width: 50vw;">State key</th>
- <th scope="col">Serialised contents</th>
+ <th scope="col">Serialised Contents</th>
</tr>
</thead>
<tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.server" && x.content.Entity == null))
+ @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && x.content.Entity == null))
{
<tr>
- <td>@policyEvent.state_key</td>
+ <td>@policyEvent.StateKey</td>
<td>@policyEvent.content.ToJson(indent: false, ignoreNull: true)</td>
</tr>
}
@@ -69,7 +70,7 @@ else
</table>
</details>
}
-@if (!PolicyEvents.Any(x => x.type == "m.policy.rule.room"))
+@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.room"))
{
<p>No room policies</p>
}
@@ -77,7 +78,7 @@ else
{
<h3>Room policies</h3>
<hr/>
- <table class="table table-striped table-hover" style="width: fit-content;">
+ <table class="table table-striped table-hover" style="width: fit-Content;">
<thead>
<tr>
<th scope="col" style="max-width: 50vw;">Room</th>
@@ -87,10 +88,10 @@ else
</tr>
</thead>
<tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.room" && x.content.Entity != null))
+ @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && x.content.Entity != null))
{
<tr>
- <td>Entity: @policyEvent.content.Entity<br/>State: @policyEvent.state_key</td>
+ <td>Entity: @policyEvent.content.Entity<br/>State: @policyEvent.StateKey</td>
<td>@policyEvent.content.Reason</td>
<td>
@policyEvent.content.ExpiryDateTime
@@ -104,18 +105,18 @@ else
</table>
<details>
<summary>Invalid events</summary>
- <table class="table table-striped table-hover" style="width: fit-content;">
+ <table class="table table-striped table-hover" style="width: fit-Content;">
<thead>
<tr>
<th scope="col" style="max-width: 50vw;">State key</th>
- <th scope="col">Serialised contents</th>
+ <th scope="col">Serialised Contents</th>
</tr>
</thead>
<tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.room" && x.content.Entity == null))
+ @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && x.content.Entity == null))
{
<tr>
- <td>@policyEvent.state_key</td>
+ <td>@policyEvent.StateKey</td>
<td>@policyEvent.content.ToJson(indent: false, ignoreNull: true)</td>
</tr>
}
@@ -123,7 +124,7 @@ else
</table>
</details>
}
-@if (!PolicyEvents.Any(x => x.type == "m.policy.rule.user"))
+@if (!PolicyEvents.Any(x => x.Type == "m.policy.rule.user"))
{
<p>No user policies</p>
}
@@ -131,9 +132,13 @@ else
{
<h3>User policies</h3>
<hr/>
- <table class="table table-striped table-hover" style="width: fit-content;">
+ <table class="table table-striped table-hover" style="width: fit-Content;">
<thead>
<tr>
+ @if (_enableAvatars)
+ {
+ <th scope="col"></th>
+ }
<th scope="col" style="max-width: 0.2vw; word-wrap: anywhere;">User</th>
<th scope="col">Reason</th>
<th scope="col">Expires</th>
@@ -141,10 +146,14 @@ else
</tr>
</thead>
<tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.user" && x.content.Entity != null))
+ @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && x.content.Entity != null))
{
<tr>
- <td style="word-wrap: anywhere;">Entity: @string.Join("", policyEvent.content.Entity.Take(64))<br/>State: @string.Join("", policyEvent.state_key.Take(64))</td>
+ @if (_enableAvatars)
+ {
+ <td scope="col"><img style="width: 48px; height: 48px; aspect-ratio: unset; border-radius: 50%;" src="@(avatars.ContainsKey(policyEvent.content.Entity) ? avatars[policyEvent.content.Entity] : "")"/></td>
+ }
+ <td style="word-wrap: anywhere;">Entity: @string.Join("", policyEvent.content.Entity.Take(64))<br/>State: @string.Join("", policyEvent.StateKey.Take(64))</td>
<td>@policyEvent.content.Reason</td>
<td>
@policyEvent.content.ExpiryDateTime
@@ -158,18 +167,18 @@ else
</table>
<details>
<summary>Invalid events</summary>
- <table class="table table-striped table-hover" style="width: fit-content;">
+ <table class="table table-striped table-hover" style="width: fit-Content;">
<thead>
<tr>
<th scope="col">State key</th>
- <th scope="col">Serialised contents</th>
+ <th scope="col">Serialised Contents</th>
</tr>
</thead>
<tbody>
- @foreach (var policyEvent in PolicyEvents.Where(x => x.type == "m.policy.rule.user" && x.content.Entity == null))
+ @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && x.content.Entity == null))
{
<tr>
- <td>@policyEvent.state_key</td>
+ <td>@policyEvent.StateKey</td>
<td>@policyEvent.content.ToJson(indent: false, ignoreNull: true)</td>
</tr>
}
@@ -183,19 +192,24 @@ else
@code {
//get room list
// - sync withroom list filter
- // type = support.feline.msc3784
+ // Type = support.feline.msc3784
//support.feline.policy.lists.msc.v1
[Parameter]
public string? RoomId { get; set; }
+
+ private bool _enableAvatars = false;
+
+ static Dictionary<string, string> avatars = new Dictionary<string, string>();
+ static Dictionary<string, RemoteHomeServer> servers = new Dictionary<string, RemoteHomeServer>();
- public List<StateEvent<PolicyRuleStateEventData>> PolicyEvents { get; set; } = new();
+ public static List<StateEventResponse<PolicyRuleStateEventData>> PolicyEvents { get; set; } = new();
protected override async Task OnInitializedAsync()
{
- if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
- // if(RuntimeCache.AccessToken == null || RuntimeCache.CurrentHomeserver == null)
+ // if(RuntimeCache.AccessToken == null || RuntimeCache.CurrentHomeserver == null)
if (RuntimeCache.CurrentHomeServer == null)
{
NavigationManager.NavigateTo("/Login");
@@ -208,21 +222,49 @@ else
private async Task LoadStatesAsync()
{
- // using var client = new HttpClient();
- // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalStorageWrapper.AccessToken);
- // var response = await client.GetAsync($"{LocalStorageWrapper.CurrentHomeserver}/_matrix/client/r0/rooms/{RoomId}/state");
- // var content = await response.Content.ReadAsStringAsync();
- // Console.WriteLine(JsonSerializer.Deserialize<object>(content).ToJson());
- // var stateEvents = JsonSerializer.Deserialize<List<StateEvent>>(content);
+ // using var client = new HttpClient();
+ // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalStorageWrapper.AccessToken);
+ // var response = await client.GetAsync($"{LocalStorageWrapper.CurrentHomeserver}/_matrix/client/r0/rooms/{RoomId}/state");
+ // var Content = await response.Content.ReadAsStringAsync();
+ // Console.WriteLine(JsonSerializer.Deserialize<object>(Content).ToJson());
+ // var stateEvents = JsonSerializer.Deserialize<List<StateEventResponse>>(Content);
var room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId);
var stateEventsQuery = await room.GetStateAsync("");
if (stateEventsQuery == null)
{
Console.WriteLine("state events query is null!!!");
}
- var stateEvents = stateEventsQuery.Value.Deserialize<List<StateEvent>>();
- PolicyEvents = stateEvents.Where(x => x.type.StartsWith("m.policy.rule"))
- .Select(x => JsonSerializer.Deserialize<StateEvent<PolicyRuleStateEventData>>(JsonSerializer.Serialize(x))).ToList();
+ var stateEvents = stateEventsQuery.Value.Deserialize<List<StateEventResponse>>();
+ PolicyEvents = stateEvents.Where(x => x.Type.StartsWith("m.policy.rule"))
+ .Select(x => JsonSerializer.Deserialize<StateEventResponse<PolicyRuleStateEventData>>(JsonSerializer.Serialize(x))).ToList();
+ StateHasChanged();
+ }
+
+ private async Task GetAvatar(string userId)
+ {
+ try
+ {
+ if (avatars.ContainsKey(userId)) return;
+ var hs = userId.Split(':')[1];
+ RemoteHomeServer server = servers.ContainsKey(hs) ? servers[hs] : await new RemoteHomeServer(userId.Split(':')[1]).Configure();
+ if (!servers.ContainsKey(hs)) servers.Add(hs, server);
+ var profile = await server.GetProfile(userId);
+ avatars.Add(userId, server.ResolveMediaUri(profile.AvatarUrl));
+ servers.Add(userId, server);
+ StateHasChanged();
+ }
+ catch
+ {
+ // ignored
+ }
+ }
+
+ private async Task GetAllAvatars()
+ {
+ foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && x.content.Entity != null))
+ {
+ await GetAvatar(policyEvent.content.Entity);
+ }
StateHasChanged();
}
diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
index f25fbae..e61598a 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
+++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListRoomList.razor
@@ -35,7 +35,7 @@ else
@code {
//get room list
// - sync withroom list filter
- // type = support.feline.msc3784
+ // Type = support.feline.msc3784
//support.feline.policy.lists.msc.v1
public List<PolicyRoomInfo> PolicyRoomList { get; set; } = new();
@@ -45,7 +45,7 @@ else
protected override async Task OnInitializedAsync()
{
- if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
if (RuntimeCache.CurrentHomeServer == null)
{
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor
index 6d27679..35bf501 100644
--- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor
@@ -11,21 +11,28 @@
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="true"></RoomListItem></a>
+ <a style="color: unset; text-decoration: unset;" href="/RoomManager/Space/@room.RoomId.Replace('.', '~')">
+ <RoomListItem Room="@room" ShowOwnProfile="true"></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>
+ <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>
@@ -34,9 +41,10 @@ else
@code {
public List<Room> Rooms { get; set; } = new();
public List<Room> Spaces { get; set; } = new();
+
protected override async Task OnInitializedAsync()
{
- if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
if (RuntimeCache.CurrentHomeServer == null)
{
@@ -45,40 +53,47 @@ else
}
Rooms = await RuntimeCache.CurrentHomeServer.GetJoinedRooms();
StateHasChanged();
- var semaphore = new SemaphoreSlim(1000);
+ Console.WriteLine($"Got {Rooms.Count} rooms");
+ var semaphore = new SemaphoreSlim(10);
var tasks = new List<Task<Room?>>();
foreach (var room in Rooms)
{
tasks.Add(CheckIfSpace(room, semaphore));
}
await Task.WhenAll(tasks);
-
+
Console.WriteLine("Fetched joined rooms!");
}
-
+
private async Task<Room?> CheckIfSpace(Room room, SemaphoreSlim semaphore)
{
await semaphore.WaitAsync();
+ // Console.WriteLine($"Checking if {room.RoomId} is a space");
try
{
- var state = await room.GetStateAsync("m.room.create");
+ var state = await room.GetStateAsync<CreateEvent>("m.room.create");
if (state != null)
{
- //Console.WriteLine(state.Value.ToJson());
- if(state.Value.TryGetProperty("type", out var type))
+ //Console.WriteLine(state.Value.ToJson());
+ if (state.Type != null)
{
- if(type.ToString() == "m.space")
+ if (state.Type == "m.space")
{
+ Console.WriteLine($"Room {room.RoomId} is a space!");
Spaces.Add(room);
Rooms.Remove(room);
StateHasChanged();
return room;
}
+ else
+ {
+ Console.WriteLine($"Encountered unknown room type {state.Type}");
+ }
}
else
{
- //this is fine, apprently...
- //Console.WriteLine($"Room {room.RoomId} has no content.type in m.room.create!");
+ //this is fine, apprently...
+ // Console.WriteLine($"Room {room.RoomId} has no Content.type in m.room.create!");
}
}
}
@@ -93,4 +108,5 @@ else
}
return null;
}
-}
\ No newline at end of file
+
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor
new file mode 100644
index 0000000..7b4db37
--- /dev/null
+++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor
@@ -0,0 +1,298 @@
+@page "/RoomManagerCreateRoom"
+@using System.Text.Json
+@using MatrixRoomUtils.Core.Extensions
+@using MatrixRoomUtils.Core.Responses
+@using System.Runtime.Intrinsics.X86
+<h3>Room Manager - Create Room</h3>
+
+@* <pre Contenteditable="true" @onkeypress="@JsonChanged" ="JsonString">@JsonString</pre> *@
+<table>
+ <tr >
+ <td style="padding-bottom: 16px;">Preset:</td>
+ <td style="padding-bottom: 16px;">
+ <InputSelect @bind-Value="@RoomPreset">
+ @foreach (var createRoomRequest in Presets)
+ {
+ <option value="@createRoomRequest.Key">@createRoomRequest.Key</option>
+ }
+ @* <option value="private_chat">Private chat</option> *@
+ @* <option value="trusted_private_chat">Trusted private chat</option> *@
+ @* <option value="public_chat">Public chat</option> *@
+ </InputSelect>
+ </td>
+ </tr>
+ <tr>
+ <td>Room name:</td>
+ <td>
+ <InputText @bind-Value="@creationEvent.Name"></InputText>
+ </td>
+ </tr>
+ <tr>
+ <td>Room alias (localpart):</td>
+ <td>
+ <InputText @bind-Value="@creationEvent.RoomAliasName"></InputText>
+ </td>
+ </tr>
+ <tr>
+ <td>Room type:</td>
+ <td>
+ <InputSelect @bind-Value="@creationEvent._creationContentBaseType.Type">
+ <option value="">Room</option>
+ <option value="m.space">Space</option>
+ </InputSelect>
+ <InputText @bind-Value="@creationEvent._creationContentBaseType.Type"></InputText>
+ </td>
+ </tr>
+ <tr>
+ <td style="padding-top: 16px;">History visibility:</td>
+ <td style="padding-top: 16px;">
+ <InputSelect @bind-Value="@creationEvent.HistoryVisibility">
+ <option value="invited">Invited</option>
+ <option value="joined">Joined</option>
+ <option value="shared">Shared</option>
+ <option value="world_readable">World readable</option>
+ </InputSelect>
+ </td>
+ </tr>
+ <tr>
+ <td>Guest access:</td>
+ <td>
+ <InputSelect @bind-Value="@creationEvent.GuestAccess">
+ <option value="can_join">Can join</option>
+ <option value="forbidden">Forbidden</option>
+ </InputSelect>
+ </td>
+ </tr>
+
+ <tr>
+ <td>Room icon:</td>
+ <td>
+ <img src="@RuntimeCache.CurrentHomeServer?.ResolveMediaUri(creationEvent.RoomIcon ?? "")" style="max-width: 100px; max-height: 100px; border-radius: 50%;"/>
+ @* <InputText @bind-Value="@creationEvent.RoomIcon"></InputText> *@
+ </td>
+
+ </tr>
+
+ <tr>
+ <td style="vertical-align: top;">Initial states:</td>
+ <td>
+ <details>
+ @code{
+
+ private static string[] ImplementedStates = new[] { "m.room.avatar", "m.room.history_visibility", "m.room.guest_access", };
+
+ }
+ <summary>@creationEvent.InitialState.Count(x => !ImplementedStates.Contains(x.Type)) custom states</summary>
+ <table>
+ @foreach (var initialState in creationEvent.InitialState.Where(x => !ImplementedStates.Contains(x.Type)))
+ {
+ <tr>
+ <td style="vertical-align: top;">@(initialState.Type):</td>
+
+ <td>
+ <pre>@JsonSerializer.Serialize(initialState.Content, new JsonSerializerOptions { WriteIndented = true })</pre>
+ </td>
+ </tr>
+ }
+ </table>
+ </details>
+ <details>
+ <summary>@creationEvent.InitialState.Count initial states</summary>
+ <table>
+ @foreach (var initialState in creationEvent.InitialState.Where(x => !new[] { "m.room.avatar", "m.room.history_visibility" }.Contains(x.Type)))
+ {
+ <tr>
+ <td style="vertical-align: top;">@(initialState.Type):</td>
+
+ <td>
+ <pre>@JsonSerializer.Serialize(initialState.Content, new JsonSerializerOptions { WriteIndented = true })</pre>
+ </td>
+ </tr>
+ }
+ </table>
+ </details>
+ </td>
+ </tr>
+</table>
+<br/>
+<details>
+ <summary>Creation JSON</summary>
+ <pre>
+ @creationEvent.ToJson(ignoreNull: true)
+ </pre>
+</details>
+<details open>
+ <summary>Creation JSON (with null values)</summary>
+ <EditablePre @bind-Value="@JsonString" oninput="@JsonChanged"></EditablePre>
+</details>
+
+
+@code {
+
+ private string JsonString
+ {
+ get => creationEvent.ToJson();
+ set
+ {
+ creationEvent = JsonSerializer.Deserialize<CreateRoomRequest>(value);
+ JsonChanged();
+ }
+ }
+
+ private string RoomPreset
+ {
+ get
+ {
+ if (Presets.ContainsValue(creationEvent))
+ {
+ return Presets.First(x => x.Value == creationEvent).Key;
+ }
+ return "Not a preset";
+ }
+ set
+ {
+ creationEvent = Presets[value];
+ JsonChanged();
+ }
+ }
+
+ private Dictionary<string, string> creationEventValidationErrors { get; set; } = new();
+
+ private CreateRoomRequest creationEvent { get; set; }
+
+ private Dictionary<string, CreateRoomRequest> Presets { get; set; } = new();
+
+ protected override async Task OnInitializedAsync()
+ {
+ await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+
+ creationEvent = Presets["Default room"] = new CreateRoomRequest
+ {
+ Name = "My new room",
+ RoomAliasName = "myroom",
+ InitialState = new()
+ {
+ new()
+ {
+ Type = "m.room.history_visibility",
+ Content = new
+ {
+ history_visibility = "world_readable"
+ }
+ },
+ new()
+ {
+ Type = "m.room.guest_access",
+ Content = new
+ {
+ guest_access = "can_join"
+ }
+ },
+ new()
+ {
+ Type = "m.room.join_rules",
+ Content = new
+ {
+ join_rule = "public"
+ }
+ },
+ new()
+ {
+ Type = "m.room.server_acl",
+ Content = new
+ {
+ allow = new[] { "*" },
+ deny = new[]
+ {
+ "midov.pl",
+ "qoto.org",
+ "matrix.kiwifarms.net",
+ "plan9.rocks",
+ "thisisjoes.site",
+ "konqi.work",
+ "austinhuang.lol",
+ "arcticfox.ems.host",
+ "*.thisisjoes.site",
+ "*.abuser.eu",
+ "*.austinhuang.lol"
+ },
+ allow_ip_literals = false
+ }
+ },
+ new()
+ {
+ Type = "m.room.avatar",
+ Content = new
+ {
+ url = "mxc://feline.support/UKNhEyrVsrAbYteVvZloZcFj"
+ }
+ }
+ },
+ Visibility = "public",
+ PowerLevelContentOverride = new()
+ {
+ UsersDefault = 0,
+ EventsDefault = 100,
+ StateDefault = 50,
+ Invite = 0,
+ Redact = 50,
+ Kick = 50,
+ Ban = 50,
+ NotificationsPl = new()
+ {
+ Room = 50
+ },
+ Events = new()
+ {
+ { "im.vector.modular.widgets", 50 },
+ { "io.element.voice_broadcast_info", 50 },
+ { "m.reaction", 100 },
+ { "m.room.avatar", 50 },
+ { "m.room.canonical_alias", 50 },
+ { "m.room.encryption", 100 },
+ { "m.room.history_visibility", 100 },
+ { "m.room.name", 50 },
+ { "m.room.pinned_events", 50 },
+ { "m.room.power_levels", 100 },
+ { "m.room.redaction", 100 },
+ { "m.room.server_acl", 100 },
+ { "m.room.tombstone", 100 },
+ { "m.room.topic", 50 },
+ { "m.space.child", 50 },
+ { "org.matrix.msc3401.call", 50 },
+ { "org.matrix.msc3401.call.member", 50 }
+ },
+ Users = new()
+ {
+ { "@alicia:rory.gay", 100 },
+ { "@emma:rory.gay", 100 },
+ { "@root:rory.gay", 100 },
+ { "@rory:rory.gay", 100 }
+ },
+ },
+ CreationContent = new()
+ {
+ { "type", null }
+ }
+ };
+
+
+ await base.OnInitializedAsync();
+ }
+
+ private void JsonChanged()
+ {
+ Console.WriteLine(JsonString);
+ }
+
+
+ private string GetStateFriendlyName(string key) => key switch {
+ "m.room.history_visibility" => "History visibility",
+ "m.room.guest_access" => "Guest access",
+ "m.room.join_rules" => "Join rules",
+ "m.room.server_acl" => "Server ACL",
+ "m.room.avatar" => "Avatar",
+ _ => key
+ };
+
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor
index 4a5bddf..a44b2b4 100644
--- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor
@@ -13,9 +13,9 @@
<br/>
<details style="background: #0002;">
<summary style="background: #fff1;">State list</summary>
- @foreach (var stateEvent in States.OrderBy(x => x.state_key).ThenBy(x => x.type))
+ @foreach (var stateEvent in States.OrderBy(x => x.StateKey).ThenBy(x => x.Type))
{
- <p>@stateEvent.state_key/@stateEvent.type:</p>
+ <p>@stateEvent.StateKey/@stateEvent.Type:</p>
<pre>@stateEvent.content.ToJson()</pre>
}
</details>
@@ -27,7 +27,7 @@
private Room? Room { get; set; }
- private StateEvent<object>[] States { get; set; } = Array.Empty<StateEvent<object>>();
+ private StateEventResponse<object>[] States { get; set; } = Array.Empty<StateEventResponse<object>>();
private List<Room> Rooms { get; set; } = new();
protected override async Task OnInitializedAsync()
@@ -38,14 +38,14 @@
if (state != null)
{
Console.WriteLine(state.Value.ToJson());
- States = state.Value.Deserialize<StateEvent<object>[]>()!;
+ States = state.Value.Deserialize<StateEventResponse<object>[]>()!;
foreach (var stateEvent in States)
{
- if (stateEvent.type == "m.space.child")
+ if (stateEvent.Type == "m.space.child")
{
- // if (stateEvent.content.ToJson().Length < 5) return;
- var roomId = stateEvent.state_key;
+ // if (stateEvent.Content.ToJson().Length < 5) return;
+ var roomId = stateEvent.StateKey;
var room = await RuntimeCache.CurrentHomeServer.GetRoom(roomId);
if (room != null)
{
@@ -54,13 +54,13 @@
}
}
- // if(state.Value.TryGetProperty("type", out var type))
+ // if(state.Value.TryGetProperty("Type", out var Type))
// {
// }
// else
// {
// //this is fine, apprently...
- // //Console.WriteLine($"Room {room.RoomId} has no content.type in m.room.create!");
+ // //Console.WriteLine($"Room {room.RoomId} has no Content.Type in m.room.create!");
// }
}
await base.OnInitializedAsync();
diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor
index 638d728..3037dcc 100644
--- a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor
@@ -12,7 +12,7 @@
<br/>
<InputSelect @bind-Value="shownStateKey">
<option value="">-- State key --</option>
- @foreach (var stateEvent in FilteredEvents.Where(x => x.state_key != "").Select(x => x.state_key).Distinct().OrderBy(x => x))
+ @foreach (var stateEvent in FilteredEvents.Where(x => x.StateKey != "").Select(x => x.StateKey).Distinct().OrderBy(x => x))
{
<option value="@stateEvent">@stateEvent</option>
Console.WriteLine(stateEvent);
@@ -21,33 +21,33 @@
<br/>
<InputSelect @bind-Value="shownType">
<option value="">-- Type --</option>
- @foreach (var stateEvent in FilteredEvents.Where(x => x.state_key != shownStateKey).Select(x => x.type).Distinct().OrderBy(x => x))
+ @foreach (var stateEvent in FilteredEvents.Where(x => x.StateKey != shownStateKey).Select(x => x.Type).Distinct().OrderBy(x => x))
{
<option value="@stateEvent">@stateEvent</option>
}
</InputSelect>
<br/>
-<textarea @bind="shownEventJson" style="width: 100%; height: fit-content;"></textarea>
+<textarea @bind="shownEventJson" style="width: 100%; height: fit-Content;"></textarea>
<LogView></LogView>
@code {
//get room list
// - sync withroom list filter
- // type = support.feline.msc3784
+ // Type = support.feline.msc3784
//support.feline.policy.lists.msc.v1
[Parameter]
public string? RoomId { get; set; }
- public List<StateEvent> FilteredEvents { get; set; } = new();
- public List<StateEvent> Events { get; set; } = new();
+ public List<StateEventResponse> FilteredEvents { get; set; } = new();
+ public List<StateEventResponse> Events { get; set; } = new();
public string status = "";
protected override async Task OnInitializedAsync()
{
- if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
if (RuntimeCache.CurrentHomeServer != null)
{
@@ -71,18 +71,18 @@
// var response = await client.GetAsync($"http://localhost:5117/matrix-hq-state.json");
//var _events = await response.Content.ReadFromJsonAsync<Queue<StateEventStruct>>();
var _data = await response.Content.ReadAsStreamAsync();
- var __events = JsonSerializer.DeserializeAsyncEnumerable<StateEvent>(_data);
+ var __events = JsonSerializer.DeserializeAsyncEnumerable<StateEventResponse>(_data);
await foreach (var _ev in __events)
{
- var e = new StateEvent()
+ var e = new StateEventResponse()
{
- type = _ev.type,
- state_key = _ev.state_key,
- origin_server_ts = _ev.origin_server_ts,
- content = _ev.content
+ Type = _ev.Type,
+ StateKey = _ev.StateKey,
+ OriginServerTs = _ev.OriginServerTs,
+ Content = _ev.Content
};
Events.Add(e);
- if (string.IsNullOrEmpty(e.state_key))
+ if (string.IsNullOrEmpty(e.StateKey))
{
FilteredEvents.Add(e);
}
@@ -106,7 +106,7 @@
await Task.Delay(1);
var _FilteredEvents = Events;
if (!ShowMembershipEvents)
- _FilteredEvents = _FilteredEvents.Where(x => x.type != "m.room.member").ToList();
+ _FilteredEvents = _FilteredEvents.Where(x => x.Type != "m.room.member").ToList();
status = "Done, rerendering!";
StateHasChanged();
@@ -114,7 +114,7 @@
FilteredEvents = _FilteredEvents;
if(_shownType != null)
- shownEventJson = _FilteredEvents.Where(x => x.type == _shownType).First().content.ToJson(indent: true, ignoreNull: true);
+ shownEventJson = _FilteredEvents.Where(x => x.Type == _shownType).First().Content.ToJson(indent: true, ignoreNull: true);
StateHasChanged();
}
@@ -126,10 +126,10 @@
public long origin_server_ts { get; set; }
public string state_key { get; set; }
public string type { get; set; }
- // public string sender { get; set; }
- // public string event_id { get; set; }
- // public string user_id { get; set; }
- // public string replaces_state { get; set; }
+ // public string Sender { get; set; }
+ // public string EventId { get; set; }
+ // public string UserId { get; set; }
+ // public string ReplacesState { get; set; }
}
public bool ShowMembershipEvents
diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor
index ba1b0ec..c654b13 100644
--- a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateRoomList.razor
@@ -23,7 +23,7 @@ else
public List<string> Rooms { get; set; } = new();
protected override async Task OnInitializedAsync()
{
- if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
if (RuntimeCache.CurrentHomeServer == null)
{
diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor
index 0f40cb9..c7f9f3c 100644
--- a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateViewerPage.razor
@@ -11,7 +11,7 @@
<input type="checkbox" id="showAll" @bind="ShowMembershipEvents"/> Show member events
-<table class="table table-striped table-hover" style="width: fit-content;">
+<table class="table table-striped table-hover" style="width: fit-Content;">
<thead>
<tr>
<th scope="col">Type</th>
@@ -23,7 +23,7 @@
{
<tr>
<td>@stateEvent.type</td>
- <td style="max-width: fit-content;">
+ <td style="max-width: fit-Content;">
<pre>@stateEvent.content</pre>
</td>
</tr>
@@ -35,7 +35,7 @@
{
<details>
<summary>@group.Key</summary>
- <table class="table table-striped table-hover" style="width: fit-content;">
+ <table class="table table-striped table-hover" style="width: fit-Content;">
<thead>
<tr>
<th scope="col">Type</th>
@@ -47,7 +47,7 @@
{
<tr>
<td>@stateEvent.type</td>
- <td style="max-width: fit-content;">
+ <td style="max-width: fit-Content;">
<pre>@stateEvent.content</pre>
</td>
</tr>
@@ -62,7 +62,7 @@
@code {
//get room list
// - sync withroom list filter
- // type = support.feline.msc3784
+ // Type = support.feline.msc3784
//support.feline.policy.lists.msc.v1
[Parameter]
@@ -74,7 +74,7 @@
protected override async Task OnInitializedAsync()
{
- if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
if (RuntimeCache.CurrentHomeServer == null)
{
@@ -149,10 +149,10 @@
public long origin_server_ts { get; set; }
public string state_key { get; set; }
public string type { get; set; }
- // public string sender { get; set; }
- // public string event_id { get; set; }
- // public string user_id { get; set; }
- // public string replaces_state { get; set; }
+ // public string Sender { get; set; }
+ // public string EventId { get; set; }
+ // public string UserId { get; set; }
+ // public string ReplacesState { get; set; }
}
public bool ShowMembershipEvents
diff --git a/MatrixRoomUtils.Web/Pages/UserImportPage.razor b/MatrixRoomUtils.Web/Pages/UserImportPage.razor
deleted file mode 100644
index 6f3045e..0000000
--- a/MatrixRoomUtils.Web/Pages/UserImportPage.razor
+++ /dev/null
@@ -1,71 +0,0 @@
-@page "/ImportUsers"
-@using System.Text.Json
-@using MatrixRoomUtils.Core.Authentication
-@inject ILocalStorageService LocalStorage
-<h3>Login</h3>
-
-<InputFile OnChange="@FileChanged" accept=".tsv"></InputFile>
-<br/>
-<button @onclick="Login">Login</button>
-<br/><br/>
-<h4>Parsed records</h4>
-<hr/>
-<table border="1">
- @foreach (var (homeserver, username, password) in records)
- {
- <tr style="background-color: @(RuntimeCache.LoginSessions.Any(x => x.Value.LoginResponse.UserId == $"@{username}:{homeserver}") ? "green" : "unset")">
- <td style="border-width: 1px;">@username</td>
- <td style="border-width: 1px;">@homeserver</td>
- <td style="border-width: 1px;">@password.Length chars</td>
- </tr>
- }
-</table>
-<br/>
-<br/>
-<LogView></LogView>
-
-@code {
- List<(string homeserver, string username, string password)> records = new();
-
- async Task Login()
- {
- foreach (var (homeserver, username, password) in records)
- {
- if(RuntimeCache.LoginSessions.Any(x => x.Value.LoginResponse.UserId == $"@{username}:{homeserver}")) continue;
- var result = await MatrixAuth.Login(homeserver, username, password);
- Console.WriteLine($"Obtained access token for {result.UserId}!");
-
- var userinfo = new UserInfo()
- {
- LoginResponse = result
- };
- userinfo.Profile = await MatrixAuth.GetProfile(result.HomeServer, result.UserId);
- RuntimeCache.LastUsedToken = result.AccessToken;
-
- RuntimeCache.LoginSessions.Add(result.AccessToken, userinfo);
- StateHasChanged();
- }
-
- await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
- }
-
- private async Task FileChanged(InputFileChangeEventArgs obj)
- {
- Console.WriteLine(JsonSerializer.Serialize(obj, new JsonSerializerOptions()
- {
- WriteIndented = true
- }));
- await using var rs = obj.File.OpenReadStream();
- using var sr = new StreamReader(rs);
- string TsvData = await sr.ReadToEndAsync();
- records.Clear();
- foreach (var line in TsvData.Split('\n'))
- {
- var parts = line.Split('\t');
- if (parts.Length != 3)
- continue;
- records.Add((parts[0], parts[1], parts[2]));
- }
- }
-
-}
\ No newline at end of file
|