From 46df5b8e335754f1582fc4d41d9546808ed8ee66 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Fri, 29 Sep 2023 19:38:00 +0200 Subject: Unit tests, small refactors --- LibMatrix/Responses/CreateRoomRequest.cs | 2 +- LibMatrix/Responses/LoginResponse.cs | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'LibMatrix/Responses') diff --git a/LibMatrix/Responses/CreateRoomRequest.cs b/LibMatrix/Responses/CreateRoomRequest.cs index 381271b..511b3da 100644 --- a/LibMatrix/Responses/CreateRoomRequest.cs +++ b/LibMatrix/Responses/CreateRoomRequest.cs @@ -40,7 +40,7 @@ public class CreateRoomRequest { public JsonObject CreationContent { get; set; } = new(); [JsonPropertyName("invite")] - public List Invite { get; set; } + public List? Invite { get; set; } /// /// For use only when you can't use the CreationContent property diff --git a/LibMatrix/Responses/LoginResponse.cs b/LibMatrix/Responses/LoginResponse.cs index 175f337..eb53c0a 100644 --- a/LibMatrix/Responses/LoginResponse.cs +++ b/LibMatrix/Responses/LoginResponse.cs @@ -1,19 +1,30 @@ using System.Text.Json.Serialization; +using LibMatrix.Homeservers; +using LibMatrix.Services; namespace LibMatrix.Responses; public class LoginResponse { [JsonPropertyName("access_token")] - public string AccessToken { get; set; } + public string AccessToken { get; set; } = null!; [JsonPropertyName("device_id")] - public string DeviceId { get; set; } + public string DeviceId { get; set; } = null!; + + private string? _homeserver; [JsonPropertyName("home_server")] - public string Homeserver { get; set; } + public string Homeserver { + get => _homeserver ?? UserId.Split(':', 2).Last(); + protected init => _homeserver = value; + } [JsonPropertyName("user_id")] - public string UserId { get; set; } + public string UserId { get; set; } = null!; + + public async Task GetAuthenticatedHomeserver(string? proxy = null) { + return new AuthenticatedHomeserverGeneric(proxy ?? await new HomeserverResolverService().ResolveHomeserverFromWellKnown(Homeserver), AccessToken); + } } public class LoginRequest { [JsonPropertyName("type")] -- cgit 1.4.1