From df9031c47f8e97d8e2df3177093271a458f27267 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 1 May 2023 02:43:32 +0200 Subject: Initial commit --- MatrixRoomUtils.Web/Classes/RuntimeStorage.cs | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 MatrixRoomUtils.Web/Classes/RuntimeStorage.cs (limited to 'MatrixRoomUtils.Web/Classes') diff --git a/MatrixRoomUtils.Web/Classes/RuntimeStorage.cs b/MatrixRoomUtils.Web/Classes/RuntimeStorage.cs new file mode 100644 index 0000000..d9d626f --- /dev/null +++ b/MatrixRoomUtils.Web/Classes/RuntimeStorage.cs @@ -0,0 +1,55 @@ +using Blazored.LocalStorage; +using MatrixRoomUtils.Authentication; +using MatrixRoomUtils.Responses; + +namespace MatrixRoomUtils.Web.Classes; + +public class RuntimeStorage +{ + public static bool WasLoaded = false; + public static UserInfo? CurrentUserInfo { get; set; } + public static string AccessToken { get; set; } + public static string? CurrentHomeserver { get; set; } + + public static List AccessTokens { get; set; } = new(); + //public static AppSettings AppSettings { get; set; } = new(); + + public static Dictionary UsersCache { get; set; } = new(); + + public static Dictionary HomeserverResolutionCache { get; set; } = new(); + + + //some basic logic + public static async Task LoadFromLocalStorage(ILocalStorageService localStorage) + { + AccessToken = await localStorage.GetItemAsync("rory.matrixroomutils.token"); + CurrentHomeserver = await localStorage.GetItemAsync("rory.matrixroomutils.current_homeserver"); + AccessTokens = await localStorage.GetItemAsync>("rory.matrixroomutils.tokens") ?? new(); + UsersCache = await localStorage.GetItemAsync>("rory.matrixroomutils.user_cache") ?? new(); + HomeserverResolutionCache = await localStorage.GetItemAsync>("rory.matrixroomutils.homeserver_resolution_cache") ?? new(); + WasLoaded = true; + } + + public static async Task SaveToLocalStorage(ILocalStorageService localStorage) + { + await localStorage.SetItemAsStringAsync("rory.matrixroomutils.token", AccessToken); + await localStorage.SetItemAsync("rory.matrixroomutils.current_homeserver", CurrentHomeserver); + await localStorage.SetItemAsync("rory.matrixroomutils.tokens", AccessTokens); + await localStorage.SetItemAsync("rory.matrixroomutils.user_cache", UsersCache); + await localStorage.SetItemAsync("rory.matrixroomutils.homeserver_resolution_cache", + HomeserverResolutionCache.DistinctBy(x => x.Key) + .ToDictionary(x => x.Key, x => x.Value)); + } +} + +public class UserInfo +{ + public ProfileResponse Profile { get; set; } = new(); + public LoginResponse LoginResponse { get; set; } +} + +public class HomeServerResolutionResult +{ + public string Result { get; set; } + public DateTime ResolutionTime { get; set; } +} \ No newline at end of file -- cgit 1.5.1