about summary refs log tree commit diff
path: root/Tests/LibMatrix.HomeserverEmulator/Controllers/Users
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-03-22 16:38:53 +0000
committerRory& <root@rory.gay>2024-03-22 16:38:53 +0000
commit2b566a31b68f14d51faae61cbfbe359d0691a890 (patch)
treebfa1c6cc563f904bcae7c3461df8eb79e4e50290 /Tests/LibMatrix.HomeserverEmulator/Controllers/Users
parentNew messagebuilder stuff, table-based help command (diff)
downloadLibMatrix-2b566a31b68f14d51faae61cbfbe359d0691a890.tar.xz
Changes
Diffstat (limited to 'Tests/LibMatrix.HomeserverEmulator/Controllers/Users')
-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