diff options
Diffstat (limited to 'MatrixRoomUtils.Web/Classes')
4 files changed, 44 insertions, 28 deletions
diff --git a/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs b/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs index 14625fd..8ea85e9 100644 --- a/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs +++ b/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs @@ -1,4 +1,5 @@ using LibMatrix; +using LibMatrix.Homeservers; using LibMatrix.Responses; using LibMatrix.Services; using Microsoft.AspNetCore.Components; @@ -20,13 +21,13 @@ public class MRUStorageWrapper { _navigationManager = navigationManager; } - public async Task<List<LoginResponse>?> GetAllTokens() { - return await _storageService.DataStorageProvider.LoadObjectAsync<List<LoginResponse>>("mru.tokens") ?? - new List<LoginResponse>(); + public async Task<List<UserAuth>?> GetAllTokens() { + return await _storageService.DataStorageProvider.LoadObjectAsync<List<UserAuth>>("mru.tokens") ?? + new List<UserAuth>(); } - public async Task<LoginResponse?> GetCurrentToken() { - var currentToken = await _storageService.DataStorageProvider.LoadObjectAsync<LoginResponse>("token"); + 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); @@ -44,14 +45,14 @@ public class MRUStorageWrapper { return currentToken; } - public async Task AddToken(LoginResponse loginResponse) { - var tokens = await GetAllTokens() ?? new List<LoginResponse>(); + public async Task AddToken(UserAuth UserAuth) { + var tokens = await GetAllTokens() ?? new List<UserAuth>(); - tokens.Add(loginResponse); + tokens.Add(UserAuth); await _storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); } - private async Task<AuthenticatedHomeServer?> GetCurrentSession() { + private async Task<AuthenticatedHomeserverGeneric?> GetCurrentSession() { var token = await GetCurrentToken(); if (token == null) { return null; @@ -60,8 +61,8 @@ public class MRUStorageWrapper { return await _homeserverProviderService.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken); } - public async Task<AuthenticatedHomeServer?> GetCurrentSessionOrNavigate() { - AuthenticatedHomeServer? session = null; + public async Task<AuthenticatedHomeserverGeneric?> GetCurrentSessionOrNavigate() { + AuthenticatedHomeserverGeneric? session = null; try { //catch if the token is invalid @@ -94,7 +95,7 @@ public class MRUStorageWrapper { public bool EnablePortableDevtools { get; set; } } - public async Task RemoveToken(LoginResponse auth) { + public async Task RemoveToken(UserAuth auth) { var tokens = await GetAllTokens(); if (tokens == null) { return; @@ -104,5 +105,5 @@ public class MRUStorageWrapper { await _storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); } - public async Task SetCurrentToken(LoginResponse? auth) => await _storageService.DataStorageProvider.SaveObjectAsync("token", auth); + 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 index bb2eab9..3f67f33 100644 --- a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs +++ b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs @@ -2,7 +2,6 @@ using System.Text.Json.Nodes; using LibMatrix; using LibMatrix.Responses; using LibMatrix.StateEventTypes.Spec; -using LibMatrix.StateEventTypes; namespace MatrixRoomUtils.Web.Classes.RoomCreationTemplates; @@ -16,39 +15,39 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { InitialState = new List<StateEvent> { new() { Type = "m.room.history_visibility", - TypedContent = new { - history_visibility = "world_readable" + TypedContent = new HistoryVisibilityEventContent() { + HistoryVisibility = "world_readable" } }, new() { Type = "m.room.guest_access", - TypedContent = new GuestAccessEventData { + TypedContent = new GuestAccessEventContent { GuestAccess = "can_join" } }, new() { Type = "m.room.join_rules", - TypedContent = new JoinRulesEventData { + TypedContent = new JoinRulesEventContent { JoinRule = "public" } }, new() { Type = "m.room.server_acl", - TypedContent = new { - allow = new[] { "*" }, - deny = Array.Empty<string>(), - allow_ip_literals = false + TypedContent = new ServerACLEventContent() { + Allow = new List<string>() { "*" }, + Deny = new List<string>(), + AllowIpLiterals = false } }, new() { Type = "m.room.avatar", - TypedContent = new RoomAvatarEventData { + TypedContent = new RoomAvatarEventContent { Url = "mxc://feline.support/UKNhEyrVsrAbYteVvZloZcFj" } } }, Visibility = "public", - PowerLevelContentOverride = new RoomPowerLevelEventData { + PowerLevelContentOverride = new RoomPowerLevelEventContent { UsersDefault = 0, EventsDefault = 100, StateDefault = 50, @@ -56,10 +55,10 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { Redact = 50, Kick = 50, Ban = 50, - NotificationsPl = new RoomPowerLevelEventData.NotificationsPL { + NotificationsPl = new RoomPowerLevelEventContent.NotificationsPL { Room = 50 }, - Events = new Dictionary<string, int> { + Events = new() { { "im.vector.modular.widgets", 50 }, { "io.element.voice_broadcast_info", 50 }, { "m.reaction", 100 }, @@ -78,7 +77,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { { "org.matrix.msc3401.call", 50 }, { "org.matrix.msc3401.call.member", 50 } }, - Users = new Dictionary<string, int> { + Users = new() { // { RuntimeCache.CurrentHomeServer.UserId, 100 } //TODO: re-implement this } diff --git a/MatrixRoomUtils.Web/Classes/RoomInfo.cs b/MatrixRoomUtils.Web/Classes/RoomInfo.cs index 111bfe0..0e21871 100644 --- a/MatrixRoomUtils.Web/Classes/RoomInfo.cs +++ b/MatrixRoomUtils.Web/Classes/RoomInfo.cs @@ -1,4 +1,5 @@ using LibMatrix; +using LibMatrix.Interfaces; using LibMatrix.Responses; using LibMatrix.RoomTypes; @@ -17,7 +18,7 @@ public class RoomInfo { StateKey = stateKey }; try { - @event.TypedContent = await Room.GetStateAsync<object>(type, stateKey); + @event.TypedContent = await Room.GetStateAsync<EventContent>(type, stateKey); } catch (MatrixException e) { if (e is { ErrorCode: "M_NOT_FOUND" }) @event.TypedContent = default!; diff --git a/MatrixRoomUtils.Web/Classes/UserAuth.cs b/MatrixRoomUtils.Web/Classes/UserAuth.cs new file mode 100644 index 0000000..e6f0954 --- /dev/null +++ b/MatrixRoomUtils.Web/Classes/UserAuth.cs @@ -0,0 +1,15 @@ +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; } +} |