From ec1752307a4a273324cd8f13bb099fed6ff7ef3a Mon Sep 17 00:00:00 2001 From: "Emma@Rory&" Date: Tue, 19 Sep 2023 00:17:18 +0200 Subject: Refactors --- ArcaneLibs | 2 +- LibMatrix | 2 +- MatrixRoomUtils.Desktop/App.axaml.cs | 4 +-- .../Components/RoomListEntry.axaml.cs | 10 +++--- .../Classes/Constants/RoomConstants.cs | 5 ++- .../DefaultRoomCreationTemplate.cs | 2 +- MatrixRoomUtils.Web/Pages/About.razor | 12 +++---- MatrixRoomUtils.Web/Pages/Index.razor | 28 +++++++++++---- MatrixRoomUtils.Web/Pages/InvalidSession.razor | 2 +- MatrixRoomUtils.Web/Pages/LoginPage.razor | 2 +- MatrixRoomUtils.Web/Pages/MediaLocator.razor | 2 +- MatrixRoomUtils.Web/Pages/Rooms/Create.razor | 4 +-- MatrixRoomUtils.Web/Pages/Rooms/Index.razor | 8 ++--- MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor | 8 ++--- MatrixRoomUtils.Web/Pages/Rooms/Space.razor | 6 ++-- MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor | 2 +- MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor | 2 +- MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor | 5 +-- MatrixRoomUtils.Web/Pages/SpaceDebug.razor | 1 - MatrixRoomUtils.Web/Shared/InlineUserItem.razor | 7 ++-- MatrixRoomUtils.Web/Shared/RoomList.razor | 5 ++- .../RoomListComponents/RoomListCategory.razor | 3 +- MatrixRoomUtils.Web/Shared/RoomListItem.razor | 11 +++--- .../TimelineComponents/TimelineMemberItem.razor | 2 +- .../TimelineRoomCreateItem.razor | 2 +- MatrixRoomUtils.Web/Shared/UserListItem.razor | 7 ++-- MatrixRoomUtils.Web/_Imports.razor | 4 +-- MatrixRoomUtils.sln | 7 ++++ MatrixRoomUtils.sln.DotSettings | 15 +++++++- MatrixRoomUtils.sln.DotSettings.user | 40 ++++++++++++++++++++-- 30 files changed, 138 insertions(+), 72 deletions(-) diff --git a/ArcaneLibs b/ArcaneLibs index 78587a5..fadd59b 160000 --- a/ArcaneLibs +++ b/ArcaneLibs @@ -1 +1 @@ -Subproject commit 78587a5303754af87cdd999b7514e42b081aaceb +Subproject commit fadd59b2d7303546585f1543ddbbc268068a70a9 diff --git a/LibMatrix b/LibMatrix index 6bd0224..f544748 160000 --- a/LibMatrix +++ b/LibMatrix @@ -1 +1 @@ -Subproject commit 6bd02248ccfbcb46960a6f39eaad23888d190eb5 +Subproject commit f5447484512d726f4403f0d7725777d0a95601fb 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(); services.AddSingleton(x => new TieredStorageService( - cacheStorageProvider: new FileStorageProvider(x.GetService().CacheStoragePath), - dataStorageProvider: new FileStorageProvider(x.GetService().DataStoragePath) + cacheStorageProvider: new FileStorageProvider(x.GetService()!.CacheStoragePath), + dataStorageProvider: new FileStorageProvider(x.GetService()!.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().GetCurrentSessionOrPrompt(); - var storage = svc.ServiceProvider.GetService().CacheStorageProvider; - var resolvedUrl = MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, mxcUrl); + var hs = await svc.ServiceProvider.GetService()?.GetCurrentSessionOrPrompt()!; + var hsResolver = svc.ServiceProvider.GetService(); + var storage = svc.ServiceProvider.GetService()?.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 @@

You can find the source code on my git server.

You can also join the Matrix room for this project.

-@if (showBinDownload) { +@if (ShowBinDownload) {

This deployment also serves a copy of the compiled, hosting-ready binaries at /MRU-BIN.tar.xz!

} -@if (showSrcDownload) { +@if (ShowSrcDownload) {

This deployment also serves a copy of the compiled, hosting-ready binaries at /MRU-SRC.tar.xz!

} @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.

@user.DisplayName on @_auth.Homeserver + @if (_auth.Proxy != null) { + (proxied via @_auth.Proxy) + }

Member of @user.RoomCount rooms

@@ -35,6 +38,7 @@ Small collection of tools to do not-so-everyday things.

Manage Remove + Log out

@* *@ @@ -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 @@ Room icon: - +

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

Room list

@Status

@@ -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() }; 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

Policy list editor - Editing @RoomId


@@ -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

RoomManagerTimeline


Loaded @Events.Count events...

@@ -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

SpaceDebug

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
@@ -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)) {

Fetching room details... @RoomsWithTypes.Sum(x=>x.Value.Count) out of @Rooms.Count done!

@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
@roomType (@rooms.Count) 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
@if (OwnMemberState != null) { + src="@hsResolver.ResolveMediaUri(hs.FullHomeServerDomain, OwnMemberState.AvatarUrl ?? GlobalProfile.AvatarUrl ?? "/icon-192.png").Result"/> @(OwnMemberState?.Displayname ?? GlobalProfile?.DisplayName ?? "Loading...") @@ -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

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

@profileName @@ -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 @@  ERROR - \ No newline at end of file + + True + True + True + True + True + True + True + True + True + True + True + True + True \ 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 @@  DoNotShowAndRun - 0 - 0 - 0 + 1048576 + 1048576 + 1048576 + <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> 12 True No 12 True + /home/root@Rory/.cache/JetBrains/Rider2023.2/resharper-host/temp/Rider/vAny/CoverageData/_MatrixRoomUtils.2147452914/Snapshot/snapshot.utdcvr + <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> + <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> + <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> + <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> + <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> + <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> + <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> + <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> -- cgit 1.4.1