about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web')
-rw-r--r--MatrixRoomUtils.Web/App.razor3
-rw-r--r--MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs22
-rw-r--r--MatrixRoomUtils.Web/Pages/DataExportPage.razor5
-rw-r--r--MatrixRoomUtils.Web/Pages/Index.razor34
-rw-r--r--MatrixRoomUtils.Web/Pages/LoginPage.razor10
-rw-r--r--MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor5
-rw-r--r--MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor68
-rw-r--r--MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor6
-rw-r--r--MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor46
-rw-r--r--MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor10
-rw-r--r--MatrixRoomUtils.Web/Pages/UserImportPage.razor12
-rw-r--r--MatrixRoomUtils.Web/Program.cs1
-rw-r--r--MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor19
-rw-r--r--MatrixRoomUtils.Web/Shared/LogView.razor11
-rw-r--r--MatrixRoomUtils.Web/Shared/MainLayout.razor5
-rw-r--r--MatrixRoomUtils.Web/_Imports.razor2
16 files changed, 113 insertions, 146 deletions
diff --git a/MatrixRoomUtils.Web/App.razor b/MatrixRoomUtils.Web/App.razor
index 4e2789d..e2a241d 100644
--- a/MatrixRoomUtils.Web/App.razor
+++ b/MatrixRoomUtils.Web/App.razor
@@ -1,4 +1,5 @@
-<Router AppAssembly="@typeof(App).Assembly">
+@using MatrixRoomUtils.Core
+<Router AppAssembly="@typeof(App).Assembly">
     <Found Context="routeData">
         <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
         <FocusOnNavigate RouteData="@routeData" Selector="h1"/>
diff --git a/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs b/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs
index 229d937..a87537b 100644
--- a/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs
+++ b/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs
@@ -1,4 +1,6 @@
 using Blazored.LocalStorage;
+using MatrixRoomUtils.Core;
+using MatrixRoomUtils.Core.Extensions;
 
 namespace MatrixRoomUtils.Web.Classes;
 
