From 712ad189c99570f686ab779782b2a873e172428e Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Tue, 13 Jun 2023 20:25:05 +0200 Subject: Change syntax style --- MatrixRoomUtils.Core/RemoteHomeServer.cs | 35 +++++++++++--------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'MatrixRoomUtils.Core/RemoteHomeServer.cs') diff --git a/MatrixRoomUtils.Core/RemoteHomeServer.cs b/MatrixRoomUtils.Core/RemoteHomeServer.cs index 942f873..3f50d2e 100644 --- a/MatrixRoomUtils.Core/RemoteHomeServer.cs +++ b/MatrixRoomUtils.Core/RemoteHomeServer.cs @@ -1,50 +1,39 @@ using System.Net.Http.Json; using System.Text.Json; +using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; namespace MatrixRoomUtils.Core; -public class RemoteHomeServer : IHomeServer -{ - - - public RemoteHomeServer(string canonicalHomeServerDomain) - { +public class RemoteHomeServer : IHomeServer { + public RemoteHomeServer(string canonicalHomeServerDomain) { HomeServerDomain = canonicalHomeServerDomain; - _httpClient = new HttpClient(); + _httpClient = new MatrixHttpClient(); _httpClient.Timeout = TimeSpan.FromSeconds(5); } - public async Task Configure() - { + + public async Task Configure() { FullHomeServerDomain = await ResolveHomeserverFromWellKnown(HomeServerDomain); _httpClient.Dispose(); - _httpClient = new HttpClient { BaseAddress = new Uri(FullHomeServerDomain) }; + _httpClient = new MatrixHttpClient { BaseAddress = new Uri(FullHomeServerDomain) }; _httpClient.Timeout = TimeSpan.FromSeconds(5); Console.WriteLine("[RHS] Finished setting up http client"); return this; } - - public async Task GetRoom(string roomId) - { - return new Room(_httpClient, roomId); - } - public async Task> GetJoinedRooms() - { + public async Task GetRoom(string roomId) => new Room(_httpClient, roomId); + + public async Task> GetJoinedRooms() { var rooms = new List(); var roomQuery = await _httpClient.GetAsync("/_matrix/client/v3/joined_rooms"); - if (!roomQuery.IsSuccessStatusCode) - { + if (!roomQuery.IsSuccessStatusCode) { Console.WriteLine($"Failed to get rooms: {await roomQuery.Content.ReadAsStringAsync()}"); throw new InvalidDataException($"Failed to get rooms: {await roomQuery.Content.ReadAsStringAsync()}"); } var roomsJson = await roomQuery.Content.ReadFromJsonAsync(); - foreach (var room in roomsJson.GetProperty("joined_rooms").EnumerateArray()) - { - rooms.Add(new Room(_httpClient, room.GetString())); - } + foreach (var room in roomsJson.GetProperty("joined_rooms").EnumerateArray()) rooms.Add(new Room(_httpClient, room.GetString())); return rooms; } -- cgit 1.4.1