about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-08-09 21:12:11 +0200
committerRory& <root@rory.gay>2024-08-09 21:12:11 +0200
commita2d4a4a82d849c5f6b0b34a97b35927db96bdef2 (patch)
tree745218b6107fd117a0187f3e23d907dcdce1737c
parentMore synapse admin apis (diff)
downloadLibMatrix-a2d4a4a82d849c5f6b0b34a97b35927db96bdef2.tar.xz
Minor cleanup
m---------ArcaneLibs0
-rw-r--r--LibMatrix/Extensions/MatrixHttpClient.Single.cs4
-rw-r--r--LibMatrix/Helpers/HomeserverWeightEstimation.cs58
-rw-r--r--LibMatrix/Helpers/MessageBuilder.cs2
-rw-r--r--LibMatrix/Helpers/SyncStateResolver.cs6
-rw-r--r--LibMatrix/Services/HomeserverResolverService.cs10
-rw-r--r--LibMatrix/StateEvent.cs3
7 files changed, 13 insertions, 70 deletions
diff --git a/ArcaneLibs b/ArcaneLibs
-Subproject 4d32676b97001f6988d1e62e53fbc837ef3fefc
+Subproject 2befb4f38c101f71a885acf8f6d442f8ace34dd
diff --git a/LibMatrix/Extensions/MatrixHttpClient.Single.cs b/LibMatrix/Extensions/MatrixHttpClient.Single.cs
index bab3e92..a5e94e5 100644
--- a/LibMatrix/Extensions/MatrixHttpClient.Single.cs
+++ b/LibMatrix/Extensions/MatrixHttpClient.Single.cs
@@ -59,7 +59,7 @@ public class MatrixHttpClient {
         typeof(HttpRequestHeaders).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, [], null)?.Invoke([]) as HttpRequestHeaders ??
         throw new InvalidOperationException("Failed to create HttpRequestHeaders");
 
