diff options
author | Emma [it/its]@Rory& <root@rory.gay> | 2024-04-05 18:58:32 +0200 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2024-04-05 18:58:32 +0200 |
commit | 37b97d65c0a5262539a5de560e911048166b8bba (patch) | |
tree | f704a9c703b0ec47122a460576e151e0cb06fdc6 /LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs | |
parent | Fix merge conficts between machines (diff) | |
download | LibMatrix-37b97d65c0a5262539a5de560e911048166b8bba.tar.xz |
Fix homeserver resolution, rewrite homeserver initialisation, HSE work
Diffstat (limited to 'LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs')
-rw-r--r-- | LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs | 108 |
1 files changed, 6 insertions, 102 deletions
diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs index 8df0c5b..307a226 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs @@ -1,113 +1,17 @@ using ArcaneLibs.Extensions; using LibMatrix.Filters; +using LibMatrix.Homeservers.ImplementationDetails.Synapse; using LibMatrix.Responses.Admin; +using LibMatrix.Services; namespace LibMatrix.Homeservers; public class AuthenticatedHomeserverSynapse : AuthenticatedHomeserverGeneric { - public readonly SynapseAdminApi Admin; + public readonly SynapseAdminApiClient Admin; - public class SynapseAdminApi(AuthenticatedHomeserverSynapse authenticatedHomeserver) { - public async IAsyncEnumerable<AdminRoomListingResult.AdminRoomListingResultRoom> SearchRoomsAsync(int limit = int.MaxValue, string orderBy = "name", string dir = "f", - string? searchTerm = null, LocalRoomQueryFilter? localFilter = null) { - AdminRoomListingResult? res = null; - var i = 0; - int? totalRooms = null; - do { - var url = $"/_synapse/admin/v1/rooms?limit={Math.Min(limit, 100)}&dir={dir}&order_by={orderBy}"; - if (!string.IsNullOrEmpty(searchTerm)) url += $"&search_term={searchTerm}"; - - if (res?.NextBatch is not null) url += $"&from={res.NextBatch}"; - - Console.WriteLine($"--- ADMIN Querying Room List with URL: {url} - Already have {i} items... ---"); - - res = await authenticatedHomeserver.ClientHttpClient.GetFromJsonAsync<AdminRoomListingResult>(url); - totalRooms ??= res.TotalRooms; - Console.WriteLine(res.ToJson(false)); - foreach (var room in res.Rooms) { - if (localFilter is not null) { - if (!room.RoomId.Contains(localFilter.RoomIdContains)) { - totalRooms--; - continue; - } - - if (!room.Name?.Contains(localFilter.NameContains) == true) { - totalRooms--; - continue; - } - - if (!room.CanonicalAlias?.Contains(localFilter.CanonicalAliasContains) == true) { - totalRooms--; - continue; - } - - if (!room.Version.Contains(localFilter.VersionContains)) { - totalRooms--; - continue; - } - - if (!room.Creator.Contains(localFilter.CreatorContains)) { - totalRooms--; - continue; - } - - if (!room.Encryption?.Contains(localFilter.EncryptionContains) == true) { - totalRooms--; - continue; - } - - if (!room.JoinRules?.Contains(localFilter.JoinRulesContains) == true) { - totalRooms--; - continue; - } - - if (!room.GuestAccess?.Contains(localFilter.GuestAccessContains) == true) { - totalRooms--; - continue; - } - - if (!room.HistoryVisibility?.Contains(localFilter.HistoryVisibilityContains) == true) { - totalRooms--; - continue; - } - - if (localFilter.CheckFederation && room.Federatable != localFilter.Federatable) { - totalRooms--; - continue; - } - - if (localFilter.CheckPublic && room.Public != localFilter.Public) { - totalRooms--; - continue; - } - - if (room.JoinedMembers < localFilter.JoinedMembersGreaterThan || room.JoinedMembers > localFilter.JoinedMembersLessThan) { - totalRooms--; - continue; - } - - if (room.JoinedLocalMembers < localFilter.JoinedLocalMembersGreaterThan || room.JoinedLocalMembers > localFilter.JoinedLocalMembersLessThan) { - totalRooms--; - continue; - } - } - // if (contentSearch is not null && !string.IsNullOrEmpty(contentSearch) && - // !( - // room.Name?.Contains(contentSearch, StringComparison.InvariantCultureIgnoreCase) == true || - // room.CanonicalAlias?.Contains(contentSearch, StringComparison.InvariantCultureIgnoreCase) == true || - // room.Creator?.Contains(contentSearch, StringComparison.InvariantCultureIgnoreCase) == true - // ) - // ) { - // totalRooms--; - // continue; - // } - - i++; - yield return room; - } - } while (i < Math.Min(limit, totalRooms ?? limit)); - } + public AuthenticatedHomeserverSynapse(string serverName, HomeserverResolverService.WellKnownUris wellKnownUris, ref string? proxy, string accessToken) : base(serverName, + wellKnownUris, ref proxy, accessToken) { + Admin = new(this); } - public AuthenticatedHomeserverSynapse(string serverName, string accessToken) : base(serverName, accessToken) => Admin = new SynapseAdminApi(this); } \ No newline at end of file |