about summary refs log tree commit diff
path: root/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomStateController.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/Rooms/RoomStateController.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/Rooms/RoomStateController.cs')
-rw-r--r--Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomStateController.cs31
1 files changed, 16 insertions, 15 deletions
diff --git a/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomStateController.cs b/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomStateController.cs
index cb5f213..3896ac0 100644
--- a/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomStateController.cs
+++ b/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomStateController.cs
@@ -10,7 +10,7 @@ namespace LibMatrix.HomeserverEmulator.Controllers.Rooms;
 public class RoomStateController(ILogger<RoomStateController> logger, TokenService tokenService, UserStore userStore, RoomStore roomStore) : ControllerBase {
     [HttpGet("")]
     public async Task<FrozenSet<StateEventResponse>> GetState(string roomId) {
-        var token = tokenService.GetAccessToken(HttpContext);
+        var token = tokenService.GetAccessTokenOrNull(HttpContext);
         if (token == null)
             throw new MatrixException() {
                 ErrorCode = "M_MISSING_TOKEN",
@@ -23,7 +23,7 @@ public class RoomStateController(ILogger<RoomStateController> logger, TokenServi
                 ErrorCode = "M_UNKNOWN_TOKEN",
                 Error = "No such user"
             };
-        
+
         var room = roomStore.GetRoomById(roomId);
         if (room == null)
             throw new MatrixException() {
@@ -33,15 +33,15 @@ public class RoomStateController(ILogger<RoomStateController> logger, TokenServi
 
         return room.State;
     }
-    
+
     [HttpGet("{eventType}")]
-    public async Task<StateEventResponse> GetState(string roomId, string eventType) {
-        return await GetState(roomId, eventType, "");
+    public async Task<object?> GetState(string roomId, string eventType, [FromQuery] string format = "client") {
+        return await GetState(roomId, eventType, "", format);
     }
-    
+
     [HttpGet("{eventType}/{stateKey}")]
-    public async Task<StateEventResponse> GetState(string roomId, string eventType, string stateKey) {
-        var token = tokenService.GetAccessToken(HttpContext);
+    public async Task<object?> GetState(string roomId, string eventType, string stateKey, [FromQuery] string format = "client") {
+        var token = tokenService.GetAccessTokenOrNull(HttpContext);
         if (token == null)
             throw new MatrixException() {
                 ErrorCode = "M_MISSING_TOKEN",
@@ -54,7 +54,7 @@ public class RoomStateController(ILogger<RoomStateController> logger, TokenServi
                 ErrorCode = "M_UNKNOWN_TOKEN",
                 Error = "No such user"
             };
-        
+
         var room = roomStore.GetRoomById(roomId);
         if (room == null)
             throw new MatrixException() {
@@ -68,17 +68,18 @@ public class RoomStateController(ILogger<RoomStateController> logger, TokenServi
                 ErrorCode = "M_NOT_FOUND",
                 Error = "Event not found"
             };
-        return stateEvent;
+        // return stateEvent;
+        return format == "event" ? stateEvent : stateEvent.RawContent;
     }
-        
+
     [HttpPut("{eventType}")]
     public async Task<EventIdResponse> SetState(string roomId, string eventType, [FromBody] StateEvent request) {
         return await SetState(roomId, eventType, "", request);
     }
-    
+
     [HttpPut("{eventType}/{stateKey}")]
     public async Task<EventIdResponse> SetState(string roomId, string eventType, string stateKey, [FromBody] StateEvent request) {
-        var token = tokenService.GetAccessToken(HttpContext);
+        var token = tokenService.GetAccessTokenOrNull(HttpContext);
         if (token == null)
             throw new MatrixException() {
                 ErrorCode = "M_MISSING_TOKEN",
@@ -91,7 +92,7 @@ public class RoomStateController(ILogger<RoomStateController> logger, TokenServi
                 ErrorCode = "M_UNKNOWN_TOKEN",
                 Error = "No such user"
             };
-        
+
         var room = roomStore.GetRoomById(roomId);
         if (room == null)
             throw new MatrixException() {
@@ -101,7 +102,7 @@ public class RoomStateController(ILogger<RoomStateController> logger, TokenServi
         var evt = room.SetStateInternal(request.ToStateEvent(user, room));
         evt.Type = eventType;
         evt.StateKey = stateKey;
-        return new EventIdResponse(){
+        return new EventIdResponse() {
             EventId = evt.EventId ?? throw new InvalidOperationException("EventId is null")
         };
     }