about summary refs log tree commit diff
path: root/Utilities/LibMatrix.FederationTest/Controllers/Spec/DirectoryController.cs
blob: 707a149b977e81f7b155f79eb1a7c77332945d0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Net.Http.Headers;
using LibMatrix.Federation;
using LibMatrix.FederationTest.Services;
using LibMatrix.Homeservers;
using Microsoft.AspNetCore.Mvc;

namespace LibMatrix.FederationTest.Controllers.Spec;

[ApiController]
[Route("_matrix/federation/")]
public class DirectoryController(ServerAuthService serverAuth) : ControllerBase {
    [HttpGet("v1/publicRooms")]
    [HttpPost("v1/publicRooms")]
    public async Task<IActionResult> GetPublicRooms() {
        if (Request.Headers.ContainsKey("Authorization")) {
            Console.WriteLine("INFO | Authorization header found.");
            await serverAuth.AssertValidAuthentication();
        }
        else Console.WriteLine("INFO | Room directory request without auth");

        var rooms = new List<PublicRoomDirectoryResult.PublicRoomListItem> {
            new() {
                GuestCanJoin = false,
                RoomId = "!tuiLEoMqNOQezxILzt:rory.gay",
                NumJoinedMembers = Random.Shared.Next(),
                WorldReadable = false,
                CanonicalAlias = "#libmatrix:rory.gay",
                Name = "Rory&::LibMatrix",
                Topic = $"A .NET {Environment.Version.Major} library for interacting with Matrix"
            }
        };
        return Ok(new PublicRoomDirectoryResult() {
            Chunk = rooms,
            TotalRoomCountEstimate = rooms.Count
        });
    }

    [HttpGet("v1/query/profile")]
    public async Task<IActionResult> GetProfile([FromQuery(Name = "user_id")] string userId) {
        if (Request.Headers.ContainsKey("Authorization")) {
            Console.WriteLine("INFO | Authorization header found.");
            await serverAuth.AssertValidAuthentication();
        }
        else Console.WriteLine("INFO | Profile request without auth");

        return Ok(new {
            avatar_url = "mxc://rory.gay/ocRVanZoUTCcifcVNwXgbtTg",
            displayname = "Rory&::LibMatrix.FederationTest"
        });
    }
}