diff --git a/MatrixRoomUtils.Web/Pages/DataExportPage.razor b/MatrixRoomUtils.Web/Pages/DataExportPage.razor
index f9a4c37..5628d94 100644
--- a/MatrixRoomUtils.Web/Pages/DataExportPage.razor
+++ b/MatrixRoomUtils.Web/Pages/DataExportPage.razor
@@ -1,10 +1,7 @@
@page "/export"
-@using MatrixRoomUtils.Web.Classes
@using MatrixRoomUtils.Web.Shared.IndexComponents
-@using Blazored.LocalStorage
@using MatrixRoomUtils.Authentication
@using System.Text.Json
-@using Microsoft.AspNetCore.Components.Rendering
@inject NavigationManager NavigationManager
@inject ILocalStorageService LocalStorage
@@ -19,7 +16,7 @@
{
@foreach (var (token, user) in RuntimeCache.LoginSessions)
{
- <IndexUserItem User="@user" Token="@token"/>
+ <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
@@ -55,16 +52,18 @@ else
StateHasChanged();
foreach (var hs in homeservers)
{
- if (LocalStorageWrapper.HomeserverResolutionCache.ContainsKey(hs)) continue;
+ if (RuntimeCache.HomeserverResolutionCache.ContainsKey(hs))
+ {
+ resolvedHomeservers++;
+ continue;
+ }
var resolvedHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(hs);
- if (LocalStorageWrapper.HomeserverResolutionCache.ContainsKey(hs))
- LocalStorageWrapper.HomeserverResolutionCache.Remove(hs);
- LocalStorageWrapper.HomeserverResolutionCache.Add(hs, new() { Result = resolvedHomeserver, ResolutionTime = DateTime.Now });
+ RuntimeCache.HomeserverResolutionCache.Add(hs, new() { Result = resolvedHomeserver, ResolutionTime = DateTime.Now });
await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
Console.WriteLine("Saved to local storage:");
- Console.WriteLine(JsonSerializer.Serialize(LocalStorageWrapper.HomeserverResolutionCache, new JsonSerializerOptions()
+ Console.WriteLine(JsonSerializer.Serialize(RuntimeCache.HomeserverResolutionCache, new JsonSerializerOptions()
{
WriteIndented = true
}));
diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor
index ea9404d..8a5dcc4 100644
--- a/MatrixRoomUtils.Web/Pages/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Index.razor
@@ -1,8 +1,6 @@
-@page "/"
-@using MatrixRoomUtils.Web.Classes
-@using MatrixRoomUtils.Web.Shared.IndexComponents
-@using Blazored.LocalStorage
-@inject NavigationManager NavigationManager
+ @page "/"
+ @using MatrixRoomUtils.Web.Shared.IndexComponents
+ @inject NavigationManager NavigationManager
@inject ILocalStorageService LocalStorage
<PageTitle>Index</PageTitle>
@@ -14,20 +12,19 @@ Small collection of tools to do not-so-everyday things.
<h5>Signed in accounts - <a href="/Login">Add new account</a> or <a href="/ImportUsers">Import from TSV</a></h5>
<hr/>
@{
- Console.WriteLine("Users in cache: " + LocalStorageWrapper.LoginSessions.Count);
- if (!LocalStorageWrapper.WasLoaded)
+ if (!RuntimeCache.WasLoaded)
{
Console.WriteLine("[INDEX] !!! LOCALSTORAGE WAS NOT LOADED !!!");
LocalStorageWrapper.LoadFromLocalStorage(LocalStorage).GetAwaiter().OnCompleted(() =>
{
- Console.WriteLine("Users in cache: " + LocalStorageWrapper.LoginSessions.Count);
+ Console.WriteLine("Users in cache: " + RuntimeCache .LoginSessions.Count);
StateHasChanged();
});
}
}
<form>
- @foreach (var (token, user) in LocalStorageWrapper.LoginSessions)
+ @foreach (var (token, user) in RuntimeCache.LoginSessions)
{
- <IndexUserItem User="@user" Token="@token"/>
+ <IndexUserItem User="@user"/>
}
</form>
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/LoginPage.razor b/MatrixRoomUtils.Web/Pages/LoginPage.razor
index aead5e8..da9345a 100644
--- a/MatrixRoomUtils.Web/Pages/LoginPage.razor
+++ b/MatrixRoomUtils.Web/Pages/LoginPage.razor
@@ -1,7 +1,5 @@
@page "/Login"
@using MatrixRoomUtils.Authentication
-@using MatrixRoomUtils.Web.Classes
-@using Blazored.LocalStorage
@inject ILocalStorageService LocalStorage
<h3>Login</h3>
@@ -23,24 +21,25 @@
string homeserver = "";
string username = "";
string password = "";
+
async Task Login()
{
var result = await MatrixAuth.Login(homeserver, username, password);
Console.WriteLine($"Obtained access token for {result.UserId}!");
-
- LocalStorageWrapper.AccessToken = result.AccessToken;
+
+ RuntimeCache.AccessToken = result.AccessToken;
var userinfo = new UserInfo()
{
- LoginResponse = result
+ LoginResponse = result,
+ AccessToken = result.AccessToken,
+ Profile = await MatrixAuth.GetProfile(result.HomeServer, result.UserId)
};
- userinfo.Profile = await MatrixAuth.GetProfile(result.HomeServer, result.UserId);
-
- LocalStorageWrapper.LoginSessions.Add(result.AccessToken, userinfo);
- LocalStorageWrapper.CurrentHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(result.HomeServer);
-
+ //TODO: refactor
+ RuntimeCache.LoginSessions.Add(userinfo.AccessToken, userinfo);
+ RuntimeCache.CurrentHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(result.HomeServer);
await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
-
}
+
}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor
index 6c276b6..a411ccc 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor
+++ b/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor
@@ -1,7 +1,4 @@
@page "/PolicyListEditor/{RoomId}"
-@using MatrixRoomUtils.Authentication
-@using MatrixRoomUtils.Web.Classes
-@using Blazored.LocalStorage
@using System.Net.Http.Headers
@using System.Text.Json
@using MatrixRoomUtils.Extensions
@@ -146,7 +143,7 @@ else
@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>
+ <td style="word-wrap: anywhere;">Entity: @string.Join("", policyEvent.content.Entity.Take(64))<br/>State: @string.Join("", policyEvent.state_key.Take(64))</td>
<td>@policyEvent.content.Reason</td>
<td>
@policyEvent.content.ExpiryDateTime
@@ -195,9 +192,10 @@ else
protected override async Task OnInitializedAsync()
{
- if (!LocalStorageWrapper.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
- if(LocalStorageWrapper.AccessToken == null || LocalStorageWrapper.CurrentHomeserver == null)
+ // if(RuntimeCache.AccessToken == null || RuntimeCache.CurrentHomeserver == null)
+ if (RuntimeCache.CurrentHomeServer == null)
{
NavigationManager.NavigateTo("/Login");
return;
@@ -209,24 +207,17 @@ 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<StateEvent>>(content);
+ var room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId);
+ var stateEvents = (await room.GetStateAsync(""))!.Value.Deserialize<List<StateEvent>>();
PolicyEvents = stateEvents.Where(x => x.type.StartsWith("m.policy.rule"))
.Select(x => JsonSerializer.Deserialize<StateEvent<PolicyRuleStateEventData>>(JsonSerializer.Serialize(x))).ToList();
StateHasChanged();
- // foreach (var stateEvent in PolicyEvents.Where(x => x.replaces_state != "" && x.replaces_state != null))
- // {
- // Console.WriteLine($"{stateEvent.replaces_state} -> {PolicyEvents.Any(x => x.state_key == stateEvent.replaces_state)}");
- // }
- // foreach (var policyEvent in PolicyEvents)
- // {
- // Console.WriteLine(policyEvent.ToJson());
- // }
}
-}
-
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor
index 032d150..f1d26f1 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor
+++ b/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor
@@ -1,12 +1,7 @@
@page "/PolicyListEditor"
-@using MatrixRoomUtils.Authentication
-@using MatrixRoomUtils.Web.Classes
-@using Blazored.LocalStorage
@using System.Net.Http.Headers
@using System.Text.Json
-@using System.Xml.Schema
@using MatrixRoomUtils.Extensions
-@using MatrixRoomUtils.StateEventTypes
@inject ILocalStorageService LocalStorage
@inject NavigationManager NavigationManager
<h3>Policy list editor</h3>
@@ -47,9 +42,9 @@ else
protected override async Task OnInitializedAsync()
{
- if (!LocalStorageWrapper.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
- if (LocalStorageWrapper.AccessToken == null || LocalStorageWrapper.CurrentHomeserver == null)
+ if (RuntimeCache.CurrentHomeServer != null)
{
NavigationManager.NavigateTo("/Login");
return;
@@ -60,7 +55,7 @@ else
private async Task EnumeratePolicyRooms()
{
- var xxxrooms = await LocalStorageWrapper.CurrentHomeServer.GetJoinedRooms();
+ var xxxrooms = await RuntimeCache.CurrentHomeServer.GetJoinedRooms();
totalRoomCount = xxxrooms.Count;
StateHasChanged();
@@ -75,7 +70,7 @@ else
Console.WriteLine($"Detected policy lists: {PolicyRoomList.ToJson()}");
return;
-
+ /*
using HttpClient wc = new();
wc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalStorageWrapper.AccessToken);
@@ -112,20 +107,22 @@ else
//print to console
Console.WriteLine($"Detected policy lists: {PolicyRoomList.ToJson()}");
+ */
}
private async Task<PolicyRoomInfo?> GetPolicyRoomInfo(string room, SemaphoreSlim semaphore)
{
try
{
+ //TODO: refactor!!!!!
await semaphore.WaitAsync();
PolicyRoomInfo roomInfo = new()
{
RoomId = room
};
using HttpClient wc = new();
- wc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalStorageWrapper.AccessToken);
- var sk = await wc.GetAsync($"{LocalStorageWrapper.CurrentHomeserver}/_matrix/client/v3/rooms/{room}/state/org.matrix.mjolnir.shortcode");
+ wc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.AccessToken);
+ var sk = await wc.GetAsync($"{RuntimeCache.CurrentHomeserver}/_matrix/client/v3/rooms/{room}/state/org.matrix.mjolnir.shortcode");
if (sk.IsSuccessStatusCode)
{
var sko = await sk.Content.ReadFromJsonAsync<JsonElement>();
@@ -149,7 +146,7 @@ else
// {
// }
// else Console.WriteLine($"Got failure while checking {room}: {sk.StatusCode} ({await sk.Content.ReadAsStringAsync()})...");
- var r = await LocalStorageWrapper.CurrentHomeServer.GetRoom(room);
+ var r = await RuntimeCache.CurrentHomeServer.GetRoom(room);
roomInfo.Shortcode = (await r.GetStateAsync("org.matrix.mjolnir.shortcode")).Value.GetProperty("shortcode").GetString();
roomInfo.Name = await r.GetNameAsync();
return roomInfo;
diff --git a/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor b/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor
index 6ad99d9..e15ce20 100644
--- a/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor
@@ -1,14 +1,6 @@
@page "/RoomStateViewer/{RoomId}/Edit"
-@using MatrixRoomUtils.Authentication
-@using MatrixRoomUtils.Web.Classes
-@using Blazored.LocalStorage
@using System.Net.Http.Headers
@using System.Text.Json
-@using System.Xml.Schema
-@using MatrixRoomUtils.Extensions
-@using MatrixRoomUtils.StateEventTypes
-@using MatrixRoomUtils.Web.Shared.IndexComponents
-@using Microsoft.Win32.SafeHandles
@inject ILocalStorageService LocalStorage
@inject NavigationManager NavigationManager
<h3>Room state editor</h3>
@@ -55,9 +47,9 @@
protected override async Task OnInitializedAsync()
{
- if (!LocalStorageWrapper.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
- if (LocalStorageWrapper.AccessToken == null || LocalStorageWrapper.CurrentHomeserver == null)
+ if (RuntimeCache.CurrentHomeServer != null)
{
NavigationManager.NavigateTo("/Login");
return;
@@ -73,8 +65,8 @@
{
int StateLoaded = 0;
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");
+ client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.AccessToken);
+ var response = await client.GetAsync($"{RuntimeCache.CurrentHomeserver}/_matrix/client/r0/rooms/{RoomId}/state");
// 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();
diff --git a/MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor b/MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor
index b13d069..6e846e9 100644
--- a/MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor
@@ -1,12 +1,6 @@
@page "/RoomStateViewer"
-@using MatrixRoomUtils.Authentication
-@using MatrixRoomUtils.Web.Classes
-@using Blazored.LocalStorage
@using System.Net.Http.Headers
@using System.Text.Json
-@using System.Xml.Schema
-@using MatrixRoomUtils.Extensions
-@using MatrixRoomUtils.StateEventTypes
@inject ILocalStorageService LocalStorage
@inject NavigationManager NavigationManager
<h3>Room state viewer</h3>
@@ -43,9 +37,9 @@ else
protected override async Task OnInitializedAsync()
{
- if (!LocalStorageWrapper.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
- if (LocalStorageWrapper.AccessToken == null || LocalStorageWrapper.CurrentHomeserver == null)
+ if (RuntimeCache.CurrentHomeServer == null)
{
NavigationManager.NavigateTo("/Login");
return;
@@ -57,12 +51,12 @@ else
private async Task EnumeratePolicyRooms()
{
using HttpClient wc = new();
- wc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalStorageWrapper.AccessToken);
+ wc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.AccessToken);
//get room list
//temporary hack until rooms get enumerated...
string[] rooms = { "!fTjMjIzNKEsFlUIiru:neko.dev" };
- var _rooms = await wc.GetAsync($"{LocalStorageWrapper.CurrentHomeserver}/_matrix/client/v3/joined_rooms");
+ var _rooms = await wc.GetAsync($"{RuntimeCache.CurrentHomeserver}/_matrix/client/v3/joined_rooms");
Console.WriteLine($"Got {_rooms.StatusCode}...");
if (!_rooms.IsSuccessStatusCode)
{
@@ -100,8 +94,8 @@ else
RoomId = room
};
using HttpClient wc = new();
- wc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalStorageWrapper.AccessToken);
- var sk = await wc.GetAsync($"{LocalStorageWrapper.CurrentHomeserver}/_matrix/client/v3/rooms/{room}/state/m.room.name");
+ wc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.AccessToken);
+ var sk = await wc.GetAsync($"{RuntimeCache.CurrentHomeserver}/_matrix/client/v3/rooms/{room}/state/m.room.name");
if (sk.IsSuccessStatusCode)
{
Console.WriteLine($"Got content: {await sk.Content.ReadAsStringAsync()}");
diff --git a/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor b/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor
index 8c33d89..72c5efa 100644
--- a/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor
@@ -1,13 +1,7 @@
@page "/RoomStateViewer/{RoomId}"
-@using MatrixRoomUtils.Authentication
-@using MatrixRoomUtils.Web.Classes
-@using Blazored.LocalStorage
@using System.Net.Http.Headers
@using System.Text.Json
-@using System.Xml.Schema
@using MatrixRoomUtils.Extensions
-@using MatrixRoomUtils.StateEventTypes
-@using MatrixRoomUtils.Web.Shared.IndexComponents
@inject ILocalStorageService LocalStorage
@inject NavigationManager NavigationManager
<h3>Room state viewer</h3>
@@ -80,9 +74,9 @@
protected override async Task OnInitializedAsync()
{
- if (!LocalStorageWrapper.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+ if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
- if (LocalStorageWrapper.AccessToken == null || LocalStorageWrapper.CurrentHomeserver == null)
+ if (RuntimeCache.AccessToken == null || RuntimeCache.CurrentHomeserver == null)
{
NavigationManager.NavigateTo("/Login");
return;
@@ -97,8 +91,8 @@
{
int StateLoaded = 0;
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");
+ client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.AccessToken);
+ var response = await client.GetAsync($"{RuntimeCache.CurrentHomeserver}/_matrix/client/r0/rooms/{RoomId}/state");
// 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();
diff --git a/MatrixRoomUtils.Web/Pages/UserImportPage.razor b/MatrixRoomUtils.Web/Pages/UserImportPage.razor
index 612b3ce..6b5eb77 100644
--- a/MatrixRoomUtils.Web/Pages/UserImportPage.razor
+++ b/MatrixRoomUtils.Web/Pages/UserImportPage.razor
@@ -1,7 +1,5 @@
@page "/ImportUsers"
@using MatrixRoomUtils.Authentication
-@using MatrixRoomUtils.Web.Classes
-@using Blazored.LocalStorage
@using System.Text.Json
@inject ILocalStorageService LocalStorage
<h3>Login</h3>
|