about summary refs log tree commit diff
path: root/Tests/LibMatrix.HomeserverEmulator/Controllers/VersionsController.cs
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2024-04-05 18:58:32 +0200
committerEmma [it/its]@Rory& <root@rory.gay>2024-04-05 18:58:32 +0200
commit37b97d65c0a5262539a5de560e911048166b8bba (patch)
treef704a9c703b0ec47122a460576e151e0cb06fdc6 /Tests/LibMatrix.HomeserverEmulator/Controllers/VersionsController.cs
parentFix merge conficts between machines (diff)
downloadLibMatrix-37b97d65c0a5262539a5de560e911048166b8bba.tar.xz
Fix homeserver resolution, rewrite homeserver initialisation, HSE work
Diffstat (limited to 'Tests/LibMatrix.HomeserverEmulator/Controllers/VersionsController.cs')
-rw-r--r--Tests/LibMatrix.HomeserverEmulator/Controllers/VersionsController.cs186
1 files changed, 95 insertions, 91 deletions
diff --git a/Tests/LibMatrix.HomeserverEmulator/Controllers/VersionsController.cs b/Tests/LibMatrix.HomeserverEmulator/Controllers/VersionsController.cs
index 704e26b..0c3bde6 100644
--- a/Tests/LibMatrix.HomeserverEmulator/Controllers/VersionsController.cs
+++ b/Tests/LibMatrix.HomeserverEmulator/Controllers/VersionsController.cs
@@ -1,92 +1,96 @@
-using System.Text.Json.Nodes;

-using System.Text.Json.Serialization;

-using LibMatrix.Homeservers;

-using LibMatrix.Responses;

-using LibMatrix.Services;

-using Microsoft.AspNetCore.Mvc;

-

-namespace LibMatrix.HomeserverEmulator.Controllers;

-

-[ApiController]

-[Route("/_matrix/")]

-public class VersionsController(ILogger<WellKnownController> logger) : ControllerBase {

-    [HttpGet("client/versions")]

-    public async Task<ClientVersionsResponse> GetClientVersions() {

-        var clientVersions = new ClientVersionsResponse {

-            Versions = new() {

-                "r0.0.1",

-                "r0.1.0",

-                "r0.2.0",

-                "r0.3.0",

-                "r0.4.0",

-                "r0.5.0",

-                "r0.6.0",

-                "r0.6.1",

-                "v1.1",

-                "v1.2",

-                "v1.3",

-                "v1.4",

-                "v1.5",

-                "v1.6",

-                "v1.7",

-                "v1.8",

-            },

-            UnstableFeatures = new()

-        };

-        return clientVersions;

-    }

-

-    [HttpGet("federation/v1/version")]

-    public async Task<ServerVersionResponse> GetServerVersions() {

-        var clientVersions = new ServerVersionResponse() {

-            Server = new() {

-                Name = "LibMatrix.HomeserverEmulator",

-                Version = "0.0.0"

-            }

-        };

-        return clientVersions;

-    }

-

-    [HttpGet("client/{version}/capabilities")]

-    public async Task<CapabilitiesResponse> GetCapabilities() {

-        return new() {

-            Capabilities = new() {

-                ChangePassword = new() {

-                    Enabled = false

-                },

-                RoomVersions = new() {

-                    Default = "11",

-                    Available = new() {

-                        ["11"] = "unstable"

-                    }

-                }

-            }

-        };

-    }

-}

-

-public class CapabilitiesResponse {

-    [JsonPropertyName("capabilities")]

-    public CapabilitiesContent Capabilities { get; set; }

-

-    public class CapabilitiesContent {

-        [JsonPropertyName("m.room_versions")]

-        public RoomVersionsContent RoomVersions { get; set; }

-        

-        [JsonPropertyName("m.change_password")]

-        public ChangePasswordContent ChangePassword { get; set; }

-

-        public class ChangePasswordContent {

-            [JsonPropertyName("enabled")]

-            public bool Enabled { get; set; }

-        }

-

-        public class RoomVersionsContent {

-            [JsonPropertyName("default")]

-            public string Default { get; set; }

-

-            [JsonPropertyName("available")]

-            public Dictionary<string, string> Available { get; set; }

-        }

-    }

+using System.Text.Json.Nodes;
+using System.Text.Json.Serialization;
+using LibMatrix.Homeservers;
+using LibMatrix.Responses;
+using LibMatrix.Services;
+using Microsoft.AspNetCore.Mvc;
+
+namespace LibMatrix.HomeserverEmulator.Controllers;
+
+[ApiController]
+[Route("/_matrix/")]
+public class VersionsController(ILogger<WellKnownController> logger) : ControllerBase {
+    [HttpGet("client/versions")]
+    public async Task<ClientVersionsResponse> GetClientVersions() {
+        var clientVersions = new ClientVersionsResponse {
+            Versions = new() {
+                "r0.0.1",
+                "r0.1.0",
+                "r0.2.0",
+                "r0.3.0",
+                "r0.4.0",
+                "r0.5.0",
+                "r0.6.0",
+                "r0.6.1",
+                "v1.1",
+                "v1.2",
+                "v1.3",
+                "v1.4",
+                "v1.5",
+                "v1.6",
+                "v1.7",
+                "v1.8",
+            },
+            UnstableFeatures = new()
+        };
+        return clientVersions;
+    }
+
+    [HttpGet("federation/v1/version")]
+    public async Task<ServerVersionResponse> GetServerVersions() {
+        var clientVersions = new ServerVersionResponse() {
+            Server = new() {
+                Name = "LibMatrix.HomeserverEmulator",
+                Version = "0.0.0"
+            }
+        };
+        return clientVersions;
+    }
+
+    [HttpGet("client/{version}/capabilities")]
+    public async Task<CapabilitiesResponse> GetCapabilities() {
+        var caps = new CapabilitiesResponse() {
+            Capabilities = new() {
+                ChangePassword = new() {
+                    Enabled = false
+                },
+                RoomVersions = new() {
+                    Default = "11",
+                    Available = []
+                }
+            }
+        };
+
+        for (int i = 0; i < 15; i++) {
+            caps.Capabilities.RoomVersions.Available.Add(i.ToString(), "stable");
+        }
+
+        return caps;
+    }
+}
+
+public class CapabilitiesResponse {
+    [JsonPropertyName("capabilities")]
+    public CapabilitiesContent Capabilities { get; set; }
+
+    public class CapabilitiesContent {
+        [JsonPropertyName("m.room_versions")]
+        public RoomVersionsContent RoomVersions { get; set; }
+
+        [JsonPropertyName("m.change_password")]
+        public ChangePasswordContent ChangePassword { get; set; }
+
+        public class ChangePasswordContent {
+            [JsonPropertyName("enabled")]
+            public bool Enabled { get; set; }
+        }
+
+        public class RoomVersionsContent {
+            [JsonPropertyName("default")]
+            public string Default { get; set; }
+
+            [JsonPropertyName("available")]
+            public Dictionary<string, string> Available { get; set; }
+        }
+    }
 }
\ No newline at end of file