diff options
author | Emma@Rory& <root@rory.gay> | 2023-09-19 00:17:18 +0200 |
---|---|---|
committer | Emma@Rory& <root@rory.gay> | 2023-09-19 00:17:18 +0200 |
commit | ec1752307a4a273324cd8f13bb099fed6ff7ef3a (patch) | |
tree | 5d287d992aa49d6d7f898198a6e769314f65f8eb | |
parent | Refactors (diff) | |
download | MatrixUtils-ec1752307a4a273324cd8f13bb099fed6ff7ef3a.tar.xz |
Refactors
30 files changed, 136 insertions, 70 deletions
diff --git a/ArcaneLibs b/ArcaneLibs -Subproject 78587a5303754af87cdd999b7514e42b081aace +Subproject fadd59b2d7303546585f1543ddbbc268068a70a diff --git a/LibMatrix b/LibMatrix -Subproject 6bd02248ccfbcb46960a6f39eaad23888d190eb +Subproject f5447484512d726f4403f0d7725777d0a95601f diff --git a/MatrixRoomUtils.Desktop/App.axaml.cs b/MatrixRoomUtils.Desktop/App.axaml.cs index 33f2c13..3963be6 100644 --- a/MatrixRoomUtils.Desktop/App.axaml.cs +++ b/MatrixRoomUtils.Desktop/App.axaml.cs @@ -20,8 +20,8 @@ public partial class App : Application { services.AddSingleton<SentryService>(); services.AddSingleton<TieredStorageService>(x => new TieredStorageService( - cacheStorageProvider: new FileStorageProvider(x.GetService<MRUDesktopConfiguration>().CacheStoragePath), - dataStorageProvider: new FileStorageProvider(x.GetService<MRUDesktopConfiguration>().DataStoragePath) + cacheStorageProvider: new FileStorageProvider(x.GetService<MRUDesktopConfiguration>()!.CacheStoragePath), + dataStorageProvider: new FileStorageProvider(x.GetService<MRUDesktopConfiguration>()!.DataStoragePath) ) ); services.AddSingleton(new RoryLibMatrixConfiguration { diff --git a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs index 6cdb767..d687679 100644 --- a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs +++ b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs @@ -2,9 +2,10 @@ using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Media.Imaging; using LibMatrix; +using LibMatrix.EventTypes.Spec.State; using LibMatrix.Helpers; +using LibMatrix.Interfaces.Services; using LibMatrix.Services; -using LibMatrix.StateEventTypes.Spec; using Microsoft.Extensions.DependencyInjection; namespace MatrixRoomUtils.Desktop.Components; @@ -43,9 +44,10 @@ public partial class RoomListEntry : UserControl { if (avatarEvent?.TypedContent is RoomAvatarEventContent avatarData) { var mxcUrl = avatarData.Url; await using var svc = _serviceScopeFactory.CreateAsyncScope(); - var hs = await svc.ServiceProvider.GetService<MRUStorageWrapper>().GetCurrentSessionOrPrompt(); - var storage = svc.ServiceProvider.GetService<TieredStorageService>().CacheStorageProvider; - var resolvedUrl = MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, mxcUrl); + var hs = await svc.ServiceProvider.GetService<MRUStorageWrapper>()?.GetCurrentSessionOrPrompt()!; + var hsResolver = svc.ServiceProvider.GetService<HomeserverResolverService>(); + var storage = svc.ServiceProvider.GetService<TieredStorageService>()?.CacheStorageProvider; + var resolvedUrl = await hsResolver.ResolveMediaUri(hs.FullHomeServerDomain, mxcUrl); var storageKey = $"media/{mxcUrl.Replace("mxc://", "").Replace("/", ".")}"; try { if (!await storage.ObjectExistsAsync(storageKey)) diff --git a/MatrixRoomUtils.Web/Classes/Constants/RoomConstants.cs b/MatrixRoomUtils.Web/Classes/Constants/RoomConstants.cs index da6bf0d..b145cd0 100644 --- a/MatrixRoomUtils.Web/Classes/Constants/RoomConstants.cs +++ b/MatrixRoomUtils.Web/Classes/Constants/RoomConstants.cs @@ -1,7 +1,6 @@ -namespace MatrixRoomUtils.Web.Classes.Constants; +namespace MatrixRoomUtils.Web.Classes.Constants; public class RoomConstants { - public static readonly string[] DangerousRoomVersions = { "1", "8" }; public const string RecommendedRoomVersion = "10"; -} \ No newline at end of file +} diff --git a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs index 3f67f33..1fa56be 100644 --- a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs +++ b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs @@ -1,7 +1,7 @@ using System.Text.Json.Nodes; using LibMatrix; +using LibMatrix.EventTypes.Spec.State; using LibMatrix.Responses; -using LibMatrix.StateEventTypes.Spec; namespace MatrixRoomUtils.Web.Classes.RoomCreationTemplates; diff --git a/MatrixRoomUtils.Web/Pages/About.razor b/MatrixRoomUtils.Web/Pages/About.razor index 17ed04a..df6e6c2 100644 --- a/MatrixRoomUtils.Web/Pages/About.razor +++ b/MatrixRoomUtils.Web/Pages/About.razor @@ -13,23 +13,23 @@ <br/><br/> <p>You can find the source code on <a href="https://git.rory.gay/MatrixRoomUtils.git/">my git server</a>.<br/></p> <p>You can also join the <a href="https://matrix.to/#/%23mru%3Arory.gay?via=rory.gay&via=matrix.org&via=feline.support">Matrix room</a> for this project.</p> -@if (showBinDownload) { +@if (ShowBinDownload) { <p>This deployment also serves a copy of the compiled, hosting-ready binaries at <a href="MRU-BIN.tar.xz">/MRU-BIN.tar.xz</a>!</p> } -@if (showSrcDownload) { +@if (ShowSrcDownload) { <p>This deployment also serves a copy of the compiled, hosting-ready binaries at <a href="MRU-SRC.tar.xz">/MRU-SRC.tar.xz</a>!</p> } @code { - private bool showBinDownload { get; set; } - private bool showSrcDownload { get; set; } + private bool ShowBinDownload { get; set; } + private bool ShowSrcDownload { get; set; } protected override async Task OnInitializedAsync() { using var hc = new HttpClient(); var hr = await hc.SendAsync(new HttpRequestMessage(HttpMethod.Head, NavigationManager.ToAbsoluteUri("/MRU-BIN.tar.xz").AbsoluteUri)); - showBinDownload = hr.StatusCode == HttpStatusCode.OK; + ShowBinDownload = hr.StatusCode == HttpStatusCode.OK; hr = await hc.SendAsync(new HttpRequestMessage(HttpMethod.Head, NavigationManager.ToAbsoluteUri("/MRU-SRC.tar.xz").AbsoluteUri)); - showSrcDownload = hr.StatusCode == HttpStatusCode.OK; + ShowSrcDownload = hr.StatusCode == HttpStatusCode.OK; await base.OnInitializedAsync(); } diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor index e02c733..845bbb9 100644 --- a/MatrixRoomUtils.Web/Pages/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Index.razor @@ -26,6 +26,9 @@ Small collection of tools to do not-so-everyday things. <p> <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> + @if (_auth.Proxy != null) { + <span class="badge badge-info"> (proxied via @_auth.Proxy)</span> + } </p> <p>Member of @user.RoomCount rooms</p> @@ -35,6 +38,7 @@ Small collection of tools to do not-so-everyday things. <p> <LinkButton href="">Manage</LinkButton> <LinkButton OnClick="@(() => RemoveUser(_auth))">Remove</LinkButton> + <LinkButton OnClick="@(() => RemoveUser(_auth, true))">Log out</LinkButton> </p> </td> @* </div> *@ @@ -55,7 +59,7 @@ Small collection of tools to do not-so-everyday things. UserInfo userInfo = new(); AuthenticatedHomeserverGeneric hs; try { - hs = await HomeserverProvider.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken); + hs = await hsProvider.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken); } catch (MatrixException e) { if (e.ErrorCode == "M_UNKNOWN_TOKEN") { @@ -65,10 +69,10 @@ Small collection of tools to do not-so-everyday things. throw; } var roomCountTask = hs.GetJoinedRooms(); - var profile = await hs.GetProfile(hs.WhoAmI.UserId); + var profile = await hs.GetProfileAsync(hs.WhoAmI.UserId); userInfo.DisplayName = profile.DisplayName ?? hs.WhoAmI.UserId; Console.WriteLine(profile.ToJson()); - userInfo.AvatarUrl = MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, + userInfo.AvatarUrl = await hsResolver.ResolveMediaUri(hs.FullHomeServerDomain, profile.AvatarUrl ?? "https://api.dicebear.com/6.x/identicon/svg?seed=" + hs.WhoAmI.UserId ); @@ -86,10 +90,22 @@ Small collection of tools to do not-so-everyday things. internal int RoomCount { get; set; } } - private async Task RemoveUser(UserAuth auth) { + private async Task RemoveUser(UserAuth auth, bool logout = false) { + try { + if (logout) { + await (await hsProvider.GetAuthenticatedWithToken(auth.Homeserver, auth.AccessToken)).Logout(); + } + } + catch (Exception e) { + if(e is MatrixException {ErrorCode: "M_UNKNOWN_TOKEN" }) { + //todo: handle this + return; + } + Console.WriteLine(e); + } await MRUStorage.RemoveToken(auth); - if ((await MRUStorage.GetCurrentToken()).AccessToken == auth.AccessToken) - MRUStorage.SetCurrentToken((await MRUStorage.GetAllTokens()).FirstOrDefault()); + if ((await MRUStorage.GetCurrentToken())?.AccessToken == auth.AccessToken) + await MRUStorage.SetCurrentToken((await MRUStorage.GetAllTokens() ?? throw new InvalidOperationException()).FirstOrDefault()); await OnInitializedAsync(); } diff --git a/MatrixRoomUtils.Web/Pages/InvalidSession.razor b/MatrixRoomUtils.Web/Pages/InvalidSession.razor index 310abb1..b476c68 100644 --- a/MatrixRoomUtils.Web/Pages/InvalidSession.razor +++ b/MatrixRoomUtils.Web/Pages/InvalidSession.razor @@ -78,7 +78,7 @@ else { private async Task TryLogin() { if(_login is null) throw new NullReferenceException("Login is null!"); try { - var result = new UserAuth(await HomeserverProvider.Login(_login.Homeserver, _login.UserId, _password)); + var result = new UserAuth(await hsProvider.Login(_login.Homeserver, _login.UserId, _password)); if (result is null) { Console.WriteLine($"Failed to login to {_login.Homeserver} as {_login.UserId}!"); return; diff --git a/MatrixRoomUtils.Web/Pages/LoginPage.razor b/MatrixRoomUtils.Web/Pages/LoginPage.razor index a6ce469..c7f5922 100644 --- a/MatrixRoomUtils.Web/Pages/LoginPage.razor +++ b/MatrixRoomUtils.Web/Pages/LoginPage.razor @@ -70,7 +70,7 @@ var (homeserver, username, password, proxy) = record; if (LoggedInSessions.Any(x => x.UserId == $"@{username}:{homeserver}" && x.Proxy == proxy)) return; try { - var result = new UserAuth(await HomeserverProvider.Login(homeserver, username, password, proxy)) { + var result = new UserAuth(await hsProvider.Login(homeserver, username, password, proxy)) { Proxy = proxy }; if (result == null) { diff --git a/MatrixRoomUtils.Web/Pages/MediaLocator.razor b/MatrixRoomUtils.Web/Pages/MediaLocator.razor index 42c7b8e..e1686b9 100644 --- a/MatrixRoomUtils.Web/Pages/MediaLocator.razor +++ b/MatrixRoomUtils.Web/Pages/MediaLocator.razor @@ -95,7 +95,7 @@ lines.ToList().ForEach(async line => { await sem.WaitAsync(); try { - homeservers.Add(await HomeserverResolver.ResolveHomeserverFromWellKnown(line)); + homeservers.Add(await hsResolver.ResolveHomeserverFromWellKnown(line)); StateHasChanged(); } catch (Exception e) { diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor index c6fd5b6..5202c40 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor @@ -3,11 +3,11 @@ @using System.Reflection @using ArcaneLibs.Extensions @using LibMatrix +@using LibMatrix.EventTypes.Spec.State @using LibMatrix.Extensions @using LibMatrix.Helpers @using LibMatrix.Homeservers @using LibMatrix.Responses -@using LibMatrix.StateEventTypes.Spec @using MatrixRoomUtils.Web.Classes.RoomCreationTemplates @* @* ReSharper disable once RedundantUsingDirective - Must not remove this, Rider marks this as "unused" when it's not */ *@ @@ -90,7 +90,7 @@ <tr> <td>Room icon:</td> <td> - <img src="@MediaResolver.ResolveMediaUri(HomeServer.HomeServerDomain, roomAvatarEvent.Url)" style="width: 128px; height: 128px; border-radius: 50%;"/> + <img src="@hsResolver.ResolveMediaUri(HomeServer.HomeServerDomain, roomAvatarEvent.Url)" style="width: 128px; height: 128px; border-radius: 50%;"/> <div style="display: inline-block; vertical-align: middle;"> <FancyTextBox @bind-Value="@roomAvatarEvent.Url"></FancyTextBox><br/> <InputFile OnChange="RoomIconFilePicked"></InputFile> diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor index c2daba7..99e8cbb 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor @@ -1,8 +1,8 @@ @page "/Rooms" -@using LibMatrix.StateEventTypes.Spec @using LibMatrix.Filters @using LibMatrix.Helpers @using LibMatrix.Responses +@using LibMatrix.EventTypes.Spec.State <h3>Room list</h3> <p>@Status</p> @@ -55,7 +55,7 @@ protected override async Task OnInitializedAsync() { var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; - GlobalProfile = await hs.GetProfile(hs.WhoAmI.UserId); + GlobalProfile = await hs.GetProfileAsync(hs.WhoAmI.UserId); Status = "Syncing..."; SyncResult? sync = null; @@ -75,7 +75,7 @@ } else { room = new RoomInfo { - Room = await hs.GetRoom(roomId), + Room = hs.GetRoom(roomId), StateEvents = new List<StateEventResponse?>() }; Rooms.Add(room); @@ -135,7 +135,7 @@ // if (res is not null) { // foreach (var (roomId, roomData) in res.Rooms.Join) { // var room = new RoomInfo() { - // Room = await hs.GetRoom(roomId), + // Room = hs.GetRoom(roomId), // StateEvents = roomData.State.Events.Where(x => x.Type == "m.room.member" && x.StateKey == hs.WhoAmI.UserId).ToList() // }; // Rooms.Add(room); diff --git a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor index d2b8360..e6f436e 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor @@ -4,8 +4,8 @@ @using LibMatrix.Helpers @using LibMatrix.Homeservers @using LibMatrix.Responses -@using LibMatrix.StateEventTypes.Spec @using ArcaneLibs.Extensions +@using LibMatrix.EventTypes.Spec.State <h3>Policy list editor - Editing @RoomId</h3> <hr/> @@ -212,7 +212,7 @@ else { var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; - var room = await hs.GetRoom(RoomId); + var room = hs.GetRoom(RoomId); var states = room.GetFullStateAsync(); await foreach (var state in states) { @@ -234,8 +234,8 @@ else { var hs = userId.Split(':')[1]; var server = servers.ContainsKey(hs) ? servers[hs] : new RemoteHomeServer(userId.Split(':')[1]); if (!servers.ContainsKey(hs)) servers.Add(hs, server); - var profile = await server.GetProfile(userId); - avatars.Add(userId, MediaResolver.ResolveMediaUri(server.FullHomeServerDomain, profile.AvatarUrl)); + var profile = await server.GetProfileAsync(userId); + avatars.Add(userId, await hsResolver.ResolveMediaUri(server.FullHomeServerDomain, profile.AvatarUrl)); servers.Add(userId, server); StateHasChanged(); } diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Space.razor b/MatrixRoomUtils.Web/Pages/Rooms/Space.razor index ef0ea5a..9474b21 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Space.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Space.razor @@ -35,14 +35,14 @@ var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; - Room = await hs.GetRoom(RoomId.Replace('~', '.')); + Room = hs.GetRoom(RoomId.Replace('~', '.')); var state = Room.GetFullStateAsync(); await foreach (var stateEvent in state) { switch (stateEvent.Type) { case "m.space.child": { var roomId = stateEvent.StateKey; - var room = await hs.GetRoom(roomId); + var room = hs.GetRoom(roomId); if (room is not null) { Rooms.Add(room); } @@ -68,7 +68,7 @@ // if (stateEvent.Type == "m.space.child") { // // if (stateEvent.Content.ToJson().Length < 5) return; // var roomId = stateEvent.StateKey; - // var room = await hs.GetRoom(roomId); + // var room = hs.GetRoom(roomId); // if (room is not null) { // Rooms.Add(room); // } diff --git a/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor b/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor index fefcabc..f7a6106 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor @@ -59,7 +59,7 @@ var hs = await MRUStorage.GetCurrentSessionOrNavigate(); var StateLoaded = 0; - var response = (await hs.GetRoom(RoomId)).GetFullStateAsync(); + var response = (hs.GetRoom(RoomId)).GetFullStateAsync(); await foreach (var _ev in response) { // var e = new StateEventResponse { // Type = _ev.Type, diff --git a/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor b/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor index 1c3f28b..6e8fe2f 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor @@ -83,7 +83,7 @@ var StateLoaded = 0; var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; - var response = (await hs.GetRoom(RoomId)).GetFullStateAsync(); + var response = (hs.GetRoom(RoomId)).GetFullStateAsync(); await foreach (var _ev in response) { Events.Add(_ev); if (string.IsNullOrEmpty(_ev.StateKey)) { diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor b/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor index 2c95c99..68125cb 100644 --- a/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor +++ b/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor @@ -1,9 +1,10 @@ @page "/Rooms/{RoomId}/Timeline" @using MatrixRoomUtils.Web.Shared.TimelineComponents @using LibMatrix +@using LibMatrix.EventTypes.Spec +@using LibMatrix.EventTypes.Spec.State @using LibMatrix.Homeservers @using LibMatrix.Responses -@using LibMatrix.StateEventTypes.Spec <h3>RoomManagerTimeline</h3> <hr/> <p>Loaded @Events.Count events...</p> @@ -30,7 +31,7 @@ Console.WriteLine("RoomId: " + RoomId); HomeServer = await MRUStorage.GetCurrentSessionOrNavigate(); if (HomeServer is null) return; - var room = await HomeServer.GetRoom(RoomId); + var room = HomeServer.GetRoom(RoomId); MessagesResponse? msgs = null; do { msgs = await room.GetMessagesAsync(limit: 1000, from: msgs?.End, dir: "b"); diff --git a/MatrixRoomUtils.Web/Pages/SpaceDebug.razor b/MatrixRoomUtils.Web/Pages/SpaceDebug.razor index c4c4ce8..1ad6276 100644 --- a/MatrixRoomUtils.Web/Pages/SpaceDebug.razor +++ b/MatrixRoomUtils.Web/Pages/SpaceDebug.razor @@ -1,5 +1,4 @@ @page "/SpaceDebug" -@using LibMatrix.StateEventTypes.Spec @using LibMatrix.RoomTypes @using LibMatrix.Filters <h3>SpaceDebug</h3> diff --git a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor index af2fa29..e82b505 100644 --- a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor +++ b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor @@ -1,6 +1,5 @@ -@using LibMatrix.StateEventTypes -@using LibMatrix.StateEventTypes.Spec @using LibMatrix +@using LibMatrix.EventTypes.Spec.State @using LibMatrix.Helpers @using LibMatrix.Homeservers <div style="background-color: #ffffff11; border-radius: 0.5em; height: 1em; display: inline-block; vertical-align: middle;" alt="@UserId"> @@ -58,11 +57,11 @@ } if (User is null && UserId is not null) { - User ??= await HomeServer.GetProfile(UserId); + User ??= await HomeServer.GetProfileAsync(UserId); } - ProfileAvatar ??= MediaResolver.ResolveMediaUri(HomeServer.FullHomeServerDomain, User.AvatarUrl); + ProfileAvatar ??= await hsResolver.ResolveMediaUri(HomeServer.FullHomeServerDomain, User.AvatarUrl); ProfileName ??= User.DisplayName; _semaphoreSlim.Release(); diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor index b0548cb..91ebb0b 100644 --- a/MatrixRoomUtils.Web/Shared/RoomList.razor +++ b/MatrixRoomUtils.Web/Shared/RoomList.razor @@ -1,9 +1,8 @@ @using MatrixRoomUtils.Web.Shared.RoomListComponents; -@using LibMatrix.StateEventTypes -@using LibMatrix.StateEventTypes.Spec @using LibMatrix @using LibMatrix.Extensions @using ArcaneLibs.Extensions +@using LibMatrix.EventTypes.Spec.State @if(Rooms.Count != RoomsWithTypes.Sum(x=>x.Value.Count)) { <p>Fetching room details... @RoomsWithTypes.Sum(x=>x.Value.Count) out of @Rooms.Count done!</p> @foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) { @@ -29,7 +28,7 @@ else { var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; - GlobalProfile ??= await hs.GetProfile(hs.WhoAmI.UserId); + GlobalProfile ??= await hs.GetProfileAsync(hs.WhoAmI.UserId); if (RoomsWithTypes.Any()) return; var tasks = Rooms.Select(ProcessRoom); diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor index d717186..27084cc 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor @@ -1,7 +1,6 @@ -@using LibMatrix.StateEventTypes @using MatrixRoomUtils.Web.Classes.Constants -@using LibMatrix.StateEventTypes.Spec @using LibMatrix +@using LibMatrix.EventTypes.Spec.State @using LibMatrix.Homeservers <details> <summary>@roomType (@rooms.Count)</summary> diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor index b74643b..d83568e 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor @@ -1,16 +1,15 @@ @using System.Text.Json @using LibMatrix +@using LibMatrix.EventTypes.Spec.State @using LibMatrix.Helpers @using LibMatrix.Homeservers @using LibMatrix.RoomTypes -@using LibMatrix.StateEventTypes.Spec -@using LibMatrix.StateEventTypes @using MatrixRoomUtils.Web.Classes.Constants <div class="roomListItem" id="@RoomId" style="background-color: #ffffff11; border-radius: 25px; margin: 8px; width: fit-Content; @(hasDangerousRoomVersion ? "border: red 4px solid;" : hasOldRoomVersion ? "border: #FF0 1px solid;" : "")"> @if (OwnMemberState != null) { <img class="imageUnloaded @(string.IsNullOrWhiteSpace(OwnMemberState?.AvatarUrl ?? GlobalProfile?.AvatarUrl) ? "" : "imageLoaded")" style="@(ChildContent is not null ? "vertical-align: baseline;" : "") width: 32px; height: 32px; border-radius: 50%; @(OwnMemberState?.AvatarUrl != GlobalProfile?.AvatarUrl ? "border-color: red; border-width: 3px; border-style: dashed;" : "")" - src="@MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, OwnMemberState.AvatarUrl ?? GlobalProfile.AvatarUrl ?? "/icon-192.png")"/> + src="@hsResolver.ResolveMediaUri(hs.FullHomeServerDomain, OwnMemberState.AvatarUrl ?? GlobalProfile.AvatarUrl ?? "/icon-192.png").Result"/> <span style="vertical-align: middle; margin-right: 8px; border-radius: 75px; @(OwnMemberState?.AvatarUrl != GlobalProfile?.AvatarUrl ? "background-color: red;" : "")"> @(OwnMemberState?.Displayname ?? GlobalProfile?.DisplayName ?? "Loading...") </span> @@ -77,7 +76,7 @@ if(Room is not null) RoomId = Room.RoomId; //sweep from id to roominfo - if(RoomId is not null) Room ??= await hs.GetRoom(RoomId); + if(RoomId is not null) Room ??= hs.GetRoom(RoomId); if(Room is not null) RoomInfo ??= new RoomInfo { Room = Room }; @@ -104,7 +103,7 @@ if (!ShowOwnProfile) return; try { OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.UserId)).TypedContent as RoomMemberEventContent; - GlobalProfile ??= await hs.GetProfile(hs.UserId); + GlobalProfile ??= await hs.GetProfileAsync(hs.UserId); } catch (MatrixException e) { if (e is { ErrorCode: "M_FORBIDDEN" }) { @@ -138,7 +137,7 @@ var state = (await RoomInfo.GetStateEvent("m.room.avatar")).TypedContent as RoomAvatarEventContent; if (state?.Url is { } url) { - roomIcon = MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, url); + roomIcon = await hsResolver.ResolveMediaUri(hs.FullHomeServerDomain, url); // Console.WriteLine($"Got avatar for room {RoomId}: {roomIcon} ({url})"); } } diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor index c450211..27c636f 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor @@ -1,6 +1,6 @@ -@using LibMatrix.StateEventTypes.Spec @using LibMatrix.Extensions @using ArcaneLibs.Extensions +@using LibMatrix.EventTypes.Spec.State @inherits BaseTimelineItem @if (roomMemberData is not null) { diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor index 9c48455..ff77726 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor @@ -1,6 +1,6 @@ -@using LibMatrix.StateEventTypes.Spec @using LibMatrix.Extensions @using ArcaneLibs.Extensions +@using LibMatrix.EventTypes.Spec.State @inherits BaseTimelineItem <p> diff --git a/MatrixRoomUtils.Web/Shared/UserListItem.razor b/MatrixRoomUtils.Web/Shared/UserListItem.razor index 7a55380..7c439cd 100644 --- a/MatrixRoomUtils.Web/Shared/UserListItem.razor +++ b/MatrixRoomUtils.Web/Shared/UserListItem.razor @@ -1,6 +1,5 @@ -@using LibMatrix.StateEventTypes -@using LibMatrix.StateEventTypes.Spec @using LibMatrix.Helpers +@using LibMatrix.EventTypes.Spec.State <div style="background-color: #ffffff11; border-radius: 25px; margin: 8px; width: fit-Content;"> <img style="@(ChildContent is not null ? "vertical-align: baseline;" : "") width: 32px; height: 32px; border-radius: 50%;" src="@profileAvatar"/> <span style="vertical-align: middle; margin-right: 8px; border-radius: 75px;">@profileName</span> @@ -41,11 +40,11 @@ if (UserId == null) { throw new ArgumentNullException(nameof(UserId)); } - User = await hs.GetProfile(UserId); + User = await hs.GetProfileAsync(UserId); } // UserId = User.; - profileAvatar = MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, User.AvatarUrl); + profileAvatar = await hsResolver.ResolveMediaUri(hs.FullHomeServerDomain, User.AvatarUrl); profileName = User.DisplayName; _semaphoreSlim.Release(); diff --git a/MatrixRoomUtils.Web/_Imports.razor b/MatrixRoomUtils.Web/_Imports.razor index a92153d..91b69fb 100644 --- a/MatrixRoomUtils.Web/_Imports.razor +++ b/MatrixRoomUtils.Web/_Imports.razor @@ -16,7 +16,7 @@ @inject NavigationManager NavigationManager @inject MRUStorageWrapper MRUStorage -@inject HomeserverProviderService HomeserverProvider +@inject HomeserverProviderService hsProvider @inject TieredStorageService TieredStorage -@inject HomeserverResolverService HomeserverResolver +@inject HomeserverResolverService hsResolver @inject IJSRuntime JSRuntime diff --git a/MatrixRoomUtils.sln b/MatrixRoomUtils.sln index e29944e..79650cf 100755 --- a/MatrixRoomUtils.sln +++ b/MatrixRoomUtils.sln @@ -42,6 +42,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{7D2C9959 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.Tests", "LibMatrix\Tests\LibMatrix.Tests\LibMatrix.Tests.csproj", "{E37B78F1-D7A5-4F79-ADBA-E12DF7D0F881}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestDataGenerator", "LibMatrix\Tests\TestDataGenerator\TestDataGenerator.csproj", "{F3312DE9-4335-4E85-A4CF-2616427A651E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -108,6 +110,10 @@ Global {E37B78F1-D7A5-4F79-ADBA-E12DF7D0F881}.Debug|Any CPU.Build.0 = Debug|Any CPU {E37B78F1-D7A5-4F79-ADBA-E12DF7D0F881}.Release|Any CPU.ActiveCfg = Release|Any CPU {E37B78F1-D7A5-4F79-ADBA-E12DF7D0F881}.Release|Any CPU.Build.0 = Release|Any CPU + {F3312DE9-4335-4E85-A4CF-2616427A651E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3312DE9-4335-4E85-A4CF-2616427A651E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3312DE9-4335-4E85-A4CF-2616427A651E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3312DE9-4335-4E85-A4CF-2616427A651E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {F4E241C3-0300-4B87-8707-BCBDEF1F0185} = {8F4F6BEC-0C66-486B-A21A-1C35B2EDAD33} @@ -125,5 +131,6 @@ Global {95052EE6-7513-46FB-91BD-EE82026B42F1} = {3E0FDE30-8DA8-4E65-A3C6-AA53B5BC70A2} {7D2C9959-8309-4110-A67F-DEE64E97C1D8} = {8F4F6BEC-0C66-486B-A21A-1C35B2EDAD33} {E37B78F1-D7A5-4F79-ADBA-E12DF7D0F881} = {7D2C9959-8309-4110-A67F-DEE64E97C1D8} + {F3312DE9-4335-4E85-A4CF-2616427A651E} = {7D2C9959-8309-4110-A67F-DEE64E97C1D8} EndGlobalSection EndGlobal diff --git a/MatrixRoomUtils.sln.DotSettings b/MatrixRoomUtils.sln.DotSettings index 3da5982..19f4edd 100644 --- a/MatrixRoomUtils.sln.DotSettings +++ b/MatrixRoomUtils.sln.DotSettings @@ -1,3 +1,16 @@ <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/InspectionSeverities/=AsyncVoidMethod/@EntryIndexedValue">ERROR</s:String> - <s:String x:Key="/Default/CustomTools/CustomToolsData/@EntryValue"></s:String></wpf:ResourceDictionary> \ No newline at end of file + <s:String x:Key="/Default/CustomTools/CustomToolsData/@EntryValue"></s:String> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=ArcaneLibs_002EBlazor_002EComponents_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=ArcaneLibs_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=LibMatrix_002EDebugDataValidationApi_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=LibMatrix_002EExampleBot_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=LibMatrix_002ETests_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=MatrixRoomUtils_002EDesktop_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=MatrixRoomUtils_002EWeb_002EServer_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=MatrixRoomUtils_002EWeb_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=MediaModeratorPoC_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=MxApiExtensions_002EClasses_002ELibMatrix_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=MxApiExtensions_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=PluralContactBotPoC_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=TestDataGenerator_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> \ No newline at end of file diff --git a/MatrixRoomUtils.sln.DotSettings.user b/MatrixRoomUtils.sln.DotSettings.user index 67b8278..f9024a8 100644 --- a/MatrixRoomUtils.sln.DotSettings.user +++ b/MatrixRoomUtils.sln.DotSettings.user @@ -1,15 +1,49 @@ <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:Int64 x:Key="/Default/Dpa/Thresholds/=AllocationClosure/@EntryIndexedValue">0</s:Int64> - <s:Int64 x:Key="/Default/Dpa/Thresholds/=AllocationLoh/@EntryIndexedValue">0</s:Int64> - <s:Int64 x:Key="/Default/Dpa/Thresholds/=AllocationTopSoh/@EntryIndexedValue">0</s:Int64> + <s:Int64 x:Key="/Default/Dpa/Thresholds/=AllocationClosure/@EntryIndexedValue">1048576</s:Int64> + <s:Int64 x:Key="/Default/Dpa/Thresholds/=AllocationLoh/@EntryIndexedValue">1048576</s:Int64> + <s:Int64 x:Key="/Default/Dpa/Thresholds/=AllocationTopSoh/@EntryIndexedValue">1048576</s:Int64> + <s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue"><AssemblyExplorer> + <PhysicalFolder Path="/home/root@Rory/.cache/NuGetPackages/xunit.microsoft.dependencyinjection/7.0.6" Loaded="True" /> + <PhysicalFolder Path="/home/root@Rory/.cache/NuGetPackages/xunit.dependencyinjection.logging/8.1.0" Loaded="True" /> + <PhysicalFolder Path="/home/root@Rory/.cache/NuGetPackages/xunit.dependencyinjection/8.8.2" Loaded="True" /> +</AssemblyExplorer></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> <s:Int64 x:Key="/Default/Environment/Hierarchy/Build/SolutionBuilderNext/ParallelProcessesCount2/@EntryValue">12</s:Int64> <s:Boolean x:Key="/Default/Environment/Hierarchy/Build/SolutionBuilderNext/ShouldRestoreNugetPackages/@EntryValue">True</s:Boolean> + <s:String x:Key="/Default/Environment/Highlighting/HighlightingSourceSnapshotLocation/@EntryValue">/home/root@Rory/.cache/JetBrains/Rider2023.2/resharper-host/temp/Rider/vAny/CoverageData/_MatrixRoomUtils.2147452914/Snapshot/snapshot.utdcvr</s:String> + <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=10c2dea2_002D6490_002D4ee9_002D8f89_002D2bf8c99bcf8e/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &lt;LibMatrix&gt; #5" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Project Location="/home/root@Rory/git/Matrix/MatrixRoomUtils" Presentation="&lt;LibMatrix&gt;" /> +</SessionState></s:String> + <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=24cf7b5e_002D6eb8_002D4f8e_002D80e5_002Dba9e1170805a/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="All tests from &lt;LibMatrix&gt; #4" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Project Location="/home/root@Rory/git/Matrix/MatrixRoomUtils" Presentation="&lt;LibMatrix&gt;" /> +</SessionState></s:String> + <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=48531877_002D5653_002D452f_002D89ae_002D53fbe92c97ea/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="ResolveServer #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Project Location="/home/root@Rory/git/Matrix/MatrixRoomUtils" Presentation="&lt;LibMatrix&gt;" /> +</SessionState></s:String> + <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=48b84506_002D952d_002D4572_002D98a8_002D1e376317b969/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="ResolveServer" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <TestAncestor> + <TestId>xUnit::E37B78F1-D7A5-4F79-ADBA-E12DF7D0F881::net7.0::LibMatrix.Tests.ResolverTest.ResolveServer</TestId> + </TestAncestor> +</SessionState></s:String> + <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=623fef6c_002Df7ae_002D4fae_002Da334_002Dd5a3401cad40/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="All tests from &lt;LibMatrix&gt; #3" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Project Location="/home/root@Rory/git/Matrix/MatrixRoomUtils" Presentation="&lt;LibMatrix&gt;" /> +</SessionState></s:String> + <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=9a78b4c8_002Dbbc5_002D4dac_002D8f0d_002De17979623cbf/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="ResolveServer #3" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <TestAncestor> + <TestId>xUnit::E37B78F1-D7A5-4F79-ADBA-E12DF7D0F881::net7.0::LibMatrix.Tests.ResolverTest.ResolveServer</TestId> + </TestAncestor> +</SessionState></s:String> + <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=b41031ac_002Dfe6a_002D4ad7_002Db7d5_002D46c2a6404301/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="All tests from &lt;LibMatrix&gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Project Location="/home/root@Rory/git/Matrix/MatrixRoomUtils" Presentation="&lt;LibMatrix&gt;" /> +</SessionState></s:String> + <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=c33adfe1_002D4af3_002D4c1e_002D9689_002De5e34a9f9113/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="All tests from &lt;LibMatrix&gt; #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Project Location="/home/root@Rory/git/Matrix/MatrixRoomUtils" Presentation="&lt;LibMatrix&gt;" /> +</SessionState></s:String> |