From a357bec1831611758a19bf23ff0fa5a5fe99ca52 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sun, 28 May 2023 11:30:53 +0200 Subject: Add changes --- MatrixRoomUtils.Core/AuthenticatedHomeServer.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'MatrixRoomUtils.Core/AuthenticatedHomeServer.cs') diff --git a/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs b/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs index 502fe5b..be085c1 100644 --- a/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs +++ b/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs @@ -1,7 +1,9 @@ using System.Net.Http.Headers; using System.Net.Http.Json; using System.Text.Json; +using System.Text.Json.Nodes; using MatrixRoomUtils.Core.Interfaces; +using MatrixRoomUtils.Core.Responses; namespace MatrixRoomUtils.Core; @@ -72,6 +74,17 @@ public class AuthenticatedHomeServer : IHomeServer } + public async Task CreateRoom(CreateRoomRequest creationEvent) + { + var res = await _httpClient.PostAsJsonAsync("/_matrix/client/r0/createRoom", creationEvent); + if (!res.IsSuccessStatusCode) + { + Console.WriteLine($"Failed to create room: {await res.Content.ReadAsStringAsync()}"); + throw new InvalidDataException($"Failed to create room: {await res.Content.ReadAsStringAsync()}"); + } + + return await GetRoom((await res.Content.ReadFromJsonAsync())!["room_id"]!.ToString()!); + } @@ -83,12 +96,6 @@ public class AuthenticatedHomeServer : IHomeServer { _authenticatedHomeServer = authenticatedHomeServer; } - - - - - - - } + } -- cgit 1.5.1