diff options
Diffstat (limited to 'MatrixRoomUtils.Web/Pages')
-rw-r--r-- | MatrixRoomUtils.Web/Pages/About.razor | 12 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/Index.razor | 28 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/InvalidSession.razor | 2 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/LoginPage.razor | 2 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/MediaLocator.razor | 2 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/Rooms/Create.razor | 4 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/Rooms/Index.razor | 8 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor | 8 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/Rooms/Space.razor | 6 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor | 2 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor | 2 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor | 5 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/Pages/SpaceDebug.razor | 1 |
13 files changed, 49 insertions, 33 deletions
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> |