about summary refs log tree commit diff
path: root/Tests/LibMatrix.HomeserverEmulator/Controllers/Users
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Tests/LibMatrix.HomeserverEmulator/Controllers/Users/UserController.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/Tests/LibMatrix.HomeserverEmulator/Controllers/Users/UserController.cs b/Tests/LibMatrix.HomeserverEmulator/Controllers/Users/UserController.cs
index eb2b879..e886d46 100644
--- a/Tests/LibMatrix.HomeserverEmulator/Controllers/Users/UserController.cs
+++ b/Tests/LibMatrix.HomeserverEmulator/Controllers/Users/UserController.cs
@@ -1,4 +1,5 @@
 using System.Text.Json.Nodes;

+using System.Text.Json.Serialization;

 using ArcaneLibs.Extensions;

 using LibMatrix.EventTypes.Spec.State;

 using LibMatrix.Filters;

@@ -55,4 +56,43 @@ public class UserController(ILogger<UserController> logger, TokenService tokenSe
             ).Select(r => r.RoomId).ToList()

         };

     }

+    

+    [HttpGet("devices")]

+    public async Task<DevicesResponse> GetDevices() {

+        var token = tokenService.GetAccessToken(HttpContext);

+        if (token is null)

+            throw new MatrixException() {

+                ErrorCode = "M_UNAUTHORIZED",

+                Error = "No token passed."

+            };

+

+        var user = await userStore.GetUserByToken(token, false);

+        if (user is null)

+            throw new MatrixException() {

+                ErrorCode = "M_UNAUTHORIZED",

+                Error = "Invalid token."

+            };

+        return new() {

+            Devices = user.AccessTokens.Select(x=>new DevicesResponse.Device() {

+                DeviceId = x.Value.DeviceId,

+                DisplayName = x.Value.DeviceId

+            }).ToList()

+        };

+    }

+

+    public class DevicesResponse {

+        [JsonPropertyName("devices")]

+        public List<Device> Devices { get; set; }

+        

+        public class Device {

+            [JsonPropertyName("device_id")]

+            public string DeviceId { get; set; }

+            [JsonPropertyName("display_name")]

+            public string DisplayName { get; set; }

+            [JsonPropertyName("last_seen_ip")]

+            public string LastSeenIp { get; set; }

+            [JsonPropertyName("last_seen_ts")]

+            public long LastSeenTs { get; set; }

+        }

+    }

 }
\ No newline at end of file