diff options
Diffstat (limited to '')
20 files changed, 53 insertions, 36 deletions
diff --git a/LibMatrix.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs b/LibMatrix.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs index b62b448..48739f2 100644 --- a/LibMatrix.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs +++ b/LibMatrix.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = EventId)] -public class RoomTypingEventContent : TimelineEventContent { +public class RoomTypingEventContent : EventContent { public const string EventId = "m.typing"; [JsonPropertyName("user_ids")] diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs index 53b85b8..14c7cf6 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State.RoomInfo; [MatrixEvent(EventName = EventId)] -public class RoomAliasEventContent : TimelineEventContent { +public class RoomAliasEventContent : EventContent { public const string EventId = "m.room.alias"; [JsonPropertyName("aliases")] diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs index d15e88e..62de70c 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State.RoomInfo; [MatrixEvent(EventName = EventId)] -public class RoomAvatarEventContent : TimelineEventContent { +public class RoomAvatarEventContent : EventContent { public const string EventId = "m.room.avatar"; [JsonPropertyName("url")] diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs index 265775e..dd96016 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = EventId)] -public class RoomCanonicalAliasEventContent : TimelineEventContent { +public class RoomCanonicalAliasEventContent : EventContent { public const string EventId = "m.room.canonical_alias"; [JsonPropertyName("alias")] diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs index 7d25dc7..02867e4 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = EventId)] -public class RoomCreateEventContent : TimelineEventContent { +public class RoomCreateEventContent : EventContent { public const string EventId = "m.room.create"; [JsonPropertyName("room_version")] diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs index 8e9e05f..992b57c 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = "m.room.encryption")] -public class RoomEncryptionEventContent : TimelineEventContent { +public class RoomEncryptionEventContent : EventContent { [JsonPropertyName("algorithm")] public string? Algorithm { get; set; } [JsonPropertyName("rotation_period_ms")] diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs index 30f2def..4f62eb1 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = "m.room.guest_access")] -public class RoomGuestAccessEventContent : TimelineEventContent { +public class RoomGuestAccessEventContent : EventContent { [JsonPropertyName("guest_access")] public required string GuestAccess { get; set; } diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs index 26d40e1..48ba538 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = "m.room.history_visibility")] -public class RoomHistoryVisibilityEventContent : TimelineEventContent { +public class RoomHistoryVisibilityEventContent : EventContent { [JsonPropertyName("history_visibility")] public required string HistoryVisibility { get; set; } } diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs index e300b5d..0663288 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = "m.room.join_rules")] -public class RoomJoinRulesEventContent : TimelineEventContent { +public class RoomJoinRulesEventContent : EventContent { /// <summary> /// one of ["public", "invite", "knock", "restricted", "knock_restricted"] /// "private" is reserved without implementation! @@ -12,7 +12,7 @@ public class RoomJoinRulesEventContent : TimelineEventContent { public string JoinRuleValue { get; set; } [JsonIgnore] - public required JoinRules JoinRule { + public JoinRules JoinRule { get => JoinRuleValue switch { "public" => JoinRules.Public, "invite" => JoinRules.Invite, diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs index 7e4f9b6..1a64f40 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = EventId)] -public class RoomMemberEventContent : TimelineEventContent { +public class RoomMemberEventContent : EventContent { public const string EventId = "m.room.member"; [JsonPropertyName("reason")] diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs index 00a1e8f..1c4513b 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = EventId)] -public class RoomNameEventContent : TimelineEventContent { +public class RoomNameEventContent : EventContent { public const string EventId = "m.room.name"; [JsonPropertyName("name")] diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs index 9bbcd90..b033d82 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = "m.room.pinned_events")] -public class RoomPinnedEventContent : TimelineEventContent { +public class RoomPinnedEventContent : EventContent { [JsonPropertyName("pinned")] public string[]? PinnedEvents { get; set; } } diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs index 1a09ab8..15c742c 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = EventId)] -public class RoomPowerLevelEventContent : TimelineEventContent { +public class RoomPowerLevelEventContent : EventContent { public const string EventId = "m.room.power_levels"; [JsonPropertyName("ban")] diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs index 75337f5..c1e1127 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = "m.room.server_acl")] -public class RoomServerACLEventContent : TimelineEventContent { +public class RoomServerACLEventContent : EventContent { [JsonPropertyName("allow")] public List<string>? Allow { get; set; } // = null!; diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs index 3121c39..37536d2 100644 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs @@ -4,7 +4,7 @@ namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = "m.room.topic")] [MatrixEvent(EventName = "org.matrix.msc3765.topic", Legacy = true)] -public class RoomTopicEventContent : TimelineEventContent { +public class RoomTopicEventContent : EventContent { [JsonPropertyName("topic")] public string? Topic { get; set; } } diff --git a/LibMatrix.EventTypes/Spec/State/Space/SpaceChildEventContent.cs b/LibMatrix.EventTypes/Spec/State/Space/SpaceChildEventContent.cs index fb5c938..2caa791 100644 --- a/LibMatrix.EventTypes/Spec/State/Space/SpaceChildEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/Space/SpaceChildEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = "m.space.child")] -public class SpaceChildEventContent : TimelineEventContent { +public class SpaceChildEventContent : EventContent { [JsonPropertyName("auto_join")] public bool? AutoJoin { get; set; } [JsonPropertyName("via")] diff --git a/LibMatrix.EventTypes/Spec/State/Space/SpaceParentEventContent.cs b/LibMatrix.EventTypes/Spec/State/Space/SpaceParentEventContent.cs index 0c23298..180f4b7 100644 --- a/LibMatrix.EventTypes/Spec/State/Space/SpaceParentEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/Space/SpaceParentEventContent.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace LibMatrix.EventTypes.Spec.State; [MatrixEvent(EventName = "m.space.parent")] -public class SpaceParentEventContent : TimelineEventContent { +public class SpaceParentEventContent : EventContent { [JsonPropertyName("via")] public string[]? Via { get; set; } diff --git a/LibMatrix/Helpers/MessageFormatter.cs b/LibMatrix/Helpers/MessageFormatter.cs index f275b57..b2dda61 100644 --- a/LibMatrix/Helpers/MessageFormatter.cs +++ b/LibMatrix/Helpers/MessageFormatter.cs @@ -6,14 +6,14 @@ namespace LibMatrix.Helpers; public static class MessageFormatter { public static RoomMessageEventContent FormatError(string error) { return new RoomMessageEventContent(body: error, messageType: "m.text") { - FormattedBody = $"<font color=\"#FF0000\">{error}</font>", + FormattedBody = $"<font color=\"#EE4444\">{error}</font>", Format = "org.matrix.custom.html" }; } public static RoomMessageEventContent FormatException(string error, Exception e) { return new RoomMessageEventContent(body: $"{error}: {e.Message}", messageType: "m.text") { - FormattedBody = $"<font color=\"#FF0000\">{error}: <pre>{e.Message}</pre></font>", + FormattedBody = $"<font color=\"#EE4444\">{error}: <pre>{e.Message}</pre></font>", Format = "org.matrix.custom.html" }; } diff --git a/LibMatrix/Responses/CreateRoomRequest.cs b/LibMatrix/Responses/CreateRoomRequest.cs index f8d1d05..3b93cf7 100644 --- a/LibMatrix/Responses/CreateRoomRequest.cs +++ b/LibMatrix/Responses/CreateRoomRequest.cs @@ -56,7 +56,7 @@ public class CreateRoomRequest { TypedContent = (EventContent)Activator.CreateInstance( StateEvent.KnownStateEventTypes.FirstOrDefault(x => x.GetCustomAttributes<MatrixEventAttribute>()? - .Any(y => y.EventName == eventType) ?? false) ?? typeof(object) + .Any(y => y.EventName == eventType) ?? false) ?? typeof(UnknownEventContent) )! }); } diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs index d067f9f..0cedf29 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs @@ -9,6 +9,7 @@ using LibMatrix.EventTypes.Spec; using LibMatrix.EventTypes.Spec.State; using LibMatrix.EventTypes.Spec.State.RoomInfo; using LibMatrix.Homeservers; +using LibMatrix.Services; namespace LibMatrix.RoomTypes; @@ -136,6 +137,7 @@ public class GenericRoom { Console.WriteLine("End is null"); yield break; } + from = resp.End; } } @@ -174,7 +176,6 @@ public class GenericRoom { Console.WriteLine($"Members call response read in {sw.GetElapsedAndRestart()}"); var result = await JsonSerializer.DeserializeAsync<ChunkedStateEventResponse>(await res.Content.ReadAsStreamAsync(), new JsonSerializerOptions() { TypeInfoResolver = ChunkedStateEventResponseSerializerContext.Default, - }); Console.WriteLine($"Members call deserialised in {sw.GetElapsedAndRestart()}"); foreach (var resp in result.Chunk) { @@ -186,7 +187,7 @@ public class GenericRoom { Console.WriteLine($"Members call iterated in {sw.GetElapsedAndRestart()}"); } - #region Utility shortcuts +#region Utility shortcuts public async Task<EventIdResponse> SendMessageEventAsync(RoomMessageEventContent content) => await SendTimelineEventAsync("m.room.message", content); @@ -254,9 +255,25 @@ public class GenericRoom { await Task.WhenAll(tasks); } - #endregion + public async Task<string?> GetResolvedRoomAvatarUrlAsync(bool useOriginHomeserver = false) { + var avatar = await GetAvatarUrlAsync(); + if (avatar?.Url is null) return null; + if (!avatar.Url.StartsWith("mxc://")) return avatar.Url; + if (useOriginHomeserver) + try { + var hs = avatar.Url.Split('/', 3)[1]; + return await new HomeserverResolverService().ResolveMediaUri(hs, avatar.Url); + } + catch (Exception e) { + Console.WriteLine(e); + } + + return Homeserver.ResolveMediaUri(avatar.Url); + } + +#endregion - #region Simple calls +#region Simple calls public async Task ForgetAsync() => await Homeserver.ClientHttpClient.PostAsync($"/_matrix/client/v3/rooms/{RoomId}/forget", null); @@ -284,9 +301,9 @@ public class GenericRoom { await Homeserver.ClientHttpClient.PostAsJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/invite", new UserIdAndReason(userId, reason)); } - #endregion +#endregion - #region Events +#region Events public async Task<EventIdResponse?> SendStateEventAsync(string eventType, object content) => await (await Homeserver.ClientHttpClient.PutAsJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/state/{eventType}", content)) @@ -347,9 +364,9 @@ public class GenericRoom { $"/_matrix/client/v3/rooms/{RoomId}/redact/{eventToRedact}/{Guid.NewGuid()}", data)).Content.ReadFromJsonAsync<EventIdResponse>())!; } - #endregion +#endregion - #region Utilities +#region Utilities public async Task<Dictionary<string, List<string>>> GetMembersByHomeserverAsync(bool joinedOnly = true) { if (Homeserver is AuthenticatedHomeserverMxApiExtended mxaeHomeserver) @@ -367,11 +384,7 @@ public class GenericRoom { return roomHomeservers; } - #endregion - - public readonly SpaceRoom AsSpace; - - #region Disband room +#region Disband room public async Task DisbandRoomAsync() { var states = GetFullStateAsync(); @@ -398,10 +411,14 @@ public class GenericRoom { } } - #endregion +#endregion + +#endregion + + public readonly SpaceRoom AsSpace; } public class RoomIdResponse { [JsonPropertyName("room_id")] public string RoomId { get; set; } = null!; -} +} \ No newline at end of file |