-    private JsonSerializerOptions GetJsonSerializerOptions(JsonSerializerOptions? options = null) {
+    private static JsonSerializerOptions GetJsonSerializerOptions(JsonSerializerOptions? options = null) {
         options ??= new JsonSerializerOptions();
         options.Converters.Add(new JsonFloatStringConverter());
         options.Converters.Add(new JsonDoubleStringConverter());
@@ -224,7 +224,7 @@ public class MatrixHttpClient {
         await foreach (var resp in result) yield return resp;
     }
 
-    public async Task<bool> CheckSuccessStatus(string url) {
+    public static async Task<bool> CheckSuccessStatus(string url) {
         //cors causes failure, try to catch
         try {
             var resp = await Client.GetAsync(url);
diff --git a/LibMatrix/Helpers/HomeserverWeightEstimation.cs b/LibMatrix/Helpers/HomeserverWeightEstimation.cs
deleted file mode 100644
index 5735af3..0000000
--- a/LibMatrix/Helpers/HomeserverWeightEstimation.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-namespace LibMatrix.Helpers;
-
-public class HomeserverWeightEstimation {
-    public static Dictionary<string, int> EstimatedSize = new() {
-        { "matrix.org", 843870 },
-        { "anontier.nl", 44809 },
-        { "nixos.org", 8195 },
-        { "the-apothecary.club", 6983 },
-        { "waifuhunter.club", 3953 },
-        { "neko.dev", 2666 },
-        { "nerdsin.space", 2647 },
-        { "feline.support", 2633 },
-        { "gitter.im", 2584 },
-        { "midov.pl", 2219 },
-        { "no.lgbtqia.zone", 2083 },
-        { "nheko.im", 1883 },
-        { "fachschaften.org", 1849 },
-        { "pixelthefox.net", 1478 },
-        { "arcticfoxes.net", 981 },
-        { "pixie.town", 817 },
-        { "privacyguides.org", 809 },
-        { "rory.gay", 653 },
-        { "artemislena.eu", 599 },
-        { "alchemi.dev", 445 },
-        { "jameskitt616.one", 390 },
-        { "hackint.org", 382 },
-        { "pikaviestin.fi", 368 },
-        { "matrix.nomagic.uk", 337 },
-        { "thearcanebrony.net", 178 },
-        { "fairydust.space", 176 },
-        { "grin.hu", 176 },
-        { "envs.net", 165 },
-        { "tastytea.de", 143 },
-        { "koneko.chat", 121 },
-        { "vscape.tk", 115 },
-        { "funklause.de", 112 },
-        { "seirdy.one", 107 },
-        { "pcg.life", 72 },
-        { "draupnir.midnightthoughts.space", 22 },
-        { "tchncs.de", 19 },
-        { "catgirl.cloud", 16 },
-        { "possum.city", 16 },
-        { "tu-dresden.de", 9 },
-        { "fosscord.com", 9 },
-        { "nightshade.fun", 8 },
-        { "matrix.eclipse.org", 8 },
-        { "masfloss.net", 8 },
-        { "e2e.zone", 8 },
-        { "hyteck.de", 8 }
-    };
-
-    public static Dictionary<string, int> LargeRooms = new() {
-        { "!ehXvUhWNASUkSLvAGP:matrix.org", 21957 },
-        { "!fRRqjOaQcUbKOfCjvc:anontier.nl", 19117 },
-        { "!OGEhHVWSdvArJzumhm:matrix.org", 101457 },
-        { "!YTvKGNlinIzlkMTVRl:matrix.org", 30164 }
-    };
-}
\ No newline at end of file
diff --git a/LibMatrix/Helpers/MessageBuilder.cs b/LibMatrix/Helpers/MessageBuilder.cs
index d897078..cfda6b3 100644
--- a/LibMatrix/Helpers/MessageBuilder.cs
+++ b/LibMatrix/Helpers/MessageBuilder.cs
@@ -93,7 +93,7 @@ public class MessageBuilder(string msgType = "m.text", string format = "org.matr
 
     public MessageBuilder WithTable(Action<TableBuilder> tableBuilder) {
         var tb = new TableBuilder(this);
-        this.WithHtmlTag("table", msb => tableBuilder(tb));
+        WithHtmlTag("table", msb => tableBuilder(tb));
         return this;
     }
 
diff --git a/LibMatrix/Helpers/SyncStateResolver.cs b/LibMatrix/Helpers/SyncStateResolver.cs
index 0daccec..e2dbdee 100644
--- a/LibMatrix/Helpers/SyncStateResolver.cs
+++ b/LibMatrix/Helpers/SyncStateResolver.cs
@@ -142,7 +142,7 @@ public class SyncStateResolver(AuthenticatedHomeserverGeneric homeserver, ILogge
         return oldState;
     }
 
-    private SyncResponse.RoomsDataStructure.LeftRoomDataStructure MergeLeftRoomDataStructure(SyncResponse.RoomsDataStructure.LeftRoomDataStructure oldData,
+    private static SyncResponse.RoomsDataStructure.LeftRoomDataStructure MergeLeftRoomDataStructure(SyncResponse.RoomsDataStructure.LeftRoomDataStructure oldData,
         SyncResponse.RoomsDataStructure.LeftRoomDataStructure newData) {
         oldData.AccountData ??= new EventList();
         oldData.AccountData.Events ??= [];
@@ -165,7 +165,7 @@ public class SyncStateResolver(AuthenticatedHomeserverGeneric homeserver, ILogge
         return oldData;
     }
 
-    private SyncResponse.RoomsDataStructure.InvitedRoomDataStructure MergeInvitedRoomDataStructure(SyncResponse.RoomsDataStructure.InvitedRoomDataStructure oldData,
+    private static SyncResponse.RoomsDataStructure.InvitedRoomDataStructure MergeInvitedRoomDataStructure(SyncResponse.RoomsDataStructure.InvitedRoomDataStructure oldData,
         SyncResponse.RoomsDataStructure.InvitedRoomDataStructure newData) {
         oldData.InviteState ??= new EventList();
         oldData.InviteState.Events ??= [];
@@ -175,7 +175,7 @@ public class SyncStateResolver(AuthenticatedHomeserverGeneric homeserver, ILogge
         return oldData;
     }
 
-    private SyncResponse.RoomsDataStructure.JoinedRoomDataStructure MergeJoinedRoomDataStructure(SyncResponse.RoomsDataStructure.JoinedRoomDataStructure oldData,
+    private static SyncResponse.RoomsDataStructure.JoinedRoomDataStructure MergeJoinedRoomDataStructure(SyncResponse.RoomsDataStructure.JoinedRoomDataStructure oldData,
         SyncResponse.RoomsDataStructure.JoinedRoomDataStructure newData) {
         oldData.AccountData ??= new EventList();
         oldData.AccountData.Events ??= [];
diff --git a/LibMatrix/Services/HomeserverResolverService.cs b/LibMatrix/Services/HomeserverResolverService.cs
index f899230..dc8e047 100644
--- a/LibMatrix/Services/HomeserverResolverService.cs
+++ b/LibMatrix/Services/HomeserverResolverService.cs
@@ -85,9 +85,9 @@ public class HomeserverResolverService {
             clientWellKnown ??= await _httpClient.TryGetFromJsonAsync<ClientWellKnown>($"http://{homeserver}/.well-known/matrix/client");
 
             if (clientWellKnown is null) {
-                if (await _httpClient.CheckSuccessStatus($"https://{homeserver}/_matrix/client/versions"))
+                if (await MatrixHttpClient.CheckSuccessStatus($"https://{homeserver}/_matrix/client/versions"))
                     return $"https://{homeserver}";
-                if (await _httpClient.CheckSuccessStatus($"http://{homeserver}/_matrix/client/versions"))
+                if (await MatrixHttpClient.CheckSuccessStatus($"http://{homeserver}/_matrix/client/versions"))
                     return $"http://{homeserver}";
             }
         }
@@ -122,16 +122,16 @@ public class HomeserverResolverService {
             var resolved = serverWellKnown.Homeserver;
             if (resolved.StartsWith("https://") || resolved.StartsWith("http://"))
                 return resolved;
-            if (await _httpClient.CheckSuccessStatus($"https://{resolved}/_matrix/federation/v1/version"))
+            if (await MatrixHttpClient.CheckSuccessStatus($"https://{resolved}/_matrix/federation/v1/version"))
                 return $"https://{resolved}";
-            if (await _httpClient.CheckSuccessStatus($"http://{resolved}/_matrix/federation/v1/version"))
+            if (await MatrixHttpClient.CheckSuccessStatus($"http://{resolved}/_matrix/federation/v1/version"))
                 return $"http://{resolved}";
             _logger.LogWarning("Server well-known points to invalid server: {resolved}", resolved);
         }
 
         // fallback: most servers host C2S and S2S on the same domain
         var clientUrl = await _tryResolveClientEndpoint(homeserver);
-        if (clientUrl is not null && await _httpClient.CheckSuccessStatus($"{clientUrl}/_matrix/federation/v1/version"))
+        if (clientUrl is not null && await MatrixHttpClient.CheckSuccessStatus($"{clientUrl}/_matrix/federation/v1/version"))
             return clientUrl;
 
         _logger.LogInformation("No server well-known for {server}...", homeserver);
diff --git a/LibMatrix/StateEvent.cs b/LibMatrix/StateEvent.cs
index 58ae7d2..75d4b12 100644
--- a/LibMatrix/StateEvent.cs
+++ b/LibMatrix/StateEvent.cs
@@ -13,7 +13,7 @@ using LibMatrix.Extensions;
 namespace LibMatrix;
 
 public class StateEvent {
-    public static FrozenSet<Type> KnownStateEventTypes { get; } = new ClassCollector<EventContent>().ResolveFromAllAccessibleAssemblies().ToFrozenSet();
+    public static FrozenSet<Type> KnownStateEventTypes { get; } = ClassCollector<EventContent>.ResolveFromAllAccessibleAssemblies().ToFrozenSet();
 
     public static FrozenDictionary<string, Type> KnownStateEventTypesByName { get; } = KnownStateEventTypes.Aggregate(
         new Dictionary<string, Type>(),
@@ -55,6 +55,7 @@ public class StateEvent {
     [SuppressMessage("ReSharper", "PropertyCanBeMadeInitOnly.Global")]
     public EventContent? TypedContent {
         get {
+            ClassCollector<EventContent>.ResolveFromAllAccessibleAssemblies();
             // if (Type == "m.receipt") {
             // return null;
             // }