From ed2205972a7b7d6fdd4563c3775a83616920597a Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 19 Jun 2023 02:36:32 +0200 Subject: Working sync --- MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs | 17 ++++++++--------- .../Classes/SessionStorageProviderService.cs | 12 ++++++++++++ MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj | 4 ++-- MatrixRoomUtils.Web/Pages/LoginPage.razor | 2 +- MatrixRoomUtils.Web/Program.cs | 8 +++----- MatrixRoomUtils.Web/SessionStorageProviderService.cs | 5 ----- .../Shared/IndexComponents/IndexUserItem.razor | 2 +- MatrixRoomUtils.Web/Shared/InlineUserItem.razor | 2 +- MatrixRoomUtils.Web/Shared/UserListItem.razor | 2 +- 9 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs delete mode 100644 MatrixRoomUtils.Web/SessionStorageProviderService.cs (limited to 'MatrixRoomUtils.Web') diff --git a/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs b/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs index b7da78a..878eca4 100644 --- a/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs +++ b/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs @@ -10,19 +10,18 @@ public class LocalStorageWrapper { //some basic logic public static async Task InitialiseRuntimeVariables(ILocalStorageService localStorage) { //RuntimeCache stuff - async Task Save() => await SaveToLocalStorage(localStorage); - async Task SaveObject(string key, object obj) => await localStorage.SetItemAsync(key, obj); - async Task RemoveObject(string key) => await localStorage.RemoveItemAsync(key); - - RuntimeCache.Save = Save; - RuntimeCache.SaveObject = SaveObject; - RuntimeCache.RemoveObject = RemoveObject; + // async Task Save() => await SaveToLocalStorage(localStorage); + // async Task SaveObject(string key, object obj) => await localStorage.SetItemAsync(key, obj); + // async Task RemoveObject(string key) => await localStorage.RemoveItemAsync(key); + // + // RuntimeCache.Save = Save; + // RuntimeCache.SaveObject = SaveObject; + // RuntimeCache.RemoveObject = RemoveObject; if (RuntimeCache.LastUsedToken != null) { 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(); + RuntimeCache.CurrentHomeServer = await new AuthenticatedHomeServer(RuntimeCache.LoginSessions[RuntimeCache.LastUsedToken].LoginResponse.HomeServer, RuntimeCache.LastUsedToken, TODO).Configure(); Console.WriteLine("Created authenticated home server"); } } diff --git a/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs b/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs new file mode 100644 index 0000000..4a9c7d1 --- /dev/null +++ b/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs @@ -0,0 +1,12 @@ +using Blazored.SessionStorage; +using MatrixRoomUtils.Core.Interfaces.Services; + +namespace MatrixRoomUtils.Web; + +public class SessionStorageProviderService : IStorageProvider { + private readonly ISessionStorageService _sessionStorage; + + public SessionStorageProviderService(ISessionStorageService sessionStorage) { + _sessionStorage = sessionStorage; + } +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj index 33fb062..4bb7aeb 100644 --- a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj +++ b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/MatrixRoomUtils.Web/Pages/LoginPage.razor b/MatrixRoomUtils.Web/Pages/LoginPage.razor index 16fdd24..3b78817 100644 --- a/MatrixRoomUtils.Web/Pages/LoginPage.razor +++ b/MatrixRoomUtils.Web/Pages/LoginPage.razor @@ -52,7 +52,7 @@ var userinfo = new UserInfo { LoginResponse = result }; - userinfo.Profile = await (await new AuthenticatedHomeServer(result.UserId, result.AccessToken, result.HomeServer).Configure()).GetProfile(result.UserId); + userinfo.Profile = await (await new AuthenticatedHomeServer(result.HomeServer, result.AccessToken, TODO).Configure()).GetProfile(result.UserId); RuntimeCache.LastUsedToken = result.AccessToken; RuntimeCache.LoginSessions.Add(result.AccessToken, userinfo); diff --git a/MatrixRoomUtils.Web/Program.cs b/MatrixRoomUtils.Web/Program.cs index 11e7f19..b106543 100644 --- a/MatrixRoomUtils.Web/Program.cs +++ b/MatrixRoomUtils.Web/Program.cs @@ -32,12 +32,10 @@ builder.Services.AddBlazoredSessionStorage(config => { config.JsonSerializerOptions.WriteIndented = false; }); -builder.Services.AddScoped(); -builder.Services.AddSingleton(); -builder.Services.AddSingleton(x => +builder.Services.AddScoped(x => new( - x.GetRequiredService(), - x.GetRequiredService() + cacheStorageProvider: new SessionStorageProviderService(x.GetRequiredService()), + dataStorageProvider: new LocalStorageProviderService(x.GetRequiredService()) ) ); diff --git a/MatrixRoomUtils.Web/SessionStorageProviderService.cs b/MatrixRoomUtils.Web/SessionStorageProviderService.cs deleted file mode 100644 index d6bffe6..0000000 --- a/MatrixRoomUtils.Web/SessionStorageProviderService.cs +++ /dev/null @@ -1,5 +0,0 @@ -using MatrixRoomUtils.Core.Interfaces.Services; - -namespace MatrixRoomUtils.Web; - -public class SessionStorageProviderService : IStorageProvider { } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor index 1fc70f2..8ab44fb 100644 --- a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor +++ b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor @@ -22,7 +22,7 @@ private int _roomCount { get; set; } = 0; protected override async Task OnInitializedAsync() { - var hs = await new AuthenticatedHomeServer(User.LoginResponse.UserId, User.AccessToken, User.LoginResponse.HomeServer).Configure(); + var hs = await new AuthenticatedHomeServer(User.LoginResponse.HomeServer, User.AccessToken, TODO).Configure(); if (User.Profile.AvatarUrl != null && User.Profile.AvatarUrl != "") _avatarUrl = hs.ResolveMediaUri(User.Profile.AvatarUrl); else _avatarUrl = "https://api.dicebear.com/6.x/identicon/svg?seed=" + User.LoginResponse.UserId; diff --git a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor index 9833c62..43a4111 100644 --- a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor +++ b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor @@ -36,7 +36,7 @@ await _semaphoreSlim.WaitAsync(); - var hs = await new AuthenticatedHomeServer(RuntimeCache.CurrentHomeServer.UserId, RuntimeCache.CurrentHomeServer.AccessToken, RuntimeCache.CurrentHomeServer.HomeServerDomain).Configure(); + var hs = await new AuthenticatedHomeServer(RuntimeCache.CurrentHomeServer.HomeServerDomain, RuntimeCache.CurrentHomeServer.AccessToken, TODO).Configure(); if (User == null) { if (UserId == null) { diff --git a/MatrixRoomUtils.Web/Shared/UserListItem.razor b/MatrixRoomUtils.Web/Shared/UserListItem.razor index 43c71ab..b99671a 100644 --- a/MatrixRoomUtils.Web/Shared/UserListItem.razor +++ b/MatrixRoomUtils.Web/Shared/UserListItem.razor @@ -33,7 +33,7 @@ await _semaphoreSlim.WaitAsync(); - var hs = await new AuthenticatedHomeServer(RuntimeCache.CurrentHomeServer.UserId, RuntimeCache.CurrentHomeServer.AccessToken, RuntimeCache.CurrentHomeServer.HomeServerDomain).Configure(); + var hs = await new AuthenticatedHomeServer(RuntimeCache.CurrentHomeServer.HomeServerDomain, RuntimeCache.CurrentHomeServer.AccessToken, TODO).Configure(); if (User == null) { if (UserId == null) { -- cgit 1.4.1