about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Classes
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-01-24 02:31:56 +0100
committerRory& <root@rory.gay>2024-01-24 17:05:25 +0100
commit03313562d21d5db9bf6a14ebbeab80e06c883d3a (patch)
treee000546a2ee8e6a886a7ed9fd01ad674178fb7cb /MatrixRoomUtils.Web/Classes
parentMake RMU installable (diff)
downloadMatrixUtils-03313562d21d5db9bf6a14ebbeab80e06c883d3a.tar.xz
MRU->RMU, fixes, cleanup
Diffstat (limited to 'MatrixRoomUtils.Web/Classes')
-rw-r--r--MatrixRoomUtils.Web/Classes/Constants/RoomConstants.cs6
-rw-r--r--MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs28
-rw-r--r--MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs98
-rw-r--r--MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs92
-rw-r--r--MatrixRoomUtils.Web/Classes/RoomCreationTemplates/IRoomCreationTemplate.cs8
-rw-r--r--MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs28
-rw-r--r--MatrixRoomUtils.Web/Classes/UserAuth.cs15
7 files changed, 0 insertions, 275 deletions
diff --git a/MatrixRoomUtils.Web/Classes/Constants/RoomConstants.cs b/MatrixRoomUtils.Web/Classes/Constants/RoomConstants.cs
deleted file mode 100644

