diff options
author | Rory& <root@rory.gay> | 2024-03-22 16:38:53 +0000 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-03-22 16:38:53 +0000 |
commit | 2b566a31b68f14d51faae61cbfbe359d0691a890 (patch) | |
tree | bfa1c6cc563f904bcae7c3461df8eb79e4e50290 /Tests/LibMatrix.HomeserverEmulator/Controllers/Users | |
parent | New messagebuilder stuff, table-based help command (diff) | |
download | LibMatrix-2b566a31b68f14d51faae61cbfbe359d0691a890.tar.xz |
Changes
Diffstat (limited to 'Tests/LibMatrix.HomeserverEmulator/Controllers/Users')
-rw-r--r-- | Tests/LibMatrix.HomeserverEmulator/Controllers/Users/UserController.cs | 40 |
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 |