Internal changes to policy list viewer (extensibility), fix duplicating change handler for room list page (performance), use /state in room list page before sync
1 files changed, 63 insertions, 26 deletions
diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor
index 2d1d6c0..ebb0ebb 100644
--- a/MatrixRoomUtils.Web/Pages/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Index.razor
@@ -16,30 +16,29 @@ Small collection of tools to do not-so-everyday things.
<hr/>
<form>
<table>
- @foreach (var __auth in _auth.OrderByDescending(x => x.UserInfo.RoomCount)) {
- var _auth = __auth.UserAuth;
+ @foreach (var session in _sessions.OrderByDescending(x => x.UserInfo.RoomCount)) {
+ var _auth = session.UserAuth;
<tr class="user-entry">
<td>
- <img class="avatar" src="@__auth.UserInfo.AvatarUrl"/>
+ <img class="avatar" src="@session.UserInfo.AvatarUrl"/>
</td>
<td class="user-info">
- @* <div class="user-info"> *@
<p>
<input type="radio" name="csa" checked="@(_currentSession.AccessToken == _auth.AccessToken)" @onclick="@(() => SwitchSession(_auth))" style="text-decoration-line: unset;"/>
- <b>@__auth.UserInfo.DisplayName</b> on <b>@_auth.Homeserver</b><br/>
+ <b>@session.UserInfo.DisplayName</b> on <b>@_auth.Homeserver</b><br/>
</p>
- <span style="display: inline-block; width: 128px;">@__auth.UserInfo.RoomCount rooms</span>
- <a style="color: #888888" href="@("/ServerInfo/"+__auth.Homeserver.ServerName+"/")">@__auth.ServerVersion.Server.Name @__auth.ServerVersion.Server.Version</a>
+ <span style="display: inline-block; width: 128px;">@session.UserInfo.RoomCount rooms</span>
+ <a style="color: #888888" href="@("/ServerInfo/" + session.Homeserver.ServerName + "/")">@session.ServerVersion.Server.Name @session.ServerVersion.Server.Version</a>
@if (_auth.Proxy != null) {
<span class="badge badge-info"> (proxied via @_auth.Proxy)</span>
}
else {
<p>Not proxied</p>
}
- @if (DEBUG) {
- <p>T=@__auth.Homeserver.GetType().FullName</p>
- <p>D=@__auth.Homeserver.WhoAmI.DeviceId</p>
- <p>U=@__auth.Homeserver.WhoAmI.UserId</p>
+ @if (_debug) {
+ <p>T=@session.Homeserver.GetType().FullName</p>
+ <p>D=@session.Homeserver.WhoAmI.DeviceId</p>
+ <p>U=@session.Homeserver.WhoAmI.UserId</p>
}
</td>
<td>
@@ -49,18 +48,46 @@ Small collection of tools to do not-so-everyday things.
<LinkButton OnClick="@(() => RemoveUser(_auth, true))">Log out</LinkButton>
</p>
</td>
- @* </div> *@
</tr>
}
</table>
</form>
+@if (_offlineSessions.Count > 0) {
+ <br/>
+ <br/>
+ <h5>Sessions on unreachable servers</h5>
+ <hr/>
+ <form>
+ <table>
+ @foreach (var session in _offlineSessions) {
+ <tr class="user-entry">
+ <td>
+ <p>
+ @{
+ string[] parts = session.UserId.Split(':');
+ }
+ <span>@parts[0][1..]</span> on <span>@parts[1]</span>
+ @if (!string.IsNullOrWhiteSpace(session.Proxy)) {
+ <span class="badge badge-info"> (proxied via @session.Proxy)</span>
+ }
+ </p>
+ </td>
+ <td>
+ <LinkButton OnClick="@(() => RemoveUser(session))">Remove</LinkButton>
+ </td>
+ </tr>
+ }
+ </table>
+ </form>
+}
+
@code
{
#if DEBUG
- bool DEBUG = true;
+ private const bool _debug = true;
#else
- bool DEBUG = false;
+ private const bool _debug = false;
#endif
private class AuthInfo {
@@ -71,35 +98,42 @@ Small collection of tools to do not-so-everyday things.
}
// private Dictionary<UserAuth, UserInfo> _users = new();
- private List<AuthInfo> _auth = new();
+ private readonly List<AuthInfo> _sessions = [];
+ private readonly List<UserAuth> _offlineSessions = [];
+ private LoginResponse? _currentSession;
protected override async Task OnInitializedAsync() {
+ Console.WriteLine("Index.OnInitializedAsync");
_currentSession = await MRUStorage.GetCurrentToken();
- // _users.Clear();
- _auth.Clear();
+ _sessions.Clear();
+ _offlineSessions.Clear();
var tokens = await MRUStorage.GetAllTokens();
var profileTasks = tokens.Select(async token => {
UserInfo userInfo = new();
AuthenticatedHomeserverGeneric hs;
+ Console.WriteLine($"Getting hs for {token.ToJson()}");
try {
hs = await hsProvider.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken, token.Proxy);
}
catch (MatrixException e) {
- if (e.ErrorCode == "M_UNKNOWN_TOKEN") {
- NavigationManager.NavigateTo("/InvalidSession?ctx=" + token.AccessToken);
- return;
- }
- throw;
+ if (e.ErrorCode != "M_UNKNOWN_TOKEN") throw;
+ NavigationManager.NavigateTo("/InvalidSession?ctx=" + token.AccessToken);
+ return;
+
}
catch (HttpRequestException e) {
logger.LogError(e, $"Failed to instantiate AuthenticatedHomeserver for {token.ToJson()}, homeserver may be offline?", token.UserId);
+ _offlineSessions.Add(token);
return;
}
+
+ Console.WriteLine($"Got hs for {token.ToJson()}");
+
var roomCountTask = hs.GetJoinedRooms();
var profile = await hs.GetProfileAsync(hs.WhoAmI.UserId);
userInfo.DisplayName = profile.DisplayName ?? hs.WhoAmI.UserId;
Console.WriteLine(profile.ToJson());
- _auth.Add(new() {
+ _sessions.Add(new() {
UserInfo = new() {
AvatarUrl = string.IsNullOrWhiteSpace(profile.AvatarUrl) ? "https://api.dicebear.com/6.x/identicon/svg?seed=" + hs.WhoAmI.UserId : hs.ResolveMediaUri(profile.AvatarUrl),
RoomCount = (await roomCountTask).Count,
@@ -110,7 +144,9 @@ Small collection of tools to do not-so-everyday things.
Homeserver = hs
});
});
+ Console.WriteLine("Waiting for profile tasks");
await Task.WhenAll(profileTasks);
+ Console.WriteLine("Done waiting for profile tasks");
await base.OnInitializedAsync();
}
@@ -127,19 +163,20 @@ Small collection of tools to do not-so-everyday things.
}
}
catch (Exception e) {
- if (e is MatrixException {ErrorCode: "M_UNKNOWN_TOKEN" }) {
- //todo: handle this
+ 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)
await MRUStorage.SetCurrentToken((await MRUStorage.GetAllTokens() ?? throw new InvalidOperationException()).FirstOrDefault());
await OnInitializedAsync();
}
- private LoginResponse _currentSession;
private async Task SwitchSession(UserAuth auth) {
Console.WriteLine($"Switching to {auth.Homeserver} {auth.UserId} via {auth.Proxy}");
|