diff options
45 files changed, 198 insertions, 204 deletions
diff --git a/LibMatrix b/LibMatrix -Subproject 15d2ed6a992619b72ffd692a37e93f53ae948ab +Subproject cb8846a7a3310f8513989da5aadb5202f048a1b diff --git a/MatrixRoomUtils.Desktop/App.axaml.cs b/MatrixRoomUtils.Desktop/App.axaml.cs index 20f2a3c..e0b50a5 100644 --- a/MatrixRoomUtils.Desktop/App.axaml.cs +++ b/MatrixRoomUtils.Desktop/App.axaml.cs @@ -20,12 +20,12 @@ public partial class App : Application { services.AddSingleton<MRUDesktopConfiguration>(); services.AddSingleton<SentryService>(); services.AddSingleton<TieredStorageService>(x => - new( + new TieredStorageService( cacheStorageProvider: new FileStorageProvider(x.GetService<MRUDesktopConfiguration>().CacheStoragePath), dataStorageProvider: new FileStorageProvider(x.GetService<MRUDesktopConfiguration>().DataStoragePath) ) ); - services.AddSingleton(new RoryLibMatrixConfiguration() { + services.AddSingleton(new RoryLibMatrixConfiguration { AppName = "MatrixRoomUtils.Desktop" }); services.AddRoryLibMatrixServices(); diff --git a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml index e0812ec..c773b8d 100644 --- a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml +++ b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml @@ -3,7 +3,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="MatrixRoomUtils.Desktop.NavigationStack"> + x:Class="MatrixRoomUtils.Desktop.Components.NavigationStack"> <DockPanel x:Name="dock"> <StackPanel x:Name="navPanel"></StackPanel> <UserControl x:Name="content"></UserControl> diff --git a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs index f4e0fed..d6343e2 100644 --- a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs +++ b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs @@ -1,8 +1,7 @@ -using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; -namespace MatrixRoomUtils.Desktop; +namespace MatrixRoomUtils.Desktop.Components; public partial class NavigationStack : UserControl { public NavigationStack() { @@ -20,7 +19,7 @@ public partial class NavigationStack : UserControl { Button btn = new() { Content = item.Name }; - btn.Click += (sender, args) => { + btn.Click += (_, _) => { PopTo(_stack.IndexOf(item)); buildView(); }; @@ -41,7 +40,7 @@ public partial class NavigationStack : UserControl { public NavigationStackItem? Current => _stack.LastOrDefault(); public void Push(string name, UserControl view) { - _stack.Add(new NavigationStackItem() { + _stack.Add(new NavigationStackItem { Name = name, View = view }); diff --git a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml index c80ef2f..09fe52b 100644 --- a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml +++ b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml @@ -3,7 +3,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="250" d:DesignHeight="32" - x:Class="MatrixRoomUtils.Desktop.RoomListEntry"> + x:Class="MatrixRoomUtils.Desktop.Components.RoomListEntry"> <StackPanel Orientation="Horizontal"> <Image MaxWidth="64" x:Name="RoomIcon"></Image> <Label x:Name="RoomName"></Label> diff --git a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs index f29db63..359deb3 100644 --- a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs +++ b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs @@ -5,10 +5,9 @@ using LibMatrix; using LibMatrix.Helpers; using LibMatrix.Services; using LibMatrix.StateEventTypes.Spec; -using MatrixRoomUtils.Web.Classes; using Microsoft.Extensions.DependencyInjection; -namespace MatrixRoomUtils.Desktop; +namespace MatrixRoomUtils.Desktop.Components; public partial class RoomListEntry : UserControl { private readonly IServiceScopeFactory _serviceScopeFactory; @@ -29,7 +28,7 @@ public partial class RoomListEntry : UserControl { private async Task GetRoomName() { try { var nameEvent = await _roomInfo.GetStateEvent("m.room.name"); - if (nameEvent is not null && nameEvent.TypedContent is RoomNameEventData nameData) + if (nameEvent?.TypedContent is RoomNameEventData nameData) RoomName.Content = nameData.Name; } catch (MatrixException e) { @@ -41,7 +40,7 @@ public partial class RoomListEntry : UserControl { private async Task GetRoomIcon() { try { var avatarEvent = await _roomInfo.GetStateEvent("m.room.avatar"); - if (avatarEvent is not null && avatarEvent.TypedContent is RoomAvatarEventData avatarData) { + if (avatarEvent?.TypedContent is RoomAvatarEventData avatarData) { var mxcUrl = avatarData.Url; await using var svc = _serviceScopeFactory.CreateAsyncScope(); var hs = await svc.ServiceProvider.GetService<MRUStorageWrapper>().GetCurrentSessionOrPrompt(); diff --git a/MatrixRoomUtils.Desktop/FileStorageProvider.cs b/MatrixRoomUtils.Desktop/FileStorageProvider.cs index 36a3c7e..b3850b0 100644 --- a/MatrixRoomUtils.Desktop/FileStorageProvider.cs +++ b/MatrixRoomUtils.Desktop/FileStorageProvider.cs @@ -23,20 +23,24 @@ public class FileStorageProvider : IStorageProvider { } } - public async Task SaveObjectAsync<T>(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), ObjectExtensions.ToJson(value)); + public async Task SaveObjectAsync<T>(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), value?.ToJson()); public async Task<T?> LoadObjectAsync<T>(string key) => JsonSerializer.Deserialize<T>(await File.ReadAllTextAsync(Path.Join(TargetPath, key))); - public async Task<bool> ObjectExistsAsync(string key) => File.Exists(Path.Join(TargetPath, key)); + public Task<bool> ObjectExistsAsync(string key) => Task.FromResult(File.Exists(Path.Join(TargetPath, key))); - public async Task<List<string>> GetAllKeysAsync() => Directory.GetFiles(TargetPath).Select(Path.GetFileName).ToList(); + public Task<List<string>> GetAllKeysAsync() => Task.FromResult(Directory.GetFiles(TargetPath).Select(Path.GetFileName).ToList()); + + public Task DeleteObjectAsync(string key) { + File.Delete(Path.Join(TargetPath, key)); + return Task.CompletedTask; + } - public async Task DeleteObjectAsync(string key) => File.Delete(Path.Join(TargetPath, key)); public async Task SaveStreamAsync(string key, Stream stream) { Directory.CreateDirectory(Path.GetDirectoryName(Path.Join(TargetPath, key)) ?? throw new InvalidOperationException()); await using var fileStream = File.Create(Path.Join(TargetPath, key)); await stream.CopyToAsync(fileStream); } - public async Task<Stream?> LoadStreamAsync(string key) => File.Exists(Path.Join(TargetPath, key)) ? File.OpenRead(Path.Join(TargetPath, key)) : null; + public Task<Stream?> LoadStreamAsync(string key) => Task.FromResult<Stream?>(File.Exists(Path.Join(TargetPath, key)) ? File.OpenRead(Path.Join(TargetPath, key)) : null); } diff --git a/MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs b/MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs index 39c42cf..4f265ee 100644 --- a/MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs +++ b/MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs @@ -11,7 +11,7 @@ public class MRUDesktopConfiguration { public MRUDesktopConfiguration(ILogger<MRUDesktopConfiguration> logger, IConfiguration config, HostBuilderContext host) { _logger = logger; - logger.LogInformation($"Loading configuration for environment: {host.HostingEnvironment.EnvironmentName}..."); + logger.LogInformation("Loading configuration for environment: {}...", host.HostingEnvironment.EnvironmentName); config.GetSection("MRUDesktop").Bind(this); DataStoragePath = ExpandPath(DataStoragePath); CacheStoragePath = ExpandPath(CacheStoragePath); @@ -22,18 +22,18 @@ public class MRUDesktopConfiguration { public string? SentryDsn { get; set; } private static string ExpandPath(string path, bool retry = true) { - _logger.LogInformation($"Expanding path `{path}`"); + _logger.LogInformation("Expanding path `{}`", path); if (path.StartsWith("~")) { path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), path[1..]); } - Environment.GetEnvironmentVariables().Cast<DictionaryEntry>().OrderByDescending(x => x.Key.ToString().Length).ToList().ForEach(x => { + Environment.GetEnvironmentVariables().Cast<DictionaryEntry>().OrderByDescending(x => x.Key.ToString()!.Length).ToList().ForEach(x => { path = path.Replace($"${x.Key}", x.Value.ToString()); }); - _logger.LogInformation($"Expanded path to `{path}`"); - int tries = 0; + _logger.LogInformation("Expanded path to `{}`", path); + var tries = 0; while(retry && path.ContainsAnyOf("~$".Split())) { if(tries++ > 100) throw new Exception($"Path `{path}` contains unrecognised environment variables"); diff --git a/MatrixRoomUtils.Desktop/MRUStorageWrapper.cs b/MatrixRoomUtils.Desktop/MRUStorageWrapper.cs index 5444f24..2243092 100644 --- a/MatrixRoomUtils.Desktop/MRUStorageWrapper.cs +++ b/MatrixRoomUtils.Desktop/MRUStorageWrapper.cs @@ -4,31 +4,20 @@ using LibMatrix.Services; namespace MatrixRoomUtils.Desktop; -public class MRUStorageWrapper { - private readonly TieredStorageService _storageService; - private readonly HomeserverProviderService _homeserverProviderService; - - public MRUStorageWrapper( - TieredStorageService storageService, - HomeserverProviderService homeserverProviderService - ) { - _storageService = storageService; - _homeserverProviderService = homeserverProviderService; - } - +public class MRUStorageWrapper(TieredStorageService storageService, HomeserverProviderService homeserverProviderService) { public async Task<List<LoginResponse>?> GetAllTokens() { - if(!await _storageService.DataStorageProvider.ObjectExistsAsync("mru.tokens")) { + if(!await storageService.DataStorageProvider.ObjectExistsAsync("mru.tokens")) { return null; } - return await _storageService.DataStorageProvider.LoadObjectAsync<List<LoginResponse>>("mru.tokens") ?? + return await storageService.DataStorageProvider.LoadObjectAsync<List<LoginResponse>>("mru.tokens") ?? new List<LoginResponse>(); } public async Task<LoginResponse?> GetCurrentToken() { - if(!await _storageService.DataStorageProvider.ObjectExistsAsync("token")) { + if(!await storageService.DataStorageProvider.ObjectExistsAsync("token")) { return null; } - var currentToken = await _storageService.DataStorageProvider.LoadObjectAsync<LoginResponse>("token"); + var currentToken = await storageService.DataStorageProvider.LoadObjectAsync<LoginResponse>("token"); var allTokens = await GetAllTokens(); if (allTokens is null or { Count: 0 }) { await SetCurrentToken(null); @@ -47,13 +36,10 @@ public class MRUStorageWrapper { } public async Task AddToken(LoginResponse loginResponse) { - var tokens = await GetAllTokens(); - if (tokens == null) { - tokens = new List<LoginResponse>(); - } + var tokens = await GetAllTokens() ?? new List<LoginResponse>(); tokens.Add(loginResponse); - await _storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); + await storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); if(await GetCurrentToken() is null) await SetCurrentToken(loginResponse); } @@ -64,7 +50,7 @@ public class MRUStorageWrapper { return null; } - return await _homeserverProviderService.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken); + return await homeserverProviderService.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken); } public async Task<AuthenticatedHomeServer?> GetCurrentSessionOrPrompt() { @@ -87,7 +73,7 @@ public class MRUStorageWrapper { if (session is null) { // _navigationManager.NavigateTo("/Login"); var wnd = new LoginWindow(this); - wnd.ShowDialog(MainWindow.Instance); + await wnd.ShowDialog(MainWindow.Instance); while (wnd.IsVisible) await Task.Delay(100); session = await GetCurrentSession(); } @@ -112,16 +98,14 @@ public class MRUStorageWrapper { } tokens.RemoveAll(x => x.AccessToken == auth.AccessToken); - await _storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); + await storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); } - public async Task SetCurrentToken(LoginResponse? auth) { - _storageService.DataStorageProvider.SaveObjectAsync("token", auth); - } + public async Task SetCurrentToken(LoginResponse? auth) => await storageService.DataStorageProvider.SaveObjectAsync("token", auth); public async Task<LoginResponse?> Login(string homeserver, string username, string password) { try { - return await _homeserverProviderService.Login(homeserver, username, password); + return await homeserverProviderService.Login(homeserver, username, password); } catch (MatrixException e) { if (e.ErrorCode == "M_FORBIDDEN") { diff --git a/MatrixRoomUtils.Desktop/MainWindow.axaml b/MatrixRoomUtils.Desktop/MainWindow.axaml index 464fc77..dd807b5 100644 --- a/MatrixRoomUtils.Desktop/MainWindow.axaml +++ b/MatrixRoomUtils.Desktop/MainWindow.axaml @@ -3,6 +3,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:desktop="clr-namespace:MatrixRoomUtils.Desktop" + xmlns:components="clr-namespace:MatrixRoomUtils.Desktop.Components" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="MatrixRoomUtils.Desktop.MainWindow" Title="Rory&::MatrixRoomUtils"> @@ -11,5 +12,5 @@ <!-- <InvokeCommandAction Command="{Binding LoadedCommand}"></InvokeCommandAction> --> <!-- </EventTriggerBehavior> --> <!-- </Interaction.Behaviors> --> - <desktop:NavigationStack x:Name="windowContent"/> + <components:NavigationStack x:Name="windowContent"/> </Window> diff --git a/MatrixRoomUtils.Desktop/MainWindow.axaml.cs b/MatrixRoomUtils.Desktop/MainWindow.axaml.cs index 89f9d52..135542b 100644 --- a/MatrixRoomUtils.Desktop/MainWindow.axaml.cs +++ b/MatrixRoomUtils.Desktop/MainWindow.axaml.cs @@ -1,7 +1,6 @@ using Avalonia.Controls; using Avalonia.Data; using Avalonia.Interactivity; -using MatrixRoomUtils.Web.Classes; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/MatrixRoomUtils.Desktop/Program.cs b/MatrixRoomUtils.Desktop/Program.cs index f692e45..6e299eb 100644 --- a/MatrixRoomUtils.Desktop/Program.cs +++ b/MatrixRoomUtils.Desktop/Program.cs @@ -10,7 +10,7 @@ internal class Program { // SynchronizationContext-reliant code before AppMain is called: things aren't initialized // yet and stuff might break. // [STAThread] - public static async Task Main(string[] args) { + public static Task Main(string[] args) { try { BuildAvaloniaApp() .StartWithClassicDesktopLifetime(args); @@ -20,6 +20,8 @@ internal class Program { Console.WriteLine(e); throw; } + + return Task.CompletedTask; } // Avalonia configuration, don't remove; also used by visual designer. diff --git a/MatrixRoomUtils.Desktop/RoomInfo.cs b/MatrixRoomUtils.Desktop/RoomInfo.cs index fdd7d03..4e76247 100644 --- a/MatrixRoomUtils.Desktop/RoomInfo.cs +++ b/MatrixRoomUtils.Desktop/RoomInfo.cs @@ -2,7 +2,7 @@ using LibMatrix; using LibMatrix.Responses; using LibMatrix.RoomTypes; -namespace MatrixRoomUtils.Web.Classes; +namespace MatrixRoomUtils.Desktop; public class RoomInfo { public RoomInfo() { } @@ -17,10 +17,10 @@ public class RoomInfo { public async Task<StateEventResponse?> GetStateEvent(string type, string stateKey = "") { var @event = StateEvents.FirstOrDefault(x => x.Type == type && x.StateKey == stateKey); if (@event is not null) return @event; - @event = new StateEventResponse() { + @event = new StateEventResponse { RoomId = Room.RoomId, Type = type, - StateKey = stateKey, + StateKey = stateKey }; try { @event.TypedContent = await Room.GetStateAsync<object>(type, stateKey); diff --git a/MatrixRoomUtils.Desktop/SentryService.cs b/MatrixRoomUtils.Desktop/SentryService.cs index ed96697..648946c 100644 --- a/MatrixRoomUtils.Desktop/SentryService.cs +++ b/MatrixRoomUtils.Desktop/SentryService.cs @@ -6,8 +6,8 @@ namespace MatrixRoomUtils.Desktop; public class SentryService : IDisposable { private IDisposable? _sentrySdkDisposable; - public SentryService(IServiceScopeFactory scopeFactory, ILogger<SentryService> logger) { - MRUDesktopConfiguration config = scopeFactory.CreateScope().ServiceProvider.GetRequiredService<MRUDesktopConfiguration>(); + public SentryService(IServiceScopeFactory scopeFactory, ILogger logger) { + var config = scopeFactory.CreateScope().ServiceProvider.GetRequiredService<MRUDesktopConfiguration>(); if (config.SentryDsn is null) { logger.LogWarning("Sentry DSN is not set, skipping Sentry initialisation"); return; diff --git a/MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs b/MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs index 02d691a..51aee12 100644 --- a/MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs +++ b/MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs @@ -10,9 +10,11 @@ public class LocalStorageProviderService : IStorageProvider { _localStorageService = localStorageService; } - async Task IStorageProvider.SaveAllChildrenAsync<T>(string key, T value) => throw new NotImplementedException(); + Task IStorageProvider.SaveAllChildrenAsync<T>(string key, T value) { + throw new NotImplementedException(); + } - async Task<T?> IStorageProvider.LoadAllChildrenAsync<T>(string key) where T : default => 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); diff --git a/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs b/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs index e9d56b9..14625fd 100644 --- a/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs +++ b/MatrixRoomUtils.Web/Classes/MRUStorageWrapper.cs @@ -45,10 +45,7 @@ public class MRUStorageWrapper { } public async Task AddToken(LoginResponse loginResponse) { - var tokens = await GetAllTokens(); - if (tokens == null) { - tokens = new List<LoginResponse>(); - } + var tokens = await GetAllTokens() ?? new List<LoginResponse>(); tokens.Add(loginResponse); await _storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); @@ -92,9 +89,9 @@ public class MRUStorageWrapper { } public class DeveloperSettings { - public bool EnableLogViewers { get; set; } = false; + public bool EnableLogViewers { get; set; } public bool EnableConsoleLogging { get; set; } = true; - public bool EnablePortableDevtools { get; set; } = false; + public bool EnablePortableDevtools { get; set; } } public async Task RemoveToken(LoginResponse auth) { @@ -107,7 +104,5 @@ public class MRUStorageWrapper { await _storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); } - public async Task SetCurrentToken(LoginResponse? auth) { - _storageService.DataStorageProvider.SaveObjectAsync("token", auth); - } + public async Task SetCurrentToken(LoginResponse? auth) => await _storageService.DataStorageProvider.SaveObjectAsync("token", auth); } diff --git a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs index b6f6d56..bb2eab9 100644 --- a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs +++ b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs @@ -28,7 +28,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { }, new() { Type = "m.room.join_rules", - TypedContent = new JoinRulesEventData() { + TypedContent = new JoinRulesEventData { JoinRule = "public" } }, @@ -42,7 +42,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate { }, new() { Type = "m.room.avatar", - TypedContent = new RoomAvatarEventData() { + TypedContent = new RoomAvatarEventData { Url = "mxc://feline.support/UKNhEyrVsrAbYteVvZloZcFj" } } diff --git a/MatrixRoomUtils.Web/Classes/RoomInfo.cs b/MatrixRoomUtils.Web/Classes/RoomInfo.cs index 4df81ec..111bfe0 100644 --- a/MatrixRoomUtils.Web/Classes/RoomInfo.cs +++ b/MatrixRoomUtils.Web/Classes/RoomInfo.cs @@ -11,10 +11,10 @@ public class RoomInfo { public async Task<StateEventResponse?> GetStateEvent(string type, string stateKey = "") { var @event = StateEvents.FirstOrDefault(x => x.Type == type && x.StateKey == stateKey); if (@event is not null) return @event; - @event = new StateEventResponse() { + @event = new StateEventResponse { RoomId = Room.RoomId, Type = type, - StateKey = stateKey, + StateKey = stateKey }; try { @event.TypedContent = await Room.GetStateAsync<object>(type, stateKey); diff --git a/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs b/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs index 6f11cad..a923015 100644 --- a/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs +++ b/MatrixRoomUtils.Web/Classes/SessionStorageProviderService.cs @@ -10,9 +10,11 @@ public class SessionStorageProviderService : IStorageProvider { _sessionStorageService = sessionStorage; } - async Task IStorageProvider.SaveAllChildrenAsync<T>(string key, T value) => throw new NotImplementedException(); + Task IStorageProvider.SaveAllChildrenAsync<T>(string key, T value) { + throw new NotImplementedException(); + } - async Task<T?> IStorageProvider.LoadAllChildrenAsync<T>(string key) where T : default => 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); diff --git a/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor index b2928ee..679f324 100644 --- a/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor +++ b/MatrixRoomUtils.Web/Pages/HSAdmin/RoomQuery.razor @@ -158,10 +158,11 @@ public LocalRoomQueryFilter Filter { get; set; } = new(); - protected override async Task OnParametersSetAsync() { + protected override Task OnParametersSetAsync() { if (Ascending == null) Ascending = true; OrderBy ??= "name"; + return Task.CompletedTask; } private async Task Search() { diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor index 65ba68b..1004ee3 100644 --- a/MatrixRoomUtils.Web/Pages/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Index.razor @@ -15,16 +15,15 @@ Small collection of tools to do not-so-everyday things. <form> @foreach (var (auth, user) in _users.OrderByDescending(x=>x.Value.RoomCount)) { var _auth = auth; - var _user = user; <div style="margin-bottom: 1em;"> - <img style="border-radius: 50%; height: 3em; width: 3em;" src="@_user.AvatarUrl"/> + <img style="border-radius: 50%; height: 3em; width: 3em;" src="@user.AvatarUrl"/> <p style="margin-left: 1em; margin-top: -0.5em; display: inline-block;"> <input type="radio" name="csa" checked="@(_currentSession.AccessToken == _auth.AccessToken)" @onclick="@(()=>SwitchSession(_auth))" style="text-decoration-line: unset;"/> - <b>@_user.DisplayName</b> on <b>@_auth.Homeserver</b> + <b>@user.DisplayName</b> on <b>@_auth.Homeserver</b> <a role="button" @onclick="@(() => RemoveUser(_auth))">Remove</a> </p> - <p style="margin-top: -1.5em; margin-left: 4em;">Member of @_user.RoomCount rooms</p> + <p style="margin-top: -1.5em; margin-left: 4em;">Member of @user.RoomCount rooms</p> </div> } @@ -69,7 +68,7 @@ Small collection of tools to do not-so-everyday things. private class UserInfo { internal string AvatarUrl { get; set; } internal string DisplayName { get; set; } - internal int RoomCount { get; set; } = 0; + internal int RoomCount { get; set; } } private async Task RemoveUser(LoginResponse auth) { diff --git a/MatrixRoomUtils.Web/Pages/InvalidSession.razor b/MatrixRoomUtils.Web/Pages/InvalidSession.razor index 2b030ce..f555be5 100644 --- a/MatrixRoomUtils.Web/Pages/InvalidSession.razor +++ b/MatrixRoomUtils.Web/Pages/InvalidSession.razor @@ -23,6 +23,9 @@ </ModalWindow> } } +else { + <b>Something has gone wrong and the login was not passed along!</b> +} @code { @@ -30,13 +33,13 @@ [SupplyParameterFromQuery(Name = "ctx")] public string Context { get; set; } - private LoginResponse _login { get; set; } + private LoginResponse? _login { get; set; } - private bool _showRefreshDialog { get; set; } = false; + private bool _showRefreshDialog { get; set; } private string _password { get; set; } = ""; - private MatrixException _loginException { get; set; } + private MatrixException? _loginException { get; set; } protected override async Task OnInitializedAsync() { var tokens = await MRUStorage.GetAllTokens(); @@ -55,15 +58,16 @@ } private async Task RemoveUser() { - await MRUStorage.RemoveToken(_login); - if ((await MRUStorage.GetCurrentToken()).AccessToken == _login.AccessToken) - MRUStorage.SetCurrentToken((await MRUStorage.GetAllTokens()).FirstOrDefault()); + await MRUStorage.RemoveToken(_login!); + if ((await MRUStorage.GetCurrentToken())!.AccessToken == _login!.AccessToken) + await MRUStorage.SetCurrentToken((await MRUStorage.GetAllTokens())?.FirstOrDefault()); await OnInitializedAsync(); } private async Task OpenRefreshDialog() { _showRefreshDialog = true; StateHasChanged(); + await Task.CompletedTask; } private async Task SwitchSession(LoginResponse auth) { @@ -73,6 +77,7 @@ } private async Task TryLogin() { + if(_login is null) throw new NullReferenceException("Login is null!"); try { var result = await HomeserverProvider.Login(_login.Homeserver, _login.UserId, _password); if (result is null) { diff --git a/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor b/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor index 10a2929..22a004d 100644 --- a/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor +++ b/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor @@ -78,10 +78,10 @@ else { await foreach (var state in states) { if (state.Type is not "m.room.member") continue; progress.ProcessedUsers[room].Total++; - if (!homeServers.Any(x => x.Server == state.StateKey.Split(':')[1])) { - homeServers.Add(new HomeServerInfo { Server = state.StateKey.Split(':')[1] }); - Console.WriteLine($"Added new homeserver {state.StateKey.Split(':')[1]}"); - } + + if (homeServers.Any(x => x.Server == state.StateKey.Split(':')[1])) continue; + homeServers.Add(new HomeServerInfo { Server = state.StateKey.Split(':')[1] }); + Console.WriteLine($"Added new homeserver {state.StateKey.Split(':')[1]}"); } semaphore.Release(); progress.ProcessedUsers[room].IsFinished = true; diff --git a/MatrixRoomUtils.Web/Pages/MediaLocator.razor b/MatrixRoomUtils.Web/Pages/MediaLocator.razor index 8c41440..af6e67a 100644 --- a/MatrixRoomUtils.Web/Pages/MediaLocator.razor +++ b/MatrixRoomUtils.Web/Pages/MediaLocator.razor @@ -56,7 +56,7 @@ }); } - async Task executeSearch() { + Task executeSearch() { var sem = new SemaphoreSlim(128, 128); homeservers.ForEach(async hs => { await sem.WaitAsync(); @@ -80,6 +80,7 @@ } StateHasChanged(); }); + return Task.CompletedTask; } async Task addMoreHomeservers() { diff --git a/MatrixRoomUtils.Web/Pages/ModalTest.razor b/MatrixRoomUtils.Web/Pages/ModalTest.razor index 79c7fcd..2b1c9bc 100644 --- a/MatrixRoomUtils.Web/Pages/ModalTest.razor +++ b/MatrixRoomUtils.Web/Pages/ModalTest.razor @@ -5,10 +5,10 @@ @foreach (var (key, value) in _windowInfos) { @* <ModalWindow X="@value.X" Y="@value.Y" Title="@value.Title">@value.Content</ModalWindow> *@ } -@for (int i = 0; i < 5; i++) { +@for (var i = 0; i < 5; i++) { var i1 = i; <ModalWindow X="@Random.Shared.Next(1400)" Y="@Random.Shared.Next(1000)" Title="@("Window " + i1)" OnCloseClicked="() => OnCloseClicked(i1)"> - @for (int j = 0; j < i1; j++) { + @for (var j = 0; j < i1; j++) { <h1>@j</h1> } </ModalWindow> @@ -31,9 +31,9 @@ double _y = 0; double multiplier = 1; - for (int i = 0; i < 200; i++) { + for (var i = 0; i < 200; i++) { var i1 = i; - _windowInfos.Add(_windowInfos.Count, new WindowInfo() { + _windowInfos.Add(_windowInfos.Count, new WindowInfo { X = _x, Y = _y, Title = "Win" + i1, diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor index ebf6444..3b7d000 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor @@ -131,7 +131,7 @@ <td> @if (serverAcl?.Allow is null) { <p>No allow rules exist!</p> - <button @onclick="@(() => { serverAcl.Allow = new() { "*" }; })">Create sane defaults</button> + <button @onclick="@(() => { serverAcl.Allow = new List<string> { "*" }; })">Create sane defaults</button> } else { <details> @@ -141,7 +141,7 @@ } @if (serverAcl?.Deny is null) { <p>No deny rules exist!</p> - <button @onclick="@(() => { serverAcl.Allow = new(); })">Create sane defaults</button> + <button @onclick="@(() => { serverAcl.Allow = new List<string>(); })">Create sane defaults</button> } else { <details> @@ -240,12 +240,7 @@ @code { private string RoomPreset { - get { - if (Presets.ContainsValue(creationEvent)) { - return Presets.First(x => x.Value == creationEvent).Key; - } - return "Not a preset"; - } + get => Presets.ContainsValue(creationEvent) ? Presets.First(x => x.Value == creationEvent).Key : "Not a preset"; set { creationEvent = Presets[value]; JsonChanged(); @@ -310,7 +305,7 @@ creationEvent.InitialState.Add(new StateEvent { Type = "m.room.member", StateKey = mxid, - TypedContent = new RoomMemberEventData() { + TypedContent = new RoomMemberEventData { Membership = "invite", Reason = "Automatically invited at room creation time." } diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor index 89ededf..ad3a714 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor @@ -19,25 +19,25 @@ private ProfileResponseEventData GlobalProfile { get; set; } private SyncFilter filter = new() { - AccountData = new() { - NotTypes = new() { "*" }, + AccountData = new SyncFilter.EventFilter { + NotTypes = new List<string> { "*" }, Limit = 1 }, - Presence = new() { - NotTypes = new() { "*" }, + Presence = new SyncFilter.EventFilter { + NotTypes = new List<string> { "*" }, Limit = 1 }, - Room = new() { - AccountData = new() { - NotTypes = new() { "*" }, + Room = new SyncFilter.RoomFilter { + AccountData = new SyncFilter.RoomFilter.StateFilter { + NotTypes = new List<string> { "*" }, Limit = 1 }, - Ephemeral = new() { - NotTypes = new() { "*" }, + Ephemeral = new SyncFilter.RoomFilter.StateFilter { + NotTypes = new List<string> { "*" }, Limit = 1 }, - State = new() { - Types = new List<string>() { + State = new SyncFilter.RoomFilter.StateFilter { + Types = new List<string> { "m.room.name", "m.room.avatar", "m.room.create", @@ -45,8 +45,8 @@ "m.room.power_levels" } }, - Timeline = new() { - NotTypes = new() { "*" }, + Timeline = new SyncFilter.RoomFilter.StateFilter { + NotTypes = new List<string> { "*" }, Limit = 1 } } @@ -74,9 +74,9 @@ room = Rooms.First(x => x.Room.RoomId == roomId); } else { - room = new RoomInfo() { + room = new RoomInfo { Room = await hs.GetRoom(roomId), - StateEvents = new() + StateEvents = new List<StateEventResponse?>() }; Rooms.Add(room); KnownRooms.Add(room); @@ -91,23 +91,23 @@ Status = "Sync complete!"; foreach (var roomInfo in Rooms) { if (!roomInfo.StateEvents.Any(x => x.Type == "m.room.name")) { - roomInfo.StateEvents.Add(new StateEventResponse() { + roomInfo.StateEvents.Add(new StateEventResponse { Type = "m.room.name", - TypedContent = new RoomNameEventData() { + TypedContent = new RoomNameEventData { Name = roomInfo.Room.RoomId } }); } if (!roomInfo.StateEvents.Any(x => x.Type == "m.room.avatar")) { - roomInfo.StateEvents.Add(new StateEventResponse() { + roomInfo.StateEvents.Add(new StateEventResponse { Type = "m.room.avatar", - TypedContent = new RoomAvatarEventData() { + TypedContent = new RoomAvatarEventData { } }); } if (!roomInfo.StateEvents.Any(x => x.Type == "org.matrix.mjolnir.shortcode")) { - roomInfo.StateEvents.Add(new StateEventResponse() { + roomInfo.StateEvents.Add(new StateEventResponse { Type = "org.matrix.mjolnir.shortcode" }); } @@ -118,10 +118,10 @@ var memberTasks = Rooms.Select(async roomInfo => { if (!roomInfo.StateEvents.Any(x => x.Type == "m.room.member" && x.StateKey == hs.WhoAmI.UserId)) { await semaphore.WaitAsync(); - roomInfo.StateEvents.Add(new StateEventResponse() { + roomInfo.StateEvents.Add(new StateEventResponse { Type = "m.room.member", StateKey = hs.WhoAmI.UserId, - TypedContent = await roomInfo.Room.GetStateAsync<RoomMemberEventData>("m.room.member", hs.WhoAmI.UserId) ?? new RoomMemberEventData() { + TypedContent = await roomInfo.Room.GetStateAsync<RoomMemberEventData>("m.room.member", hs.WhoAmI.UserId) ?? new RoomMemberEventData { Membership = "unknown" } }); @@ -148,7 +148,7 @@ await base.OnInitializedAsync(); } - private bool RenderContents { get; set; } = false; + private bool RenderContents { get; set; } private string _status; diff --git a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor index 3297bcb..2b31389 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor @@ -114,7 +114,7 @@ else { @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) { <tr> <td>@policyEvent.StateKey</td> - <td>@policyEvent.RawContent.ToJson(false, true)</td> + <td>@policyEvent.RawContent!.ToJson(false, true)</td> </tr> } </tbody> diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Space.razor b/MatrixRoomUtils.Web/Pages/Rooms/Space.razor index 15c7c70..c37b8ab 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Space.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Space.razor @@ -39,17 +39,21 @@ var state = Room.GetFullStateAsync(); await foreach (var stateEvent in state) { - if (stateEvent.Type == "m.space.child") { - var roomId = stateEvent.StateKey; - var room = await hs.GetRoom(roomId); - if (room is not null) { - Rooms.Add(room); + switch (stateEvent.Type) { + case "m.space.child": { + var roomId = stateEvent.StateKey; + var room = await hs.GetRoom(roomId); + if (room is not null) { + Rooms.Add(room); + } + break; } - } - else if (stateEvent.Type == "m.room.member") { - var serverName = stateEvent.StateKey.Split(':').Last(); - if (!ServersInSpace.Contains(serverName)) { - ServersInSpace.Add(serverName); + case "m.room.member": { + var serverName = stateEvent.StateKey.Split(':').Last(); + if (!ServersInSpace.Contains(serverName)) { + ServersInSpace.Add(serverName); + } + break; } } } @@ -89,10 +93,10 @@ // await base.OnInitializedAsync(); } - private async Task JoinAllRooms() { - foreach (var room in Rooms) { - room.JoinAsync(ServersInSpace.ToArray()); - } + private Task JoinAllRooms() { + List<Task> tasks = Rooms.Select(room => room.JoinAsync(ServersInSpace.ToArray())).ToList(); + Task.WaitAll(tasks.ToArray()); + return Task.CompletedTask; } } diff --git a/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor b/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor index e01fca8..ef7cd51 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor @@ -73,12 +73,12 @@ FilteredEvents.Add(_ev); } StateLoaded++; - if ((DateTime.Now - _lastUpdate).TotalMilliseconds > 100) { - _lastUpdate = DateTime.Now; - status = $"Loaded {StateLoaded} state events"; - StateHasChanged(); - await Task.Delay(0); - } + + if (!((DateTime.Now - _lastUpdate).TotalMilliseconds > 100)) continue; + _lastUpdate = DateTime.Now; + status = $"Loaded {StateLoaded} state events"; + StateHasChanged(); + await Task.Delay(0); } StateHasChanged(); @@ -98,7 +98,7 @@ FilteredEvents = _FilteredEvents; if (_shownType is not null) - shownEventJson = _FilteredEvents.Where(x => x.Type == _shownType).First().RawContent.ToJson(indent: true, ignoreNull: true); + shownEventJson = _FilteredEvents.First(x => x.Type == _shownType).RawContent.ToJson(indent: true, ignoreNull: true); StateHasChanged(); } diff --git a/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor b/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor index cf23c36..5a48b32 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor @@ -91,12 +91,12 @@ FilteredEvents.Add(_ev); } StateLoaded++; - if ((DateTime.Now - _lastUpdate).TotalMilliseconds > 100) { - _lastUpdate = DateTime.Now; - status = $"Loaded {StateLoaded} state events"; - StateHasChanged(); - await Task.Delay(0); - } + + if (!((DateTime.Now - _lastUpdate).TotalMilliseconds > 100)) continue; + _lastUpdate = DateTime.Now; + status = $"Loaded {StateLoaded} state events"; + StateHasChanged(); + await Task.Delay(0); } StateHasChanged(); diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor b/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor index 7fe89cc..4a5298b 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor @@ -45,7 +45,7 @@ private StateEventResponse GetProfileEventBefore(StateEventResponse Event) => Events.TakeWhile(x => x != Event).Last(e => e.Type == "m.room.member" && e.StateKey == Event.Sender); - private Type ComponentType(StateEventResponse Event) => Event.TypedContent switch { + private Type ComponentType(StateEvent Event) => Event.TypedContent switch { RoomMessageEventData => typeof(TimelineMessageItem), RoomMemberEventData => typeof(TimelineMemberItem), _ => typeof(TimelineUnknownItem) diff --git a/MatrixRoomUtils.Web/Program.cs b/MatrixRoomUtils.Web/Program.cs index c760108..a670378 100644 --- a/MatrixRoomUtils.Web/Program.cs +++ b/MatrixRoomUtils.Web/Program.cs @@ -33,7 +33,7 @@ builder.Services.AddBlazoredSessionStorage(config => { }); builder.Services.AddScoped<TieredStorageService>(x => - new( + new TieredStorageService( cacheStorageProvider: new SessionStorageProviderService(x.GetRequiredService<ISessionStorageService>()), dataStorageProvider: new LocalStorageProviderService(x.GetRequiredService<ILocalStorageService>()) ) diff --git a/MatrixRoomUtils.Web/Shared/EditablePre.razor b/MatrixRoomUtils.Web/Shared/EditablePre.razor index e759015..acb477c 100644 --- a/MatrixRoomUtils.Web/Shared/EditablePre.razor +++ b/MatrixRoomUtils.Web/Shared/EditablePre.razor @@ -11,6 +11,9 @@ public object Id { get; set; } - private async Task Callback() => Console.WriteLine("beep"); + private Task Callback() { + Console.WriteLine("beep"); + return Task.CompletedTask; + } } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor index f3a7162..db66309 100644 --- a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor +++ b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor @@ -50,7 +50,7 @@ throw new ArgumentNullException(nameof(UserId)); if (MemberEvent != null) { - User = new() { + User = new ProfileResponseEventData { AvatarUrl = MemberEvent.AvatarUrl, DisplayName = MemberEvent.DisplayName }; diff --git a/MatrixRoomUtils.Web/Shared/ModalWindow.razor b/MatrixRoomUtils.Web/Shared/ModalWindow.razor index 2f001e1..beb7198 100644 --- a/MatrixRoomUtils.Web/Shared/ModalWindow.razor +++ b/MatrixRoomUtils.Web/Shared/ModalWindow.razor @@ -74,13 +74,13 @@ } private void MouseMove(MouseEventArgs obj) { - if (isDragging) { - _x += obj.ClientX - dragX; - _y += obj.ClientY - dragY; - dragX = obj.ClientX; - dragY = obj.ClientY; - StateHasChanged(); - } + if (!isDragging) return; + + _x += obj.ClientX - dragX; + _y += obj.ClientY - dragY; + dragX = obj.ClientX; + dragY = obj.ClientY; + StateHasChanged(); } } diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor index dc06d90..3b057a4 100644 --- a/MatrixRoomUtils.Web/Shared/RoomList.razor +++ b/MatrixRoomUtils.Web/Shared/RoomList.razor @@ -51,7 +51,7 @@ else { await _semaphoreSlim.WaitAsync(); string roomType; try { - RoomCreateEventData createEvent = (await room.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventData; + var createEvent = (await room.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventData; roomType = GetRoomTypeName(createEvent.Type); if (roomType == "Room") { diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor index c04df3f..381ecd1 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor @@ -38,13 +38,11 @@ private List<RoomInfo> rooms => Category.Value; private int RoomVersionDangerLevel(RoomInfo room) { - var roomVersion = room.StateEvents.FirstOrDefault(x=>x.Type == "m.room.create"); + var roomVersion = room.StateEvents.FirstOrDefault(x => x.Type == "m.room.create"); if (roomVersion is null) return 0; - var roomVersionContent = roomVersion.TypedContent as RoomCreateEventData; - if (roomVersionContent is null) return 0; - if (RoomConstants.DangerousRoomVersions.Contains(roomVersionContent.RoomVersion)) return 2; - if (roomVersionContent.RoomVersion != RoomConstants.RecommendedRoomVersion) return 1; - return 0; + return roomVersion.TypedContent is not RoomCreateEventData roomVersionContent ? 0 + : RoomConstants.DangerousRoomVersions.Contains(roomVersionContent.RoomVersion) ? 2 + : roomVersionContent.RoomVersion != RoomConstants.RecommendedRoomVersion ? 1 : 0; } } diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor index a113f0b..0867b48 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor @@ -33,9 +33,9 @@ var rooms = Space.Room.AsSpace.GetRoomsAsync(); await foreach (var room in rooms) { if (Breadcrumbs.Contains(room.RoomId)) continue; - RoomInfo roomInfo = KnownRooms.FirstOrDefault(x => x.Room.RoomId == room.RoomId); + var roomInfo = KnownRooms.FirstOrDefault(x => x.Room.RoomId == room.RoomId); if (roomInfo is null) { - roomInfo = new() { + roomInfo = new RoomInfo { Room = room }; KnownRooms.Add(roomInfo); @@ -48,10 +48,11 @@ private bool _shouldRenderChildren = false; private string? _breadcrumbs; - private async Task SpaceChildrenOpened() { - if (_shouldRenderChildren) return; + private Task SpaceChildrenOpened() { + if (_shouldRenderChildren) return Task.CompletedTask; _shouldRenderChildren = true; Console.WriteLine($"[RoomList] Rendering children of {Space.Room.RoomId}"); + return Task.CompletedTask; } } diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor index 6e3adc6..79844ef 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor @@ -77,7 +77,7 @@ //sweep from id to roominfo if(RoomId is not null) Room ??= await hs.GetRoom(RoomId); - if(Room is not null) RoomInfo ??= new RoomInfo() { + if(Room is not null) RoomInfo ??= new RoomInfo { Room = Room }; diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor index 8239367..d67fdab 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor @@ -4,31 +4,31 @@ @inherits BaseTimelineItem @if (roomMemberData is not null) { - @if (roomMemberData.Membership == "ban") { - <i>@Event.StateKey was banned</i> - } - else if (roomMemberData.Membership == "invite") { - <i>@Event.StateKey was invited</i> - } - else if (roomMemberData.Membership == "join") { - @if (Event.ReplacesState is not null) { + @switch (roomMemberData.Membership) { + case "ban": + <i>@Event.StateKey was banned</i> + break; + case "invite": + <i>@Event.StateKey was invited</i> + break; + case "join" when Event.ReplacesState is not null: <i>@Event.StateKey changed their display name to @(roomMemberData.Displayname ?? Event.Sender)</i> - } - else { - <i><InlineUserItem User="new ProfileResponseEventData()" HomeServer="HomeServer" UserId="@Event.StateKey"></InlineUserItem> joined</i> - } - } - else if (roomMemberData.Membership == "leave") { - <i>@Event.StateKey left</i> - } - else if (roomMemberData.Membership == "knock") { - <i>@Event.StateKey knocked</i> - } - else { - <i>@Event.StateKey has an unknown state:</i> - <pre> + break; + case "join": + <i><InlineUserItem User="@(new ProfileResponseEventData())" HomeServer="@HomeServer" UserId="@Event.StateKey"></InlineUserItem> joined</i> + break; + case "leave": + <i>@Event.StateKey left</i> + break; + case "knock": + <i>@Event.StateKey knocked</i> + break; + default: + <i>@Event.StateKey has an unknown state:</i> + <pre> @Event.ToJson() </pre> + break; } } else { diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor index 411b750..13cce88 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor @@ -2,7 +2,7 @@ @inherits BaseTimelineItem <pre> - @ObjectExtensions.ToJson(Event.RawContent, indent: false) + @Event.RawContent?.ToJson(indent: false) </pre> @code { diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor index b20cc1a..8053a47 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor @@ -8,7 +8,7 @@ This room is of type @(CreationEventContent.Type ?? "Untyped room (usually a chat room)") </p> <pre> - @ObjectExtensions.ToJson(Event.RawContent, indent: false) + @Event.RawContent?.ToJson(indent: false) </pre> @code { diff --git a/MatrixRoomUtils.sln.DotSettings.user b/MatrixRoomUtils.sln.DotSettings.user index 8e084e1..8f91cef 100644 --- a/MatrixRoomUtils.sln.DotSettings.user +++ b/MatrixRoomUtils.sln.DotSettings.user @@ -1,5 +1,5 @@ <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> - <s:String x:Key="/Default/CodeInspection/Highlighting/SweaWarningsMode/@EntryValue">DoNotShowAndRun</s:String> + <s:String x:Key="/Default/CodeInspection/Highlighting/SweaWarningsMode/@EntryValue">ShowAndRun</s:String> <s:Int64 x:Key="/Default/Environment/Hierarchy/Build/BuildTool/MsBuildSolutionLoadingNodeCount/@EntryValue">12</s:Int64> <s:Boolean x:Key="/Default/Environment/Hierarchy/Build/BuildTool/MsBuildSolutionLoadingOrderingEnabled/@EntryValue">True</s:Boolean> <s:String x:Key="/Default/Environment/Hierarchy/Build/SolBuilderDuo/UseMsbuildSolutionBuilder/@EntryValue">No</s:String> diff --git a/MxApiExtensions b/MxApiExtensions -Subproject 977220895d8127116d0000fa98088b235d4a880 +Subproject 8253ca8cb96154f95854b1c1e5dd3ba53f41e5e |