diff options
Diffstat (limited to 'LibMatrix')
6 files changed, 18 insertions, 8 deletions
diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs index 4cca32c..5513904 100644 --- a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs @@ -3,8 +3,9 @@ using LibMatrix.Interfaces; namespace LibMatrix.EventTypes.Spec.State; -[MatrixEvent(EventName = "m.room.avatar")] +[MatrixEvent(EventName = EventId)] public class RoomAvatarEventContent : EventContent { + public const string EventId = "m.room.avatar"; [JsonPropertyName("url")] public string? Url { get; set; } diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs index 275203c..46c4000 100644 --- a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs @@ -3,8 +3,10 @@ using LibMatrix.Interfaces; namespace LibMatrix.EventTypes.Spec.State; -[MatrixEvent(EventName = "m.room.create")] +[MatrixEvent(EventName = EventId)] public class RoomCreateEventContent : EventContent { + public const string EventId = "m.room.create"; + [JsonPropertyName("room_version")] public string? RoomVersion { get; set; } diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs index e475012..ea174d7 100644 --- a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs @@ -3,8 +3,10 @@ using LibMatrix.Interfaces; namespace LibMatrix.EventTypes.Spec.State; -[MatrixEvent(EventName = "m.room.name")] +[MatrixEvent(EventName = EventId)] public class RoomNameEventContent : EventContent { + public const string EventId = "m.room.name"; + [JsonPropertyName("name")] public string? Name { get; set; } -} +} \ No newline at end of file diff --git a/LibMatrix/Extensions/EnumerableExtensions.cs b/LibMatrix/Extensions/EnumerableExtensions.cs index d9619b7..0c98bfe 100644 --- a/LibMatrix/Extensions/EnumerableExtensions.cs +++ b/LibMatrix/Extensions/EnumerableExtensions.cs @@ -1,7 +1,7 @@ namespace LibMatrix.Extensions; public static class EnumerableExtensions { - public static void MergeStateEventLists(this List<StateEvent> oldState, List<StateEvent> newState) { + public static void MergeStateEventLists(this IList<StateEvent> oldState, IList<StateEvent> newState) { foreach (var stateEvent in newState) { var old = oldState.FirstOrDefault(x => x.Type == stateEvent.Type && x.StateKey == stateEvent.StateKey); if (old is null) { @@ -13,7 +13,7 @@ public static class EnumerableExtensions { } } - public static void MergeStateEventLists(this List<StateEventResponse> oldState, List<StateEventResponse> newState) { + public static void MergeStateEventLists(this IList<StateEventResponse> oldState, IList<StateEventResponse> newState) { foreach (var stateEvent in newState) { var old = oldState.FirstOrDefault(x => x.Type == stateEvent.Type && x.StateKey == stateEvent.StateKey); if (old is null) { diff --git a/LibMatrix/Extensions/HttpClientExtensions.cs b/LibMatrix/Extensions/HttpClientExtensions.cs index d280ef3..5bb0dc2 100644 --- a/LibMatrix/Extensions/HttpClientExtensions.cs +++ b/LibMatrix/Extensions/HttpClientExtensions.cs @@ -80,6 +80,7 @@ public class MatrixHttpClient : HttpClient { // GetFromJsonAsync public async Task<T> GetFromJsonAsync<T>(string requestUri, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) { options = GetJsonSerializerOptions(options); + // Console.WriteLine($"GetFromJsonAsync called for {requestUri} with json options {options?.ToJson(ignoreNull:true)} and cancellation token {cancellationToken}"); var request = new HttpRequestMessage(HttpMethod.Get, requestUri); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await SendAsync(request, cancellationToken); diff --git a/LibMatrix/Helpers/SyncHelper.cs b/LibMatrix/Helpers/SyncHelper.cs index bfcd650..c6c5378 100644 --- a/LibMatrix/Helpers/SyncHelper.cs +++ b/LibMatrix/Helpers/SyncHelper.cs @@ -15,15 +15,19 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg public bool FullState { get; set; } = false; public bool IsInitialSync { get; set; } = true; - + public async Task<SyncResponse?> SyncAsync(CancellationToken? cancellationToken = null) { + if (homeserver is null) { + Console.WriteLine("Null passed as homeserver for SyncHelper!"); + throw new ArgumentNullException("Null passed as homeserver for SyncHelper!"); + } var url = $"/_matrix/client/v3/sync?timeout={Timeout}&set_presence={SetPresence}&full_state={(FullState ? "true" : "false")}"; if (!string.IsNullOrWhiteSpace(Since)) url += $"&since={Since}"; if (Filter is not null) url += $"&filter={Filter.ToJson(ignoreNull: true, indent: false)}"; // Console.WriteLine("Calling: " + url); logger?.LogInformation("SyncHelper: Calling: {}", url); try { - return await homeserver._httpClient.GetFromJsonAsync<SyncResponse>(url, cancellationToken: cancellationToken ?? CancellationToken.None); + return await homeserver?._httpClient?.GetFromJsonAsync<SyncResponse>(url, cancellationToken: cancellationToken ?? CancellationToken.None)!; } catch (TaskCanceledException) { Console.WriteLine("Sync cancelled!"); |