about summary refs log tree commit diff
path: root/Utilities/LibMatrix.HomeserverEmulator/Controllers/DirectoryController.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-11-16 03:33:00 +0100
committerRory& <root@rory.gay>2024-11-16 03:33:00 +0100
commit652cabb51294064f51b6459f000c75941f412a27 (patch)
tree653448091fb00175db72806825d8712512a2c5c0 /Utilities/LibMatrix.HomeserverEmulator/Controllers/DirectoryController.cs
parentUpdate to .NET 9 (diff)
downloadLibMatrix-652cabb51294064f51b6459f000c75941f412a27.tar.xz
HSE updates
Diffstat (limited to '')
-rw-r--r--Utilities/LibMatrix.HomeserverEmulator/Controllers/DirectoryController.cs33
1 files changed, 33 insertions, 0 deletions
diff --git a/Utilities/LibMatrix.HomeserverEmulator/Controllers/DirectoryController.cs b/Utilities/LibMatrix.HomeserverEmulator/Controllers/DirectoryController.cs

index 52d5932..b29edf5 100644 --- a/Utilities/LibMatrix.HomeserverEmulator/Controllers/DirectoryController.cs +++ b/Utilities/LibMatrix.HomeserverEmulator/Controllers/DirectoryController.cs
@@ -1,5 +1,6 @@ using System.Text.Json.Nodes; using System.Text.Json.Serialization; +using ArcaneLibs.Extensions; using LibMatrix.EventTypes.Spec.State; using LibMatrix.HomeserverEmulator.Services; using LibMatrix.Homeservers; @@ -12,6 +13,8 @@ namespace LibMatrix.HomeserverEmulator.Controllers; [ApiController] [Route("/_matrix/")] public class DirectoryController(ILogger<DirectoryController> logger, RoomStore roomStore) : ControllerBase { +#region Room directory + [HttpGet("client/v3/directory/room/{alias}")] public async Task<AliasResult> GetRoomAliasV3(string alias) { var match = roomStore._rooms.FirstOrDefault(x => @@ -31,4 +34,34 @@ public class DirectoryController(ILogger<DirectoryController> logger, RoomStore Servers = servers }; } + +#endregion + +#region User directory + + [HttpPost("client/v3/user_directory/search")] + public async Task<UserDirectoryResponse> SearchUserDirectory([FromBody] UserDirectoryRequest request) { + var users = roomStore._rooms + .SelectMany(x => x.State.Where(y => + y.Type == RoomMemberEventContent.EventId + && y.RawContent?["membership"]?.ToString() == "join" + && (y.StateKey!.ContainsAnyCase(request.SearchTerm) || y.RawContent?["displayname"]?.ToString()?.ContainsAnyCase(request.SearchTerm) == true) + ) + ) + .DistinctBy(x => x.StateKey) + .ToList(); + + request.Limit ??= 10; + + return new() { + Results = users.Select(x => new UserDirectoryResponse.UserDirectoryResult { + UserId = x.StateKey!, + DisplayName = x.RawContent?["displayname"]?.ToString(), + AvatarUrl = x.RawContent?["avatar_url"]?.ToString() + }).ToList(), + Limited = users.Count > request.Limit + }; + } + +#endregion } \ No newline at end of file