index b145cd0..0000000 --- a/MatrixRoomUtils.Web/Classes/Constants/RoomConstants.cs +++ /dev/null
@@ -1,6 +0,0 @@ -namespace MatrixRoomUtils.Web.Classes.Constants; - -public class RoomConstants { - public static readonly string[] DangerousRoomVersions = { "1", "8" }; - public const string RecommendedRoomVersion = "10"; -} diff --git a/MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs b/MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs deleted file mode 100644
index 51aee12..0000000 --- a/MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs +++ /dev/null
@@ -1,28 +0,0 @@ -using Blazored.LocalStorage; -using LibMatrix.Interfaces.Services; - -namespace MatrixRoomUtils.Web.Classes; - -public class LocalStorageProviderService : IStorageProvider { - private readonly ILocalStorageService _localStorageService; - - public LocalStorageProviderService(ILocalStorageService localStorageService) { - _localStorageService = localStorageService; - } - - Task IStorageProvider.SaveAllChildrenAsync<T>(string key, T value) { - throw new NotImplementedException(); - } - - Task<T?> IStorageProvider.LoadAllChildrenAsync<T>(string key) where T : default => throw new NotImplementedException(); - - async Task IStorageProvider.SaveObjectAsync<T>(string key, T value) => await _localStorageService.SetItemAsync(key, value); - - async Task<T?> IStorageProvider.LoadObjectAsync<T>(string key) where T : default => await _localStorageService.GetItemAsync<T>(key); - - async Task<bool> IStorageProvider.ObjectExistsAsync(string key) => await _localStorageService.ContainKeyAsync(key); - - async Task<List<string>> IStorageProvider.GetAllKeysAsync() => (await _localStorageService.KeysAsync()).ToList(); - - async Task IStorageProvider.DeleteObjectAsync(string key) => await _localStorageService.RemoveItemAsync(key); -} diff --git a/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs b/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs deleted file mode 100644
index fb3b041..0000000 --- a/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs +++ /dev/null
@@ -1,98 +0,0 @@ -using LibMatrix; -using LibMatrix.Homeservers; -using LibMatrix.Services; -using Microsoft.AspNetCore.Components; - -namespace MatrixRoomUtils.Web.Classes; - -public class MRUStorageWrapper(TieredStorageService storageService, HomeserverProviderService homeserverProviderService, NavigationManager navigationManager) { - public async Task<List<UserAuth>?> GetAllTokens() { - return await storageService.DataStorageProvider.LoadObjectAsync<List<UserAuth>>("mru.tokens") ?? - new List<UserAuth>(); - } - - public async Task<UserAuth?> GetCurrentToken() { - var currentToken = await storageService.DataStorageProvider.LoadObjectAsync<UserAuth>("token"); - var allTokens = await GetAllTokens(); - if (allTokens is null or { Count: 0 }) { - await SetCurrentToken(null); - return null; - } - - if (currentToken is null) { - await SetCurrentToken(currentToken = allTokens[0]); - } - - if (!allTokens.Any(x => x.AccessToken == currentToken.AccessToken)) { - await SetCurrentToken(currentToken = allTokens[0]); - } - - return currentToken; - } - - public async Task AddToken(UserAuth UserAuth) { - var tokens = await GetAllTokens() ?? new List<UserAuth>(); - - tokens.Add(UserAuth); - await storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); - } - - private async Task<AuthenticatedHomeserverGeneric?> GetCurrentSession() { - var token = await GetCurrentToken(); - if (token == null) { - return null; - } - - return await homeserverProviderService.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken, token.Proxy); - } - - public async Task<AuthenticatedHomeserverGeneric?> GetSession(UserAuth userAuth) { - return await homeserverProviderService.GetAuthenticatedWithToken(userAuth.Homeserver, userAuth.AccessToken, userAuth.Proxy); - } - - public async Task<AuthenticatedHomeserverGeneric?> GetCurrentSessionOrNavigate() { - AuthenticatedHomeserverGeneric? session = null; - - try { - //catch if the token is invalid - session = await GetCurrentSession(); - } - catch (MatrixException e) { - if (e.ErrorCode == "M_UNKNOWN_TOKEN") { - var token = await GetCurrentToken(); - navigationManager.NavigateTo("/InvalidSession?ctx=" + token.AccessToken); - return null; - } - - throw; - } - - if (session is null) { - navigationManager.NavigateTo("/Login"); - } - - return session; - } - - public class Settings { - public DeveloperSettings DeveloperSettings { get; set; } = new(); - } - - public class DeveloperSettings { - public bool EnableLogViewers { get; set; } - public bool EnableConsoleLogging { get; set; } = true; - public bool EnablePortableDevtools { get; set; } - } - - public async Task RemoveToken(UserAuth auth) { - var tokens = await GetAllTokens(); - if (tokens == null) { - return; - } - - tokens.RemoveAll(x => x.AccessToken == auth.AccessToken); - await storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); - } - - public async Task SetCurrentToken(UserAuth? auth) => await storageService.DataStorageProvider.SaveObjectAsync("token", auth); -} diff --git a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs deleted file mode 100644
index a6831d4..0000000 --- a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs +++ /dev/null
@@ -1,92 +0,0 @@ -using System.Text.Json.Nodes; -using LibMatrix; -using LibMatrix.EventTypes.Spec.State; -using LibMatrix.EventTypes.Spec.State.RoomInfo; -using LibMatrix.Responses; - -namespace MatrixRoomUtils.Web.Classes.RoomCreationTemplates; - -public class DefaultRoomCreationTemplate : IRoomCreationTemplate { - public string Name => "Default"; - - public CreateRoomRequest CreateRoomRequest => - new() { - Name = "My new room", - RoomAliasName = "myroom", - InitialState = new List<StateEvent> { - new() { - Type = "m.room.history_visibility", - TypedContent = new RoomHistoryVisibilityEventContent() { - HistoryVisibility = "world_readable" - } - }, - new() { - Type = "m.room.guest_access", - TypedContent = new RoomGuestAccessEventContent { - GuestAccess = "can_join" - } - }, - new() { - Type = "m.room.join_rules", - TypedContent = new RoomJoinRulesEventContent { - JoinRule = RoomJoinRulesEventContent.JoinRules.Public - } - }, - new() { - Type = "m.room.server_acl", - TypedContent = new RoomServerACLEventContent() { - Allow = new List<string>() { "*" }, - Deny = new List<string>(), - AllowIpLiterals = false - } - }, - new() { - Type = "m.room.avatar", - TypedContent = new RoomAvatarEventContent { - Url = "mxc://feline.support/UKNhEyrVsrAbYteVvZloZcFj" - } - } - }, - Visibility = "public", - PowerLevelContentOverride = new RoomPowerLevelEventContent { - UsersDefault = 0, - EventsDefault = 100, - StateDefault = 50, - Invite = 0, - Redact = 50, - Kick = 50, - Ban = 50, - NotificationsPl = new RoomPowerLevelEventContent.NotificationsPL { - 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() { - // { RuntimeCache.CurrentHomeserver.UserId, 100 } - //TODO: re-implement this - } - }, - CreationContent = new JsonObject { - { - "type", null - } - } - }; -} diff --git a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/IRoomCreationTemplate.cs b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/IRoomCreationTemplate.cs deleted file mode 100644
index 42503f7..0000000 --- a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/IRoomCreationTemplate.cs +++ /dev/null
@@ -1,8 +0,0 @@ -using LibMatrix.Responses; - -namespace MatrixRoomUtils.Web.Classes.RoomCreationTemplates; - -public interface IRoomCreationTemplate { - public CreateRoomRequest CreateRoomRequest { get; } - public string Name { get; } -} diff --git a/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs b/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs deleted file mode 100644
index a923015..0000000 --- a/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs +++ /dev/null
@@ -1,28 +0,0 @@ -using Blazored.SessionStorage; -using LibMatrix.Interfaces.Services; - -namespace MatrixRoomUtils.Web.Classes; - -public class SessionStorageProviderService : IStorageProvider { - private readonly ISessionStorageService _sessionStorageService; - - public SessionStorageProviderService(ISessionStorageService sessionStorage) { - _sessionStorageService = sessionStorage; - } - - Task IStorageProvider.SaveAllChildrenAsync<T>(string key, T value) { - throw new NotImplementedException(); - } - - Task<T?> IStorageProvider.LoadAllChildrenAsync<T>(string key) where T : default => throw new NotImplementedException(); - - async Task IStorageProvider.SaveObjectAsync<T>(string key, T value) => await _sessionStorageService.SetItemAsync(key, value); - - async Task<T?> IStorageProvider.LoadObjectAsync<T>(string key) where T : default => await _sessionStorageService.GetItemAsync<T>(key); - - async Task<bool> IStorageProvider.ObjectExistsAsync(string key) => await _sessionStorageService.ContainKeyAsync(key); - - async Task<List<string>> IStorageProvider.GetAllKeysAsync() => (await _sessionStorageService.KeysAsync()).ToList(); - - async Task IStorageProvider.DeleteObjectAsync(string key) => await _sessionStorageService.RemoveItemAsync(key); -} diff --git a/MatrixRoomUtils.Web/Classes/UserAuth.cs b/MatrixRoomUtils.Web/Classes/UserAuth.cs deleted file mode 100644
index e6f0954..0000000 --- a/MatrixRoomUtils.Web/Classes/UserAuth.cs +++ /dev/null
@@ -1,15 +0,0 @@ -using LibMatrix.Responses; - -namespace MatrixRoomUtils.Web.Classes; - -public class UserAuth : LoginResponse { - public UserAuth() { } - public UserAuth(LoginResponse login) { - Homeserver = login.Homeserver; - UserId = login.UserId; - AccessToken = login.AccessToken; - DeviceId = login.DeviceId; - } - - public string? Proxy { get; set; } -}