@@ -12,15 +14,18 @@ public partial class LocalStorageWrapper
     }
     public static async Task LoadFromLocalStorage(ILocalStorageService localStorage)
     {
-        RuntimeCache.AccessToken = await localStorage.GetItemAsync<string>("rory.matrixroomutils.token");
-        RuntimeCache.CurrentHomeserver = await localStorage.GetItemAsync<string>("rory.matrixroomutils.current_homeserver");
+        // RuntimeCache.AccessToken = await localStorage.GetItemAsync<string>("rory.matrixroomutils.token");
+        RuntimeCache.LastUsedToken = await localStorage.GetItemAsync<string>("rory.matrixroomutils.last_used_token");
+        // RuntimeCache.CurrentHomeserver = await localStorage.GetItemAsync<string>("rory.matrixroomutils.current_homeserver");
         RuntimeCache.LoginSessions = await localStorage.GetItemAsync<Dictionary<string, UserInfo>>("rory.matrixroomutils.user_cache") ?? new();
         RuntimeCache.HomeserverResolutionCache = await localStorage.GetItemAsync<Dictionary<string, HomeServerResolutionResult>>("rory.matrixroomutils.homeserver_resolution_cache") ?? new();
         Console.WriteLine($"[LocalStorageWrapper] Loaded {RuntimeCache.LoginSessions.Count} login sessions, {RuntimeCache.HomeserverResolutionCache.Count} homeserver resolution cache entries");
-        if (RuntimeCache.AccessToken != null && RuntimeCache.CurrentHomeserver != null)
+        if (RuntimeCache.LastUsedToken != null)
         {
-            Console.WriteLine($"Access token and current homeserver are not null, creating authenticated home server");
-            RuntimeCache.CurrentHomeServer = new AuthenticatedHomeServer(RuntimeCache.LoginSessions[RuntimeCache.AccessToken].LoginResponse.UserId, RuntimeCache.AccessToken, RuntimeCache.LoginSessions[RuntimeCache.AccessToken].LoginResponse.HomeServer);
+            Console.WriteLine($"Access token is not null, creating authenticated home server");
+            Console.WriteLine($"Homeserver cache: {RuntimeCache.HomeserverResolutionCache.Count} entries");
+            Console.WriteLine(RuntimeCache.HomeserverResolutionCache.ToJson());
+            RuntimeCache.CurrentHomeServer = await new AuthenticatedHomeServer(RuntimeCache.LoginSessions[RuntimeCache.LastUsedToken].LoginResponse.UserId, RuntimeCache.LastUsedToken, RuntimeCache.LoginSessions[RuntimeCache.LastUsedToken].LoginResponse.HomeServer).Configure();
             Console.WriteLine("Created authenticated home server");
         }
         RuntimeCache.WasLoaded = true;
@@ -28,9 +33,10 @@ public partial class LocalStorageWrapper
 
     public static async Task SaveToLocalStorage(ILocalStorageService localStorage)
     {
-        await localStorage.SetItemAsStringAsync("rory.matrixroomutils.token", RuntimeCache.AccessToken);
-        await localStorage.SetItemAsync("rory.matrixroomutils.current_homeserver", RuntimeCache.CurrentHomeserver);
-        await localStorage.SetItemAsync("rory.matrixroomutils.user_cache", RuntimeCache.LoginSessions);
+        // if(RuntimeCache.AccessToken != null) await localStorage.SetItemAsStringAsync("rory.matrixroomutils.token", RuntimeCache.AccessToken);
+        // if(RuntimeCache.CurrentHomeserver != null) await localStorage.SetItemAsync("rory.matrixroomutils.current_homeserver", RuntimeCache.CurrentHomeserver);
+        if(RuntimeCache.LoginSessions != null) await localStorage.SetItemAsync("rory.matrixroomutils.user_cache", RuntimeCache.LoginSessions);
+        if(RuntimeCache.LastUsedToken != null) await localStorage.SetItemAsync("rory.matrixroomutils.last_used_token", RuntimeCache.LastUsedToken);
         await localStorage.SetItemAsync("rory.matrixroomutils.homeserver_resolution_cache", 
             RuntimeCache.HomeserverResolutionCache.DistinctBy(x => x.Key)
                 .ToDictionary(x => x.Key, x => x.Value));
diff --git a/MatrixRoomUtils.Web/Pages/DataExportPage.razor b/MatrixRoomUtils.Web/Pages/DataExportPage.razor
index 5628d94..58d49fc 100644
--- a/MatrixRoomUtils.Web/Pages/DataExportPage.razor
+++ b/MatrixRoomUtils.Web/Pages/DataExportPage.razor
@@ -1,7 +1,8 @@
 @page "/export"
 @using MatrixRoomUtils.Web.Shared.IndexComponents
-@using MatrixRoomUtils.Authentication
 @using System.Text.Json
+@using MatrixRoomUtils.Core
+@using MatrixRoomUtils.Core.Authentication
 @inject NavigationManager NavigationManager
 @inject ILocalStorageService LocalStorage
 
@@ -57,7 +58,7 @@ else
                     resolvedHomeservers++;
                     continue;
                 }
-                var resolvedHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(hs);
+                var resolvedHomeserver = (await new RemoteHomeServer(hs).Configure()).FullHomeServerDomain;
 
                 RuntimeCache.HomeserverResolutionCache.Add(hs, new() { Result = resolvedHomeserver, ResolutionTime = DateTime.Now });
                 await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor
index 8a5dcc4..67cefed 100644
--- a/MatrixRoomUtils.Web/Pages/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Index.razor
@@ -1,6 +1,7 @@
-    @page "/"
-    @using MatrixRoomUtils.Web.Shared.IndexComponents
-    @inject NavigationManager NavigationManager
+@page "/"
+@using MatrixRoomUtils.Web.Shared.IndexComponents
+@using MatrixRoomUtils.Core
+@inject NavigationManager NavigationManager
 @inject ILocalStorageService LocalStorage
 
 <PageTitle>Index</PageTitle>
@@ -11,20 +12,23 @@ 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>
 <hr/>
-@{
-    if (!RuntimeCache.WasLoaded)
-    {
-        Console.WriteLine("[INDEX] !!! LOCALSTORAGE WAS NOT LOADED !!!");
-        LocalStorageWrapper.LoadFromLocalStorage(LocalStorage).GetAwaiter().OnCompleted(() =>
-        {
-            Console.WriteLine("Users in cache: " + RuntimeCache .LoginSessions.Count);
-            StateHasChanged();
-        });
-    }
-}
 <form>
     @foreach (var (token, user) in RuntimeCache.LoginSessions)
     {
         <IndexUserItem User="@user"/>
     }
-</form>
\ No newline at end of file
+</form>
+
+@code
+{
+    protected override async Task OnInitializedAsync()
+    {
+        if (!RuntimeCache.WasLoaded)
+        {
+            Console.WriteLine("[INDEX] !!! LOCALSTORAGE WAS NOT LOADED !!!");
+            await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+        }
+        await base.OnInitializedAsync();
+        await LocalStorageWrapper.ReloadLocalStorage(LocalStorage);
+    }
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/LoginPage.razor b/MatrixRoomUtils.Web/Pages/LoginPage.razor
index da9345a..f318646 100644
--- a/MatrixRoomUtils.Web/Pages/LoginPage.razor
+++ b/MatrixRoomUtils.Web/Pages/LoginPage.razor
@@ -1,5 +1,6 @@
 @page "/Login"
-@using MatrixRoomUtils.Authentication
+@using MatrixRoomUtils.Core
+@using MatrixRoomUtils.Core.Authentication
 @inject ILocalStorageService LocalStorage
 <h3>Login</h3>
 
@@ -27,17 +28,14 @@
         var result = await MatrixAuth.Login(homeserver, username, password);
         Console.WriteLine($"Obtained access token for {result.UserId}!");
 
-        RuntimeCache.AccessToken = result.AccessToken;
+        RuntimeCache.LastUsedToken = result.AccessToken;
 
         var userinfo = new UserInfo()
         {
             LoginResponse = result,
-            AccessToken = result.AccessToken,
-            Profile = await MatrixAuth.GetProfile(result.HomeServer, result.UserId)
+            Profile = await (await new RemoteHomeServer(result.HomeServer).Configure()).GetProfile(result.UserId)
         };
-    //TODO: refactor
         RuntimeCache.LoginSessions.Add(userinfo.AccessToken, userinfo);
-        RuntimeCache.CurrentHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(result.HomeServer);
 
         await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
     }
diff --git a/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor
index a411ccc..ec452f3 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor
+++ b/MatrixRoomUtils.Web/Pages/PolicyListEditorPage.razor
@@ -1,8 +1,9 @@
 @page "/PolicyListEditor/{RoomId}"
 @using System.Net.Http.Headers
 @using System.Text.Json
-@using MatrixRoomUtils.Extensions
-@using MatrixRoomUtils.StateEventTypes
+@using MatrixRoomUtils.Core
+@using MatrixRoomUtils.Core.Extensions
+@using MatrixRoomUtils.Core.StateEventTypes
 @inject ILocalStorageService LocalStorage
 @inject NavigationManager NavigationManager
 <h3>Policy list editor</h3>
diff --git a/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor b/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor
index f1d26f1..924b68f 100644
--- a/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor
+++ b/MatrixRoomUtils.Web/Pages/PolicyListRoomList.razor
@@ -1,7 +1,8 @@
 @page "/PolicyListEditor"
 @using System.Net.Http.Headers
 @using System.Text.Json
-@using MatrixRoomUtils.Extensions
+@using MatrixRoomUtils.Core
+@using MatrixRoomUtils.Core.Extensions
 @inject ILocalStorageService LocalStorage
 @inject NavigationManager NavigationManager
 <h3>Policy list editor</h3>
@@ -44,7 +45,7 @@ else
     {
         if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
         await base.OnInitializedAsync();
-        if (RuntimeCache.CurrentHomeServer != null)
+        if (RuntimeCache.CurrentHomeServer == null)
         {
             NavigationManager.NavigateTo("/Login");
             return;
@@ -70,7 +71,7 @@ else
 
         Console.WriteLine($"Detected policy lists: {PolicyRoomList.ToJson()}");
         return;
-        /*
+    /*
         using HttpClient wc = new();
         wc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalStorageWrapper.AccessToken);
 
@@ -114,53 +115,28 @@ else
     {
         try
         {
-            //TODO: refactor!!!!!
+    //TODO: refactor!!!!!
             await semaphore.WaitAsync();
             PolicyRoomInfo roomInfo = new()
             {
                 RoomId = room
             };
-            using HttpClient wc = new();
-            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>();
-                if (sko.TryGetProperty("shortcode", out JsonElement shortcode))
-                {
-                    Console.WriteLine($"Room {room} has a shortcode: {shortcode.GetString()}!");
-                    roomInfo.Shortcode = shortcode.GetString();
-                    // sk = await wc.GetAsync($"{LocalStorageWrapper.CurrentHomeserver}/_matrix/client/v3/rooms/{room}/state/m.room.name");
-                    // if (sk.IsSuccessStatusCode)
-                    // {
-                    //     Console.WriteLine($"Got content: {await sk.Content.ReadAsStringAsync()}");
-                    //     sko = await sk.Content.ReadFromJsonAsync<JsonElement>();
-                    //     if (sko.TryGetProperty("name", out JsonElement roomname))
-                    //     {
-                    //         Console.WriteLine($"Room {room} has a name: {roomname.GetString()}!");
-                    //         roomInfo.Name = roomname.GetString();
-                    //     }
-                    //     else Console.WriteLine("No record found...");
-                    // }
-                    // else if (sk.StatusCode == System.Net.HttpStatusCode.NotFound)
-                    // {
-                    // }
-                    // else Console.WriteLine($"Got failure while checking {room}: {sk.StatusCode} ({await sk.Content.ReadAsStringAsync()})...");
-                    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;
-                }
-                else Console.WriteLine("No record found...");
-            }
-            else if (sk.StatusCode == System.Net.HttpStatusCode.NotFound)
+
+
+    // --- //
+            var r = await RuntimeCache.CurrentHomeServer.GetRoom(room);
+            roomInfo.Shortcode = (await r.GetStateAsync("org.matrix.mjolnir.shortcode")).Value.GetProperty("shortcode").GetString();
+
+            if (roomInfo.Shortcode != null)
             {
+                roomInfo.Name = await r.GetNameAsync();
+                return roomInfo;
             }
-            else Console.WriteLine($"Got failure while checking {room}: {sk.StatusCode} ({await sk.Content.ReadAsStringAsync()})...");
-            
+
             return null;
         }
         finally
+
         {
             checkedRoomCount++;
             StateHasChanged();
@@ -169,9 +145,15 @@ else
     }
 
     public struct PolicyRoomInfo
+
     {
-        public string RoomId { get; set; }
-        public string? Shortcode { get; set; }
-        public string? Name { get; set; }
+        public
+            string RoomId { get; set; }
+
+        public
+            string? Shortcode { get; set; }
+
+        public
+            string? Name { get; set; }
     }
     } 
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor b/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor
index e15ce20..47f2aba 100644
--- a/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomStateEditorPage.razor
@@ -1,6 +1,7 @@
 @page "/RoomStateViewer/{RoomId}/Edit"
 @using System.Net.Http.Headers
 @using System.Text.Json
+@using MatrixRoomUtils.Core
 @inject ILocalStorageService LocalStorage
 @inject NavigationManager NavigationManager
 <h3>Room state editor</h3>
@@ -65,8 +66,9 @@
     {
         int StateLoaded = 0;
         using var client = new HttpClient();
-        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.AccessToken);
-        var response = await client.GetAsync($"{RuntimeCache.CurrentHomeserver}/_matrix/client/r0/rooms/{RoomId}/state");
+        //TODO: can this be improved?
+        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.CurrentHomeServer.AccessToken);
+        var response = await client.GetAsync($"{RuntimeCache.CurrentHomeServer.FullHomeServerDomain}/_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 6e846e9..92e7955 100644
--- a/MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomStateRoomList.razor
@@ -1,6 +1,7 @@
 @page "/RoomStateViewer"
 @using System.Net.Http.Headers
 @using System.Text.Json
+@using MatrixRoomUtils.Core
 @inject ILocalStorageService LocalStorage
 @inject NavigationManager NavigationManager
 <h3>Room state viewer</h3>
@@ -50,26 +51,9 @@ else
 
     private async Task EnumeratePolicyRooms()
     {
-        using HttpClient wc = new();
-        wc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.AccessToken);
+        var rooms = (await RuntimeCache.CurrentHomeServer.GetJoinedRooms()).Select(x=>x.RoomId).ToList();
 
-    //get room list
-    //temporary hack until rooms get enumerated...
-        string[] rooms = { "!fTjMjIzNKEsFlUIiru:neko.dev" };
-        var _rooms = await wc.GetAsync($"{RuntimeCache.CurrentHomeserver}/_matrix/client/v3/joined_rooms");
-        Console.WriteLine($"Got {_rooms.StatusCode}...");
-        if (!_rooms.IsSuccessStatusCode)
-        {
-            Console.WriteLine($"Failed to get rooms: {await _rooms.Content.ReadAsStringAsync()}");
-            return;
-        }
-        var _rooms_o = await _rooms.Content.ReadFromJsonAsync<JsonElement>();
-        if (_rooms_o.TryGetProperty("joined_rooms", out JsonElement _rooms_j))
-        {
-            rooms = _rooms_j.EnumerateArray().Select(x => x.GetString()).ToArray();
-        }
-
-        totalRoomCount = rooms.Length;
+        totalRoomCount = rooms.Count;
         StateHasChanged();
 
         var semaphore = new SemaphoreSlim(128);
@@ -89,29 +73,11 @@ else
         try
         {
             await semaphore.WaitAsync();
-            var roomInfo = new PolicyRoomInfo()
+            return new PolicyRoomInfo()
             {
-                RoomId = room
+                RoomId = room,
+                Name = await (await RuntimeCache.CurrentHomeServer.GetRoom(room)).GetNameAsync()
             };
-            using HttpClient wc = new();
-            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()}");
-                var sko = await sk.Content.ReadFromJsonAsync<JsonElement>();
-                if (sko.TryGetProperty("name", out JsonElement shortcode))
-                {
-                    Console.WriteLine($"Room {room} has a name: {shortcode.GetString()}!");
-                    roomInfo.Name = shortcode.GetString();
-                }
-                else Console.WriteLine("No record found...");
-            }
-            else if (sk.StatusCode == System.Net.HttpStatusCode.NotFound)
-            {
-            }
-            else Console.WriteLine($"Got failure while checking {room}: {sk.StatusCode} ({await sk.Content.ReadAsStringAsync()})...");
-            return roomInfo;
         }
         finally
         {
diff --git a/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor b/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor
index 72c5efa..199c75b 100644
--- a/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor
+++ b/MatrixRoomUtils.Web/Pages/RoomStateViewerPage.razor
@@ -1,7 +1,8 @@
 @page "/RoomStateViewer/{RoomId}"
 @using System.Net.Http.Headers
 @using System.Text.Json
-@using MatrixRoomUtils.Extensions
+@using MatrixRoomUtils.Core
+@using MatrixRoomUtils.Core.Extensions
 @inject ILocalStorageService LocalStorage
 @inject NavigationManager NavigationManager
 <h3>Room state viewer</h3>
@@ -76,7 +77,7 @@
     {
         if (!RuntimeCache.WasLoaded) await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
         await base.OnInitializedAsync();
-        if (RuntimeCache.AccessToken == null || RuntimeCache.CurrentHomeserver == null)
+        if (RuntimeCache.CurrentHomeServer == null)
         {
             NavigationManager.NavigateTo("/Login");
             return;
@@ -90,9 +91,10 @@
     private async Task LoadStatesAsync()
     {
         int StateLoaded = 0;
+        //TODO: can we improve this?
         using var client = new HttpClient();
-        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.AccessToken);
-    var response = await client.GetAsync($"{RuntimeCache.CurrentHomeserver}/_matrix/client/r0/rooms/{RoomId}/state");
+        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", RuntimeCache.CurrentHomeServer.AccessToken);
+    var response = await client.GetAsync($"{RuntimeCache.CurrentHomeServer.FullHomeServerDomain}/_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 6b5eb77..97a1c44 100644
--- a/MatrixRoomUtils.Web/Pages/UserImportPage.razor
+++ b/MatrixRoomUtils.Web/Pages/UserImportPage.razor
@@ -1,10 +1,11 @@
 @page "/ImportUsers"
-@using MatrixRoomUtils.Authentication
 @using System.Text.Json
+@using MatrixRoomUtils.Core
+@using MatrixRoomUtils.Core.Authentication
 @inject ILocalStorageService LocalStorage
 <h3>Login</h3>
 
-<InputFile OnChange="@FileChanged"></InputFile>
+<InputFile OnChange="@FileChanged" accept=".tsv"></InputFile>
 <br/>
 <button @onclick="Login">Login</button>
 <br/><br/>
@@ -13,7 +14,7 @@
 <table border="1">
     @foreach (var (homeserver, username, password) in records)
     {
-        <tr style="background-color: @(LocalStorageWrapper.LoginSessions.Any(x => x.Value.LoginResponse.UserId == $"@{username}:{homeserver}") ? "green" : "unset")">
+        <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>
@@ -31,7 +32,7 @@
     {
         foreach (var (homeserver, username, password) in records)
         {
-            if(LocalStorageWrapper.LoginSessions.Any(x => x.Value.LoginResponse.UserId == $"@{username}:{homeserver}")) continue;
+            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}!");
 
@@ -40,8 +41,9 @@
                 LoginResponse = result
             };
             userinfo.Profile = await MatrixAuth.GetProfile(result.HomeServer, result.UserId);
+            RuntimeCache.LastUsedToken = result.AccessToken;
 
-            LocalStorageWrapper.LoginSessions.Add(result.AccessToken, userinfo);
+            RuntimeCache.LoginSessions.Add(result.AccessToken, userinfo);
             StateHasChanged();
         }
         
diff --git a/MatrixRoomUtils.Web/Program.cs b/MatrixRoomUtils.Web/Program.cs
index 410a98f..f83f008 100644
--- a/MatrixRoomUtils.Web/Program.cs
+++ b/MatrixRoomUtils.Web/Program.cs
@@ -1,7 +1,6 @@
 using System.Text.Json;
 using System.Text.Json.Serialization;
 using Blazored.LocalStorage;using MatrixRoomUtils;
-using MatrixRoomUtils.StateEventTypes;
 using Microsoft.AspNetCore.Components.Web;
 using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
 using MatrixRoomUtils.Web;
diff --git a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
index d0fb2f0..08161b2 100644
--- a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
+++ b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
@@ -1,44 +1,45 @@
-@using MatrixRoomUtils.Authentication
 @using MatrixRoomUtils.Web.Classes
 @using System.Text.Json
 @using Blazored.LocalStorage
-@using MatrixRoomUtils.Extensions
+@using MatrixRoomUtils.Core
+@using MatrixRoomUtils.Core.Extensions
 @using Index = MatrixRoomUtils.Web.Pages.Index
+@using System.ComponentModel.DataAnnotations
 @inject ILocalStorageService LocalStorage
 @inject NavigationManager NavigationManager
 
 <div style="margin-bottom: 1em;">
     <img style="border-radius: 50%; height: 3em; width: 3em;" src="@_avatarUrl"/>
-    <span style="margin-left: 1em;"><input type="radio" name="csa" checked="@(RuntimeCache.AccessToken == User.AccessToken)" onclick="@SetCurrent" style="text-decoration-line: unset;"/> <b>@User.Profile.DisplayName</b> on <b>@User.LoginResponse.HomeServer</b></span>
+    <span style="margin-left: 1em;"><input type="radio" name="csa" checked="@(RuntimeCache.LastUsedToken == User.AccessToken)" onclick="@SetCurrent" style="text-decoration-line: unset;"/> <b>@User.Profile.DisplayName</b> on <b>@User.LoginResponse.HomeServer</b></span>
     <a href="#" onclick="@RemoveUser">Remove</a>
 </div>
 
 @code {
+
     [Parameter]
-    public UserInfo User { get; set; }
+    public UserInfo User { get; set; } = null!;
     
     private string _avatarUrl { get; set; }
-    private bool _removed { get; set; } = false;
 
     protected override async Task OnInitializedAsync()
     {
-        if(User.Profile.AvatarUrl != null && User.Profile.AvatarUrl != "")
-            _avatarUrl = await User.Profile.AvatarUrl.GetMediaUrl();
+        if (User.Profile.AvatarUrl != null && User.Profile.AvatarUrl != "")
+            _avatarUrl = await (await new AuthenticatedHomeServer(User.LoginResponse.UserId, User.AccessToken, User.LoginResponse.HomeServer).Configure()).ResolveMediaUri(User.Profile.AvatarUrl);
         else _avatarUrl = "https://api.dicebear.com/6.x/identicon/svg?seed=" + User.LoginResponse.UserId;
         await base.OnInitializedAsync();
     }
 
     private async Task RemoveUser()
     {
+        Console.WriteLine(User.ToJson());
         RuntimeCache.LoginSessions.Remove(User.AccessToken);
         await LocalStorageWrapper.ReloadLocalStorage(LocalStorage);
-        _removed = true;
         
         StateHasChanged();
     }
     private async Task SetCurrent()
     {
-        RuntimeCache.AccessToken = User.AccessToken;
+        RuntimeCache.LastUsedToken = User.AccessToken;
         //RuntimeCache.CurrentHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(LocalStorageWrapper.LoginSessions[Token].LoginResponse.HomeServer);
         await LocalStorageWrapper.ReloadLocalStorage(LocalStorage);
         
diff --git a/MatrixRoomUtils.Web/Shared/LogView.razor b/MatrixRoomUtils.Web/Shared/LogView.razor
index fbe5264..f60f271 100644
--- a/MatrixRoomUtils.Web/Shared/LogView.razor
+++ b/MatrixRoomUtils.Web/Shared/LogView.razor
@@ -1,15 +1,15 @@
 @using System.Text
 <u>Logs</u><br/>
 <pre>
-    @sb
+    @_stringBuilder
 </pre>
 
 @code {
-    StringBuilder sb = new();
+    StringBuilder _stringBuilder = new();
     protected override void OnInitialized()
     {
         //intecept stdout with textwriter to get logs
-        var sw = new StringWriter(sb);
+        var sw = new StringWriter(_stringBuilder);
         Console.SetOut(sw);
         Console.SetError(sw);
         //keep updated
@@ -19,12 +19,13 @@
             while (true)
             {
                 await Task.Delay(100);
-                if (sb.Length != length)
+                if (_stringBuilder.Length != length)
                 {
                     StateHasChanged();
-                    length = sb.Length;
+                    length = _stringBuilder.Length;
                 }
             }
+    // ReSharper disable once FunctionNeverReturns - This is intentional behavior
         });
         base.OnInitialized();
     }
diff --git a/MatrixRoomUtils.Web/Shared/MainLayout.razor b/MatrixRoomUtils.Web/Shared/MainLayout.razor
index 055cec7..4aa01c6 100644
--- a/MatrixRoomUtils.Web/Shared/MainLayout.razor
+++ b/MatrixRoomUtils.Web/Shared/MainLayout.razor
@@ -1,6 +1,4 @@
 @inherits LayoutComponentBase
-@inject ILocalStorageService LocalStorage
-@inject NavigationManager NavigationManager
 
 <div class="page">
     <div class="sidebar">
@@ -9,7 +7,8 @@
 
     <main>
         <div class="top-row px-4">
-            <a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
+            <a href="https://git.rory.gay/MatrixRoomUtils.git/" target="_blank">Git</a>
+            <a href="https://matrix.to/#/%23mru%3Arory.gay?via=rory.gay&via=matrix.org&via=feline.support" target="_blank">Matrix</a>
         </div>
 
         <article class="content px-4">
diff --git a/MatrixRoomUtils.Web/_Imports.razor b/MatrixRoomUtils.Web/_Imports.razor
index dd81444..a558b8f 100644
--- a/MatrixRoomUtils.Web/_Imports.razor
+++ b/MatrixRoomUtils.Web/_Imports.razor
@@ -1,6 +1,7 @@
 @using System.Net.Http
 @using System.Net.Http.Json
 @using Blazored.LocalStorage
+@using MatrixRoomUtils.Core
 @using Microsoft.AspNetCore.Components.Forms
 @using Microsoft.AspNetCore.Components.Routing
 @using Microsoft.AspNetCore.Components.Web
@@ -12,6 +13,7 @@
 @using MatrixRoomUtils.Web.Shared
 
 @inject ILocalStorageService LocalStorage
+@inject NavigationManager NavigationManager
 
 @code
 {