From 30a0868789466012bab869af4300aef5a9cac108 Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 30 May 2024 09:46:43 +0000 Subject: Rename legacy event types --- .../Common/MjolnirShortcodeEventContent.cs | 11 --- .../Common/MjolnirShortcodeLegacyEventContent.cs | 11 +++ .../Common/RoomEmotesEventContent.cs | 24 ------ .../Common/RoomEmotesLegacyEventContent.cs | 24 ++++++ LibMatrix.LegacyEvents.EventTypes/EventContent.cs | 48 ----------- .../LegacyEventContent.cs | 48 +++++++++++ .../LegacyMatrixEventAttribute.cs | 7 ++ .../MatrixEventAttribute.cs | 7 -- .../Spec/Ephemeral/PresenceLegacyEventContent.cs | 30 +++++++ .../Spec/Ephemeral/PresenceStateEventContent.cs | 30 ------- .../Spec/Ephemeral/RoomTypingEventContent.cs | 11 --- .../Spec/Ephemeral/RoomTypingLegacyEventContent.cs | 11 +++ .../Spec/RoomMessageEventContent.cs | 56 ------------- .../Spec/RoomMessageLegacyEventContent.cs | 56 +++++++++++++ .../Spec/RoomMessageReactionEventContent.cs | 6 -- .../Spec/RoomMessageReactionLegacyEventContent.cs | 6 ++ .../State/Policy/PolicyRuleStateEventContent.cs | 28 +++---- .../Spec/State/RoomInfo/RoomAliasEventContent.cs | 11 --- .../State/RoomInfo/RoomAliasLegacyEventContent.cs | 11 +++ .../Spec/State/RoomInfo/RoomAvatarEventContent.cs | 28 ------- .../State/RoomInfo/RoomAvatarLegacyEventContent.cs | 28 +++++++ .../RoomInfo/RoomCanonicalAliasEventContent.cs | 14 ---- .../RoomCanonicalAliasLegacyEventContent.cs | 14 ++++ .../Spec/State/RoomInfo/RoomCreateEventContent.cs | 31 -------- .../State/RoomInfo/RoomCreateLegacyEventContent.cs | 31 ++++++++ .../State/RoomInfo/RoomEncryptionEventContent.cs | 17 ---- .../RoomInfo/RoomEncryptionLegacyEventContent.cs | 17 ++++ .../State/RoomInfo/RoomGuestAccessEventContent.cs | 17 ---- .../RoomInfo/RoomGuestAccessLegacyEventContent.cs | 17 ++++ .../RoomInfo/RoomHistoryVisibilityEventContent.cs | 11 --- .../RoomHistoryVisibilityLegacyEventContent.cs | 11 +++ .../State/RoomInfo/RoomJoinRulesEventContent.cs | 60 -------------- .../RoomInfo/RoomJoinRulesLegacyEventContent.cs | 60 ++++++++++++++ .../Spec/State/RoomInfo/RoomMemberEventContent.cs | 37 --------- .../State/RoomInfo/RoomMemberLegacyEventContent.cs | 37 +++++++++ .../Spec/State/RoomInfo/RoomNameEventContent.cs | 11 --- .../State/RoomInfo/RoomNameLegacyEventContent.cs | 11 +++ .../Spec/State/RoomInfo/RoomPinnedEventContent.cs | 11 --- .../State/RoomInfo/RoomPinnedLegacyEventContent.cs | 11 +++ .../State/RoomInfo/RoomPowerLevelEventContent.cs | 93 ---------------------- .../RoomInfo/RoomPowerLevelLegacyEventContent.cs | 93 ++++++++++++++++++++++ .../State/RoomInfo/RoomServerACLEventContent.cs | 17 ---- .../RoomInfo/RoomServerAclLegacyEventContent.cs | 17 ++++ .../Spec/State/RoomInfo/RoomTopicEventContent.cs | 12 --- .../State/RoomInfo/RoomTopicLegacyEventContent.cs | 12 +++ .../Spec/State/Space/SpaceChildEventContent.cs | 17 ---- .../State/Space/SpaceChildLegacyEventContent.cs | 17 ++++ .../Spec/State/Space/SpaceParentEventContent.cs | 14 ---- .../State/Space/SpaceParentLegacyEventContent.cs | 14 ++++ LibMatrix/Helpers/MessageBuilder.cs | 4 +- LibMatrix/Helpers/MessageFormatter.cs | 18 ++--- .../Homeservers/AuthenticatedHomeserverGeneric.cs | 12 +-- LibMatrix/LegacyMatrixEvent.cs | 14 ++-- LibMatrix/Responses/CreateRoomRequest.cs | 16 ++-- LibMatrix/RoomTypes/GenericRoom.cs | 48 +++++------ LibMatrix/Utilities/CommonSyncFilters.cs | 16 ++-- Tests/TestDataGenerator/Bot/DataFetcher.cs | 12 +-- .../Program.cs | 2 +- .../Commands/AliassesCommand.cs | 2 +- .../Commands/PingCommand.cs | 2 +- .../Interfaces/CommandContext.cs | 4 +- .../Services/CommandListenerHostedService.cs | 16 ++-- 62 files changed, 691 insertions(+), 691 deletions(-) delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Common/MjolnirShortcodeEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Common/MjolnirShortcodeLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Common/RoomEmotesEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Common/RoomEmotesLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/EventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/LegacyEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/LegacyMatrixEventAttribute.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/MatrixEventAttribute.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/PresenceLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/RoomTypingLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageReactionEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageReactionLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAvatarLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCreateLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomEncryptionLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomGuestAccessLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomJoinRulesLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomMemberLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomNameLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPinnedLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPowerLevelLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomServerAclLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomTopicLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceChildEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceChildLegacyEventContent.cs delete mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceParentEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceParentLegacyEventContent.cs diff --git a/LibMatrix.LegacyEvents.EventTypes/Common/MjolnirShortcodeEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Common/MjolnirShortcodeEventContent.cs deleted file mode 100644 index be8c154..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Common/MjolnirShortcodeEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Common; - -[MatrixEvent(EventName = EventId)] -public class MjolnirShortcodeEventContent : TimelineEventContent { - public const string EventId = "org.matrix.mjolnir.shortcode"; - - [JsonPropertyName("shortcode")] - public string? Shortcode { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Common/MjolnirShortcodeLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Common/MjolnirShortcodeLegacyEventContent.cs new file mode 100644 index 0000000..25c53a6 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Common/MjolnirShortcodeLegacyEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Common; + +[LegacyMatrixEvent(EventName = EventId)] +public class MjolnirShortcodeLegacyEventContent : TimelineLegacyEventContent { + public const string EventId = "org.matrix.mjolnir.shortcode"; + + [JsonPropertyName("shortcode")] + public string? Shortcode { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Common/RoomEmotesEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Common/RoomEmotesEventContent.cs deleted file mode 100644 index ee268d9..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Common/RoomEmotesEventContent.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Common; - -[MatrixEvent(EventName = EventId)] -public class RoomEmotesEventContent : TimelineEventContent { - public const string EventId = "im.ponies.room_emotes"; - - [JsonPropertyName("emoticons")] - public Dictionary? Emoticons { get; set; } - - [JsonPropertyName("images")] - public Dictionary? Images { get; set; } - - [JsonPropertyName("pack")] - public PackInfo? Pack { get; set; } - - public class EmoticonData { - [JsonPropertyName("url")] - public string? Url { get; set; } - } - - public class PackInfo; // TODO: Implement this -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Common/RoomEmotesLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Common/RoomEmotesLegacyEventContent.cs new file mode 100644 index 0000000..a884359 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Common/RoomEmotesLegacyEventContent.cs @@ -0,0 +1,24 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Common; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomEmotesLegacyEventContent : TimelineLegacyEventContent { + public const string EventId = "im.ponies.room_emotes"; + + [JsonPropertyName("emoticons")] + public Dictionary? Emoticons { get; set; } + + [JsonPropertyName("images")] + public Dictionary? Images { get; set; } + + [JsonPropertyName("pack")] + public PackInfo? Pack { get; set; } + + public class EmoticonData { + [JsonPropertyName("url")] + public string? Url { get; set; } + } + + public class PackInfo; // TODO: Implement this +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/EventContent.cs b/LibMatrix.LegacyEvents.EventTypes/EventContent.cs deleted file mode 100644 index 3e76459..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/EventContent.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Text.Json; -using System.Text.Json.Nodes; -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes; - -public abstract class EventContent; - -public class UnknownEventContent : TimelineEventContent; - -public abstract class TimelineEventContent : EventContent { - [JsonPropertyName("m.relates_to")] - public MessageRelatesTo? RelatesTo { get; set; } - - [JsonPropertyName("m.new_content")] - public JsonObject? NewContent { get; set; } - - public TimelineEventContent SetReplaceRelation(string eventId) { - NewContent = JsonSerializer.SerializeToNode(this, GetType())!.AsObject(); - // NewContent = JsonSerializer.Deserialize(jsonText, GetType()); - RelatesTo = new MessageRelatesTo { - RelationType = "m.replace", - EventId = eventId - }; - return this; - } - - public T SetReplaceRelation(string eventId) where T : TimelineEventContent => SetReplaceRelation(eventId) as T ?? throw new InvalidOperationException(); - - public class MessageRelatesTo { - [JsonPropertyName("m.in_reply_to")] - public EventInReplyTo? InReplyTo { get; set; } - - [JsonPropertyName("event_id")] - public string? EventId { get; set; } - - [JsonPropertyName("rel_type")] - public string? RelationType { get; set; } - - public class EventInReplyTo { - [JsonPropertyName("event_id")] - public string? EventId { get; set; } - - [JsonPropertyName("rel_type")] - public string? RelType { get; set; } - } - } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/LegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/LegacyEventContent.cs new file mode 100644 index 0000000..002a85f --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/LegacyEventContent.cs @@ -0,0 +1,48 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes; + +public abstract class LegacyEventContent; + +public class UnknownLegacyEventContent : TimelineLegacyEventContent; + +public abstract class TimelineLegacyEventContent : LegacyEventContent { + [JsonPropertyName("m.relates_to")] + public MessageRelatesTo? RelatesTo { get; set; } + + [JsonPropertyName("m.new_content")] + public JsonObject? NewContent { get; set; } + + public TimelineLegacyEventContent SetReplaceRelation(string eventId) { + NewContent = JsonSerializer.SerializeToNode(this, GetType())!.AsObject(); + // NewContent = JsonSerializer.Deserialize(jsonText, GetType()); + RelatesTo = new MessageRelatesTo { + RelationType = "m.replace", + EventId = eventId + }; + return this; + } + + public T SetReplaceRelation(string eventId) where T : TimelineLegacyEventContent => SetReplaceRelation(eventId) as T ?? throw new InvalidOperationException(); + + public class MessageRelatesTo { + [JsonPropertyName("m.in_reply_to")] + public EventInReplyTo? InReplyTo { get; set; } + + [JsonPropertyName("event_id")] + public string? EventId { get; set; } + + [JsonPropertyName("rel_type")] + public string? RelationType { get; set; } + + public class EventInReplyTo { + [JsonPropertyName("event_id")] + public string? EventId { get; set; } + + [JsonPropertyName("rel_type")] + public string? RelType { get; set; } + } + } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/LegacyMatrixEventAttribute.cs b/LibMatrix.LegacyEvents.EventTypes/LegacyMatrixEventAttribute.cs new file mode 100644 index 0000000..bfcc6f8 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/LegacyMatrixEventAttribute.cs @@ -0,0 +1,7 @@ +namespace LibMatrix.LegacyEvents.EventTypes; + +[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] +public class LegacyMatrixEventAttribute : Attribute { + public required string EventName { get; set; } + public bool Legacy { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/MatrixEventAttribute.cs b/LibMatrix.LegacyEvents.EventTypes/MatrixEventAttribute.cs deleted file mode 100644 index 708dad1..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/MatrixEventAttribute.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LibMatrix.LegacyEvents.EventTypes; - -[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] -public class MatrixEventAttribute : Attribute { - public required string EventName { get; set; } - public bool Legacy { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/PresenceLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/PresenceLegacyEventContent.cs new file mode 100644 index 0000000..136b69a --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/PresenceLegacyEventContent.cs @@ -0,0 +1,30 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.Ephemeral; + +[LegacyMatrixEvent(EventName = EventId)] +public class PresenceLegacyEventContent : LegacyEventContent { + public const string EventId = "m.presence"; + + [JsonPropertyName("presence")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Presence { get; set; } + + [JsonPropertyName("last_active_ago")] + public long LastActiveAgo { get; set; } + + [JsonPropertyName("currently_active")] + public bool CurrentlyActive { get; set; } + + [JsonPropertyName("status_msg")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? StatusMessage { get; set; } + + [JsonPropertyName("avatar_url")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? AvatarUrl { get; set; } + + [JsonPropertyName("displayname")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? DisplayName { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs deleted file mode 100644 index 676f36d..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.Ephemeral; - -[MatrixEvent(EventName = EventId)] -public class PresenceEventContent : EventContent { - public const string EventId = "m.presence"; - - [JsonPropertyName("presence")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? Presence { get; set; } - - [JsonPropertyName("last_active_ago")] - public long LastActiveAgo { get; set; } - - [JsonPropertyName("currently_active")] - public bool CurrentlyActive { get; set; } - - [JsonPropertyName("status_msg")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? StatusMessage { get; set; } - - [JsonPropertyName("avatar_url")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? AvatarUrl { get; set; } - - [JsonPropertyName("displayname")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? DisplayName { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs deleted file mode 100644 index 97b86fc..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class RoomTypingEventContent : EventContent { - public const string EventId = "m.typing"; - - [JsonPropertyName("user_ids")] - public string[]? UserIds { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/RoomTypingLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/RoomTypingLegacyEventContent.cs new file mode 100644 index 0000000..a44b6a5 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/RoomTypingLegacyEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomTypingLegacyEventContent : LegacyEventContent { + public const string EventId = "m.typing"; + + [JsonPropertyName("user_ids")] + public string[]? UserIds { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageEventContent.cs deleted file mode 100644 index ef26ab0..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageEventContent.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec; - -[MatrixEvent(EventName = EventId)] -public class RoomMessageEventContent : TimelineEventContent { - public const string EventId = "m.room.message"; - - public RoomMessageEventContent(string messageType = "m.notice", string? body = null) { - MessageType = messageType; - Body = body ?? ""; - } - - [JsonPropertyName("body")] - public string Body { get; set; } - - [JsonPropertyName("msgtype")] - public string MessageType { get; set; } = "m.notice"; - - [JsonPropertyName("formatted_body")] - public string? FormattedBody { get; set; } - - [JsonPropertyName("format")] - public string? Format { get; set; } - - /// - /// Media URI for this message, if any - /// - [JsonPropertyName("url")] - public string? Url { get; set; } - - public string? FileName { get; set; } - - [JsonPropertyName("info")] - public FileInfoStruct? FileInfo { get; set; } - - [JsonIgnore] - public string BodyWithoutReplyFallback => Body.Split('\n').SkipWhile(x => x.StartsWith(">")).SkipWhile(x=>x.Trim().Length == 0).Aggregate((x, y) => $"{x}\n{y}"); - - public class FileInfoStruct { - [JsonPropertyName("mimetype")] - public string? MimeType { get; set; } - - [JsonPropertyName("size")] - public long Size { get; set; } - - [JsonPropertyName("thumbnail_url")] - public string? ThumbnailUrl { get; set; } - - [JsonPropertyName("w")] - public int? Width { get; set; } - - [JsonPropertyName("h")] - public int? Height { get; set; } - } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageLegacyEventContent.cs new file mode 100644 index 0000000..a4de54e --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageLegacyEventContent.cs @@ -0,0 +1,56 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomMessageLegacyEventContent : TimelineLegacyEventContent { + public const string EventId = "m.room.message"; + + public RoomMessageLegacyEventContent(string messageType = "m.notice", string? body = null) { + MessageType = messageType; + Body = body ?? ""; + } + + [JsonPropertyName("body")] + public string Body { get; set; } + + [JsonPropertyName("msgtype")] + public string MessageType { get; set; } = "m.notice"; + + [JsonPropertyName("formatted_body")] + public string? FormattedBody { get; set; } + + [JsonPropertyName("format")] + public string? Format { get; set; } + + /// + /// Media URI for this message, if any + /// + [JsonPropertyName("url")] + public string? Url { get; set; } + + public string? FileName { get; set; } + + [JsonPropertyName("info")] + public FileInfoStruct? FileInfo { get; set; } + + [JsonIgnore] + public string BodyWithoutReplyFallback => Body.Split('\n').SkipWhile(x => x.StartsWith(">")).SkipWhile(x=>x.Trim().Length == 0).Aggregate((x, y) => $"{x}\n{y}"); + + public class FileInfoStruct { + [JsonPropertyName("mimetype")] + public string? MimeType { get; set; } + + [JsonPropertyName("size")] + public long Size { get; set; } + + [JsonPropertyName("thumbnail_url")] + public string? ThumbnailUrl { get; set; } + + [JsonPropertyName("w")] + public int? Width { get; set; } + + [JsonPropertyName("h")] + public int? Height { get; set; } + } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageReactionEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageReactionEventContent.cs deleted file mode 100644 index 3649a6b..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageReactionEventContent.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace LibMatrix.LegacyEvents.EventTypes.Spec; - -[MatrixEvent(EventName = EventId)] -public class RoomMessageReactionEventContent : TimelineEventContent { - public const string EventId = "m.reaction"; -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageReactionLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageReactionLegacyEventContent.cs new file mode 100644 index 0000000..185f2db --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageReactionLegacyEventContent.cs @@ -0,0 +1,6 @@ +namespace LibMatrix.LegacyEvents.EventTypes.Spec; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomMessageReactionLegacyEventContent : TimelineLegacyEventContent { + public const string EventId = "m.reaction"; +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs index c61f2bf..60b1dff 100644 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs @@ -4,32 +4,32 @@ using ArcaneLibs.Attributes; namespace LibMatrix.LegacyEvents.EventTypes.Spec.State.Policy; //spec -[MatrixEvent(EventName = EventId)] //spec -[MatrixEvent(EventName = "m.room.rule.server", Legacy = true)] //??? -[MatrixEvent(EventName = "org.matrix.mjolnir.rule.server", Legacy = true)] //legacy +[LegacyMatrixEvent(EventName = EventId)] //spec +[LegacyMatrixEvent(EventName = "m.room.rule.server", Legacy = true)] //??? +[LegacyMatrixEvent(EventName = "org.matrix.mjolnir.rule.server", Legacy = true)] //legacy [FriendlyName(Name = "Server policy", NamePlural = "Server policies")] -public class ServerPolicyRuleEventContent : PolicyRuleEventContent { +public class ServerPolicyRuleLegacyEventContent : PolicyRuleLegacyEventContent { public const string EventId = "m.policy.rule.server"; } -[MatrixEvent(EventName = EventId)] //spec -[MatrixEvent(EventName = "m.room.rule.user", Legacy = true)] //??? -[MatrixEvent(EventName = "org.matrix.mjolnir.rule.user", Legacy = true)] //legacy +[LegacyMatrixEvent(EventName = EventId)] //spec +[LegacyMatrixEvent(EventName = "m.room.rule.user", Legacy = true)] //??? +[LegacyMatrixEvent(EventName = "org.matrix.mjolnir.rule.user", Legacy = true)] //legacy [FriendlyName(Name = "User policy", NamePlural = "User policies")] -public class UserPolicyRuleEventContent : PolicyRuleEventContent { +public class UserPolicyRuleLegacyEventContent : PolicyRuleLegacyEventContent { public const string EventId = "m.policy.rule.user"; } -[MatrixEvent(EventName = EventId)] //spec -[MatrixEvent(EventName = "m.room.rule.room", Legacy = true)] //??? -[MatrixEvent(EventName = "org.matrix.mjolnir.rule.room", Legacy = true)] //legacy +[LegacyMatrixEvent(EventName = EventId)] //spec +[LegacyMatrixEvent(EventName = "m.room.rule.room", Legacy = true)] //??? +[LegacyMatrixEvent(EventName = "org.matrix.mjolnir.rule.room", Legacy = true)] //legacy [FriendlyName(Name = "Room policy", NamePlural = "Room policies")] -public class RoomPolicyRuleEventContent : PolicyRuleEventContent { +public class RoomPolicyRuleLegacyEventContent : PolicyRuleLegacyEventContent { public const string EventId = "m.policy.rule.room"; } -public abstract class PolicyRuleEventContent : EventContent { - public PolicyRuleEventContent() => Console.WriteLine($"init policy {GetType().Name}"); +public abstract class PolicyRuleLegacyEventContent : LegacyEventContent { + public PolicyRuleLegacyEventContent() => Console.WriteLine($"init policy {GetType().Name}"); private string? _reason; /// diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs deleted file mode 100644 index 197fe4b..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State.RoomInfo; - -[MatrixEvent(EventName = EventId)] -public class RoomAliasEventContent : EventContent { - public const string EventId = "m.room.alias"; - - [JsonPropertyName("aliases")] - public List? Aliases { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasLegacyEventContent.cs new file mode 100644 index 0000000..34ff49e --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasLegacyEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State.RoomInfo; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomAliasLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.alias"; + + [JsonPropertyName("aliases")] + public List? Aliases { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs deleted file mode 100644 index bc70d65..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State.RoomInfo; - -[MatrixEvent(EventName = EventId)] -public class RoomAvatarEventContent : EventContent { - public const string EventId = "m.room.avatar"; - - [JsonPropertyName("url")] - public string? Url { get; set; } - - [JsonPropertyName("info")] - public RoomAvatarInfo? Info { get; set; } - - public class RoomAvatarInfo { - [JsonPropertyName("h")] - public int? Height { get; set; } - - [JsonPropertyName("w")] - public int? Width { get; set; } - - [JsonPropertyName("mimetype")] - public string? MimeType { get; set; } - - [JsonPropertyName("size")] - public int? Size { get; set; } - } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAvatarLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAvatarLegacyEventContent.cs new file mode 100644 index 0000000..99d8b39 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAvatarLegacyEventContent.cs @@ -0,0 +1,28 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State.RoomInfo; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomAvatarLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.avatar"; + + [JsonPropertyName("url")] + public string? Url { get; set; } + + [JsonPropertyName("info")] + public RoomAvatarInfo? Info { get; set; } + + public class RoomAvatarInfo { + [JsonPropertyName("h")] + public int? Height { get; set; } + + [JsonPropertyName("w")] + public int? Width { get; set; } + + [JsonPropertyName("mimetype")] + public string? MimeType { get; set; } + + [JsonPropertyName("size")] + public int? Size { get; set; } + } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs deleted file mode 100644 index 790f80b..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class RoomCanonicalAliasEventContent : EventContent { - public const string EventId = "m.room.canonical_alias"; - - [JsonPropertyName("alias")] - public string? Alias { get; set; } - - [JsonPropertyName("alt_aliases")] - public string[]? AltAliases { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasLegacyEventContent.cs new file mode 100644 index 0000000..9d27079 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasLegacyEventContent.cs @@ -0,0 +1,14 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomCanonicalAliasLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.canonical_alias"; + + [JsonPropertyName("alias")] + public string? Alias { get; set; } + + [JsonPropertyName("alt_aliases")] + public string[]? AltAliases { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs deleted file mode 100644 index c6d259d..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class RoomCreateEventContent : EventContent { - public const string EventId = "m.room.create"; - - [JsonPropertyName("room_version")] - public string? RoomVersion { get; set; } - - [JsonPropertyName("creator")] - public string? Creator { get; set; } - - [JsonPropertyName("m.federate")] - public bool? Federate { get; set; } - - [JsonPropertyName("predecessor")] - public RoomCreatePredecessor? Predecessor { get; set; } - - [JsonPropertyName("type")] - public string? Type { get; set; } - - public class RoomCreatePredecessor { - [JsonPropertyName("room_id")] - public string? RoomId { get; set; } - - [JsonPropertyName("event_id")] - public string? EventId { get; set; } - } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCreateLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCreateLegacyEventContent.cs new file mode 100644 index 0000000..9f0a693 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCreateLegacyEventContent.cs @@ -0,0 +1,31 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomCreateLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.create"; + + [JsonPropertyName("room_version")] + public string? RoomVersion { get; set; } + + [JsonPropertyName("creator")] + public string? Creator { get; set; } + + [JsonPropertyName("m.federate")] + public bool? Federate { get; set; } + + [JsonPropertyName("predecessor")] + public RoomCreatePredecessor? Predecessor { get; set; } + + [JsonPropertyName("type")] + public string? Type { get; set; } + + public class RoomCreatePredecessor { + [JsonPropertyName("room_id")] + public string? RoomId { get; set; } + + [JsonPropertyName("event_id")] + public string? EventId { get; set; } + } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs deleted file mode 100644 index 2fed1f3..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class RoomEncryptionEventContent : EventContent { - public const string EventId = "m.room.encryption"; - - [JsonPropertyName("algorithm")] - public string? Algorithm { get; set; } - - [JsonPropertyName("rotation_period_ms")] - public ulong? RotationPeriodMs { get; set; } - - [JsonPropertyName("rotation_period_msgs")] - public ulong? RotationPeriodMsgs { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomEncryptionLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomEncryptionLegacyEventContent.cs new file mode 100644 index 0000000..34bd4fe --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomEncryptionLegacyEventContent.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomEncryptionLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.encryption"; + + [JsonPropertyName("algorithm")] + public string? Algorithm { get; set; } + + [JsonPropertyName("rotation_period_ms")] + public ulong? RotationPeriodMs { get; set; } + + [JsonPropertyName("rotation_period_msgs")] + public ulong? RotationPeriodMsgs { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs deleted file mode 100644 index be66dbf..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class RoomGuestAccessEventContent : EventContent { - public const string EventId = "m.room.guest_access"; - - [JsonPropertyName("guest_access")] - public string GuestAccess { get; set; } - - [JsonIgnore] - public bool IsGuestAccessEnabled { - get => GuestAccess == "can_join"; - set => GuestAccess = value ? "can_join" : "forbidden"; - } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomGuestAccessLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomGuestAccessLegacyEventContent.cs new file mode 100644 index 0000000..923b8ee --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomGuestAccessLegacyEventContent.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomGuestAccessLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.guest_access"; + + [JsonPropertyName("guest_access")] + public string GuestAccess { get; set; } + + [JsonIgnore] + public bool IsGuestAccessEnabled { + get => GuestAccess == "can_join"; + set => GuestAccess = value ? "can_join" : "forbidden"; + } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs deleted file mode 100644 index 0be42d6..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class RoomHistoryVisibilityEventContent : EventContent { - public const string EventId = "m.room.history_visibility"; - - [JsonPropertyName("history_visibility")] - public string HistoryVisibility { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityLegacyEventContent.cs new file mode 100644 index 0000000..ab11dfc --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityLegacyEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomHistoryVisibilityLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.history_visibility"; + + [JsonPropertyName("history_visibility")] + public string HistoryVisibility { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs deleted file mode 100644 index 48202a5..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class RoomJoinRulesEventContent : EventContent { - public const string EventId = "m.room.join_rules"; - - /// - /// one of ["public", "invite", "knock", "restricted", "knock_restricted"] - /// "private" is reserved without implementation! - /// unknown values are treated as "private" - /// - [JsonPropertyName("join_rule")] - public string JoinRuleValue { get; set; } - - [JsonIgnore] - public JoinRules JoinRule { - get => JoinRuleValue switch { - "public" => JoinRules.Public, - "invite" => JoinRules.Invite, - "knock" => JoinRules.Knock, - "restricted" => JoinRules.Restricted, - "knock_restricted" => JoinRules.KnockRestricted, - _ => JoinRules.Private - }; - set => JoinRuleValue = value switch { - JoinRules.Public => "public", - JoinRules.Invite => "invite", - JoinRules.Knock => "knock", - JoinRules.Restricted => "restricted", - JoinRules.KnockRestricted => "knock_restricted", - _ => "private" - }; - } - - [JsonPropertyName("allow")] - public List? Allow { get; set; } - - public class AllowEntry { - [JsonPropertyName("type")] - public required string Type { get; set; } - - [JsonPropertyName("room_id")] - public required string RoomId { get; set; } - - public static class Types { - public const string RoomMembership = "m.room_membership"; - } - } - - public enum JoinRules { - Public, - Invite, - Knock, - Restricted, - KnockRestricted, - Private // reserved without implementation! - } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomJoinRulesLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomJoinRulesLegacyEventContent.cs new file mode 100644 index 0000000..4330697 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomJoinRulesLegacyEventContent.cs @@ -0,0 +1,60 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomJoinRulesLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.join_rules"; + + /// + /// one of ["public", "invite", "knock", "restricted", "knock_restricted"] + /// "private" is reserved without implementation! + /// unknown values are treated as "private" + /// + [JsonPropertyName("join_rule")] + public string JoinRuleValue { get; set; } + + [JsonIgnore] + public JoinRules JoinRule { + get => JoinRuleValue switch { + "public" => JoinRules.Public, + "invite" => JoinRules.Invite, + "knock" => JoinRules.Knock, + "restricted" => JoinRules.Restricted, + "knock_restricted" => JoinRules.KnockRestricted, + _ => JoinRules.Private + }; + set => JoinRuleValue = value switch { + JoinRules.Public => "public", + JoinRules.Invite => "invite", + JoinRules.Knock => "knock", + JoinRules.Restricted => "restricted", + JoinRules.KnockRestricted => "knock_restricted", + _ => "private" + }; + } + + [JsonPropertyName("allow")] + public List? Allow { get; set; } + + public class AllowEntry { + [JsonPropertyName("type")] + public required string Type { get; set; } + + [JsonPropertyName("room_id")] + public required string RoomId { get; set; } + + public static class Types { + public const string RoomMembership = "m.room_membership"; + } + } + + public enum JoinRules { + Public, + Invite, + Knock, + Restricted, + KnockRestricted, + Private // reserved without implementation! + } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs deleted file mode 100644 index 1926417..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class RoomMemberEventContent : EventContent { - public const string EventId = "m.room.member"; - - [JsonPropertyName("reason")] - public string? Reason { get; set; } - - [JsonPropertyName("membership")] - public required string Membership { get; set; } - - [JsonPropertyName("displayname")] - public string? DisplayName { get; set; } - - [JsonPropertyName("is_direct")] - public bool? IsDirect { get; set; } - - [JsonPropertyName("avatar_url")] - public string? AvatarUrl { get; set; } - - [JsonPropertyName("kind")] - public string? Kind { get; set; } - - [JsonPropertyName("join_authorised_via_users_server")] - public string? JoinAuthorisedViaUsersServer { get; set; } - - public static class MembershipTypes { - public const string Invite = "invite"; - public const string Join = "join"; - public const string Leave = "leave"; - public const string Ban = "ban"; - public const string Knock = "knock"; - } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomMemberLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomMemberLegacyEventContent.cs new file mode 100644 index 0000000..d716425 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomMemberLegacyEventContent.cs @@ -0,0 +1,37 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomMemberLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.member"; + + [JsonPropertyName("reason")] + public string? Reason { get; set; } + + [JsonPropertyName("membership")] + public required string Membership { get; set; } + + [JsonPropertyName("displayname")] + public string? DisplayName { get; set; } + + [JsonPropertyName("is_direct")] + public bool? IsDirect { get; set; } + + [JsonPropertyName("avatar_url")] + public string? AvatarUrl { get; set; } + + [JsonPropertyName("kind")] + public string? Kind { get; set; } + + [JsonPropertyName("join_authorised_via_users_server")] + public string? JoinAuthorisedViaUsersServer { get; set; } + + public static class MembershipTypes { + public const string Invite = "invite"; + public const string Join = "join"; + public const string Leave = "leave"; + public const string Ban = "ban"; + public const string Knock = "knock"; + } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs deleted file mode 100644 index 165a1a3..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[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.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomNameLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomNameLegacyEventContent.cs new file mode 100644 index 0000000..29646fe --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomNameLegacyEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomNameLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.name"; + + [JsonPropertyName("name")] + public string? Name { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs deleted file mode 100644 index 4c08396..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class RoomPinnedEventContent : EventContent { - public const string EventId = "m.room.pinned_events"; - - [JsonPropertyName("pinned")] - public string[]? PinnedEvents { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPinnedLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPinnedLegacyEventContent.cs new file mode 100644 index 0000000..bbef3de --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPinnedLegacyEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomPinnedLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.pinned_events"; + + [JsonPropertyName("pinned")] + public string[]? PinnedEvents { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs deleted file mode 100644 index e7b58ee..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] -public class RoomPowerLevelEventContent : EventContent { - public const string EventId = "m.room.power_levels"; - - [JsonPropertyName("ban")] - public long? Ban { get; set; } = 50; - - [JsonPropertyName("events_default")] - public long? EventsDefault { get; set; } = 0; - - [JsonPropertyName("invite")] - public long? Invite { get; set; } = 0; - - [JsonPropertyName("kick")] - public long? Kick { get; set; } = 50; - - [JsonPropertyName("notifications")] - public NotificationsPL? NotificationsPl { get; set; } // = null!; - - [JsonPropertyName("redact")] - public long? Redact { get; set; } = 50; - - [JsonPropertyName("state_default")] - public long? StateDefault { get; set; } = 50; - - [JsonPropertyName("events")] - public Dictionary? Events { get; set; } // = null!; - - [JsonPropertyName("users")] - public Dictionary? Users { get; set; } // = null!; - - [JsonPropertyName("users_default")] - public long? UsersDefault { get; set; } = 0; - - [Obsolete("Historical was a key related to MSC2716, a spec change on backfill that was dropped!", true)] - [JsonIgnore] - [JsonPropertyName("historical")] - public long Historical { get; set; } // = 50; - - public class NotificationsPL { - [JsonPropertyName("room")] - public long Room { get; set; } = 50; - } - - public bool IsUserAdmin(string userId) { - ArgumentNullException.ThrowIfNull(userId); - return Users.TryGetValue(userId, out var level) && level >= Events.Max(x => x.Value); - } - - public bool UserHasTimelinePermission(string userId, string eventType) { - ArgumentNullException.ThrowIfNull(userId); - return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, EventsDefault ?? 0); - } - - public bool UserHasStatePermission(string userId, string eventType) { - ArgumentNullException.ThrowIfNull(userId); - var userLevel = GetUserPowerLevel(userId); - var eventLevel = GetStateEventPowerLevel(eventType); - - Console.WriteLine($"{userId}={userLevel} >= {eventType}={eventLevel} = {userLevel >= eventLevel}"); - - return userLevel >= eventLevel; - } - - public long GetUserPowerLevel(string userId) { - ArgumentNullException.ThrowIfNull(userId); - if (Users is null) return UsersDefault ?? 0; - return Users.TryGetValue(userId, out var level) ? level : UsersDefault ?? 0; - } - - public long GetStateEventPowerLevel(string eventType) { - ArgumentNullException.ThrowIfNull(eventType); - if (Events is null) return StateDefault ?? 0; - return Events.TryGetValue(eventType, out var level) ? level : StateDefault ?? 0; - } - - public long GetTimelineEventPowerLevel(string eventType) { - ArgumentNullException.ThrowIfNull(eventType); - if (Events is null) return EventsDefault ?? 0; - return Events.TryGetValue(eventType, out var level) ? level : EventsDefault ?? 0; - } - - public void SetUserPowerLevel(string userId, long powerLevel) { - ArgumentNullException.ThrowIfNull(userId); - Users ??= new Dictionary(); - Users[userId] = powerLevel; - } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPowerLevelLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPowerLevelLegacyEventContent.cs new file mode 100644 index 0000000..cf41b6d --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPowerLevelLegacyEventContent.cs @@ -0,0 +1,93 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] +public class RoomPowerLevelLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.power_levels"; + + [JsonPropertyName("ban")] + public long? Ban { get; set; } = 50; + + [JsonPropertyName("events_default")] + public long? EventsDefault { get; set; } = 0; + + [JsonPropertyName("invite")] + public long? Invite { get; set; } = 0; + + [JsonPropertyName("kick")] + public long? Kick { get; set; } = 50; + + [JsonPropertyName("notifications")] + public NotificationsPL? NotificationsPl { get; set; } // = null!; + + [JsonPropertyName("redact")] + public long? Redact { get; set; } = 50; + + [JsonPropertyName("state_default")] + public long? StateDefault { get; set; } = 50; + + [JsonPropertyName("events")] + public Dictionary? Events { get; set; } // = null!; + + [JsonPropertyName("users")] + public Dictionary? Users { get; set; } // = null!; + + [JsonPropertyName("users_default")] + public long? UsersDefault { get; set; } = 0; + + [Obsolete("Historical was a key related to MSC2716, a spec change on backfill that was dropped!", true)] + [JsonIgnore] + [JsonPropertyName("historical")] + public long Historical { get; set; } // = 50; + + public class NotificationsPL { + [JsonPropertyName("room")] + public long Room { get; set; } = 50; + } + + public bool IsUserAdmin(string userId) { + ArgumentNullException.ThrowIfNull(userId); + return Users.TryGetValue(userId, out var level) && level >= Events.Max(x => x.Value); + } + + public bool UserHasTimelinePermission(string userId, string eventType) { + ArgumentNullException.ThrowIfNull(userId); + return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, EventsDefault ?? 0); + } + + public bool UserHasStatePermission(string userId, string eventType) { + ArgumentNullException.ThrowIfNull(userId); + var userLevel = GetUserPowerLevel(userId); + var eventLevel = GetStateEventPowerLevel(eventType); + + Console.WriteLine($"{userId}={userLevel} >= {eventType}={eventLevel} = {userLevel >= eventLevel}"); + + return userLevel >= eventLevel; + } + + public long GetUserPowerLevel(string userId) { + ArgumentNullException.ThrowIfNull(userId); + if (Users is null) return UsersDefault ?? 0; + return Users.TryGetValue(userId, out var level) ? level : UsersDefault ?? 0; + } + + public long GetStateEventPowerLevel(string eventType) { + ArgumentNullException.ThrowIfNull(eventType); + if (Events is null) return StateDefault ?? 0; + return Events.TryGetValue(eventType, out var level) ? level : StateDefault ?? 0; + } + + public long GetTimelineEventPowerLevel(string eventType) { + ArgumentNullException.ThrowIfNull(eventType); + if (Events is null) return EventsDefault ?? 0; + return Events.TryGetValue(eventType, out var level) ? level : EventsDefault ?? 0; + } + + public void SetUserPowerLevel(string userId, long powerLevel) { + ArgumentNullException.ThrowIfNull(userId); + Users ??= new Dictionary(); + Users[userId] = powerLevel; + } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs deleted file mode 100644 index 506203f..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class RoomServerACLEventContent : EventContent { - public const string EventId = "m.room.server_acl"; - - [JsonPropertyName("allow")] - public List? Allow { get; set; } // = null!; - - [JsonPropertyName("deny")] - public List? Deny { get; set; } // = null!; - - [JsonPropertyName("allow_ip_literals")] - public bool AllowIpLiterals { get; set; } // = false; -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomServerAclLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomServerAclLegacyEventContent.cs new file mode 100644 index 0000000..d9cedd4 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomServerAclLegacyEventContent.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class RoomServerAclLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.server_acl"; + + [JsonPropertyName("allow")] + public List? Allow { get; set; } // = null!; + + [JsonPropertyName("deny")] + public List? Deny { get; set; } // = null!; + + [JsonPropertyName("allow_ip_literals")] + public bool AllowIpLiterals { get; set; } // = false; +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs deleted file mode 100644 index d9e1ba9..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -[MatrixEvent(EventName = "org.matrix.msc3765.topic", Legacy = true)] -public class RoomTopicEventContent : EventContent { - public const string EventId = "m.room.topic"; - - [JsonPropertyName("topic")] - public string? Topic { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomTopicLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomTopicLegacyEventContent.cs new file mode 100644 index 0000000..fbd5124 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomTopicLegacyEventContent.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +[LegacyMatrixEvent(EventName = "org.matrix.msc3765.topic", Legacy = true)] +public class RoomTopicLegacyEventContent : LegacyEventContent { + public const string EventId = "m.room.topic"; + + [JsonPropertyName("topic")] + public string? Topic { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceChildEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceChildEventContent.cs deleted file mode 100644 index bd8ff64..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceChildEventContent.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class SpaceChildEventContent : EventContent { - public const string EventId = "m.space.child"; - - [JsonPropertyName("auto_join")] - public bool? AutoJoin { get; set; } - - [JsonPropertyName("via")] - public List? Via { get; set; } - - [JsonPropertyName("suggested")] - public bool? Suggested { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceChildLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceChildLegacyEventContent.cs new file mode 100644 index 0000000..75440e5 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceChildLegacyEventContent.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class SpaceChildLegacyEventContent : LegacyEventContent { + public const string EventId = "m.space.child"; + + [JsonPropertyName("auto_join")] + public bool? AutoJoin { get; set; } + + [JsonPropertyName("via")] + public List? Via { get; set; } + + [JsonPropertyName("suggested")] + public bool? Suggested { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceParentEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceParentEventContent.cs deleted file mode 100644 index 4e9903f..0000000 --- a/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceParentEventContent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; - -[MatrixEvent(EventName = EventId)] -public class SpaceParentEventContent : EventContent { - public const string EventId = "m.space.parent"; - - [JsonPropertyName("via")] - public string[]? Via { get; set; } - - [JsonPropertyName("canonical")] - public bool? Canonical { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceParentLegacyEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceParentLegacyEventContent.cs new file mode 100644 index 0000000..f58143a --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceParentLegacyEventContent.cs @@ -0,0 +1,14 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.LegacyEvents.EventTypes.Spec.State; + +[LegacyMatrixEvent(EventName = EventId)] +public class SpaceParentLegacyEventContent : LegacyEventContent { + public const string EventId = "m.space.parent"; + + [JsonPropertyName("via")] + public string[]? Via { get; set; } + + [JsonPropertyName("canonical")] + public bool? Canonical { get; set; } +} \ No newline at end of file diff --git a/LibMatrix/Helpers/MessageBuilder.cs b/LibMatrix/Helpers/MessageBuilder.cs index 54de7ad..0ed0339 100644 --- a/LibMatrix/Helpers/MessageBuilder.cs +++ b/LibMatrix/Helpers/MessageBuilder.cs @@ -3,12 +3,12 @@ using LibMatrix.LegacyEvents.EventTypes.Spec; namespace LibMatrix.Helpers; public class MessageBuilder(string msgType = "m.text", string format = "org.matrix.custom.html") { - private RoomMessageEventContent Content { get; set; } = new() { + private RoomMessageLegacyEventContent Content { get; set; } = new() { MessageType = msgType, Format = format }; - public RoomMessageEventContent Build() => Content; + public RoomMessageLegacyEventContent Build() => Content; public MessageBuilder WithBody(string body) { Content.Body += body; diff --git a/LibMatrix/Helpers/MessageFormatter.cs b/LibMatrix/Helpers/MessageFormatter.cs index f234d8f..2c5021e 100644 --- a/LibMatrix/Helpers/MessageFormatter.cs +++ b/LibMatrix/Helpers/MessageFormatter.cs @@ -4,25 +4,25 @@ using LibMatrix.LegacyEvents.EventTypes.Spec; namespace LibMatrix.Helpers; public static class MessageFormatter { - public static RoomMessageEventContent FormatError(string error) => + public static RoomMessageLegacyEventContent FormatError(string error) => new(body: error, messageType: "m.text") { FormattedBody = $"{error}", Format = "org.matrix.custom.html" }; - public static RoomMessageEventContent FormatException(string error, Exception e) => + public static RoomMessageLegacyEventContent FormatException(string error, Exception e) => new(body: $"{error}: {e.Message}", messageType: "m.text") { FormattedBody = $"{error}:
{e.Message}
", Format = "org.matrix.custom.html" }; - public static RoomMessageEventContent FormatSuccess(string text) => + public static RoomMessageLegacyEventContent FormatSuccess(string text) => new(body: text, messageType: "m.text") { FormattedBody = $"{text}", Format = "org.matrix.custom.html" }; - public static RoomMessageEventContent FormatSuccessJson(string text, object data) => + public static RoomMessageLegacyEventContent FormatSuccessJson(string text, object data) => new(body: text, messageType: "m.text") { FormattedBody = $"{text}:
{data.ToJson(ignoreNull: true)}
", Format = "org.matrix.custom.html" @@ -37,29 +37,29 @@ public static class MessageFormatter { #region Extension functions - public static RoomMessageEventContent ToMatrixMessage(this Exception e, string error) => FormatException(error, e); + public static RoomMessageLegacyEventContent ToMatrixMessage(this Exception e, string error) => FormatException(error, e); #endregion - public static RoomMessageEventContent FormatWarning(string warning) => + public static RoomMessageLegacyEventContent FormatWarning(string warning) => new(body: warning, messageType: "m.text") { FormattedBody = $"{warning}", Format = "org.matrix.custom.html" }; - public static RoomMessageEventContent FormatWarningJson(string warning, object data) => + public static RoomMessageLegacyEventContent FormatWarningJson(string warning, object data) => new(body: warning, messageType: "m.text") { FormattedBody = $"{warning}:
{data.ToJson(ignoreNull: true)}
", Format = "org.matrix.custom.html" }; - public static RoomMessageEventContent Concat(this RoomMessageEventContent a, RoomMessageEventContent b) => + public static RoomMessageLegacyEventContent Concat(this RoomMessageLegacyEventContent a, RoomMessageLegacyEventContent b) => new(body: $"{a.Body}{b.Body}", messageType: a.MessageType) { FormattedBody = $"{a.FormattedBody}{b.FormattedBody}", Format = a.Format }; - public static RoomMessageEventContent ConcatLine(this RoomMessageEventContent a, RoomMessageEventContent b) => + public static RoomMessageLegacyEventContent ConcatLine(this RoomMessageLegacyEventContent a, RoomMessageLegacyEventContent b) => new(body: $"{a.Body}\n{b.Body}", messageType: "m.text") { FormattedBody = $"{a.FormattedBody}
{b.FormattedBody}", Format = "org.matrix.custom.html" diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs index 86977ec..db76985 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs @@ -190,7 +190,7 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { if (newProfile is null) return; Console.WriteLine($"Updating profile for {WhoAmI.UserId} to {newProfile.ToJson(ignoreNull: true)} (preserving room profiles: {preserveCustomRoomProfile})"); var oldProfile = await GetProfileAsync(WhoAmI.UserId!); - Dictionary expectedRoomProfiles = new(); + Dictionary expectedRoomProfiles = new(); var syncHelper = new SyncHelper(this) { Filter = new SyncFilter { AccountData = new SyncFilter.EventFilter() { @@ -209,7 +209,7 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { targetSyncCount = rooms.Count; await foreach (var (roomId, currentRoomProfile) in roomProfiles) try { - // var currentRoomProfile = await room.GetStateAsync("m.room.member", WhoAmI.UserId!); + // var currentRoomProfile = await room.GetStateAsync("m.room.member", WhoAmI.UserId!); //build new profiles if (currentRoomProfile.DisplayName == oldProfile.DisplayName) currentRoomProfile.DisplayName = newProfile.DisplayName; @@ -243,7 +243,7 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { foreach (var (roomId, roomData) in sync.Rooms.Join) if (roomData.State is { Events.Count: > 0 }) { var incommingRoomProfile = - roomData.State?.Events?.FirstOrDefault(x => x.Type == "m.room.member" && x.StateKey == WhoAmI.UserId)?.TypedContent as RoomMemberEventContent; + roomData.State?.Events?.FirstOrDefault(x => x.Type == "m.room.member" && x.StateKey == WhoAmI.UserId)?.TypedContent as RoomMemberLegacyEventContent; if (incommingRoomProfile is null) continue; if (!expectedRoomProfiles.ContainsKey(roomId)) continue; var targetRoomProfileOverride = expectedRoomProfiles[roomId]; @@ -276,7 +276,7 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { } } - public async IAsyncEnumerable> GetRoomProfilesAsync() { + public async IAsyncEnumerable> GetRoomProfilesAsync() { var rooms = await GetJoinedRooms(); var results = rooms.Select(GetOwnRoomProfileWithIdAsync).ToAsyncEnumerable(); await foreach (var res in results) yield return res; @@ -295,8 +295,8 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { #region Room Profile Utility - private async Task> GetOwnRoomProfileWithIdAsync(GenericRoom room) => - new(room.RoomId, await room.GetStateAsync("m.room.member", WhoAmI.UserId!)); + private async Task> GetOwnRoomProfileWithIdAsync(GenericRoom room) => + new(room.RoomId, await room.GetStateAsync("m.room.member", WhoAmI.UserId!)); #endregion diff --git a/LibMatrix/LegacyMatrixEvent.cs b/LibMatrix/LegacyMatrixEvent.cs index 1c1ebf3..5433da3 100644 --- a/LibMatrix/LegacyMatrixEvent.cs +++ b/LibMatrix/LegacyMatrixEvent.cs @@ -13,12 +13,12 @@ using LibMatrix.Extensions; namespace LibMatrix; public class LegacyMatrixEvent { - public static FrozenSet KnownStateEventTypes { get; } = new ClassCollector().ResolveFromAllAccessibleAssemblies().ToFrozenSet(); + public static FrozenSet KnownStateEventTypes { get; } = new ClassCollector().ResolveFromAllAccessibleAssemblies().ToFrozenSet(); public static FrozenDictionary KnownStateEventTypesByName { get; } = KnownStateEventTypes.Aggregate( new Dictionary(), (dict, type) => { - var attrs = type.GetCustomAttributes(); + var attrs = type.GetCustomAttributes(); foreach (var attr in attrs) { if (dict.TryGetValue(attr.EventName, out var existing)) Console.WriteLine($"Duplicate event type '{attr.EventName}' registered for types '{existing.Name}' and '{type.Name}'"); @@ -29,13 +29,13 @@ public class LegacyMatrixEvent { }).OrderBy(x => x.Key).ToFrozenDictionary(); public static Type GetStateEventType(string? type) => - string.IsNullOrWhiteSpace(type) ? typeof(UnknownEventContent) : KnownStateEventTypesByName.GetValueOrDefault(type) ?? typeof(UnknownEventContent); + string.IsNullOrWhiteSpace(type) ? typeof(UnknownLegacyEventContent) : KnownStateEventTypesByName.GetValueOrDefault(type) ?? typeof(UnknownLegacyEventContent); [JsonIgnore] public Type MappedType => GetStateEventType(Type); [JsonIgnore] - public bool IsLegacyType => MappedType.GetCustomAttributes().FirstOrDefault(x => x.EventName == Type)?.Legacy ?? false; + public bool IsLegacyType => MappedType.GetCustomAttributes().FirstOrDefault(x => x.EventName == Type)?.Legacy ?? false; [JsonIgnore] public string FriendlyTypeName => MappedType.GetFriendlyNameOrNull() ?? Type; @@ -53,16 +53,16 @@ public class LegacyMatrixEvent { [JsonIgnore] [SuppressMessage("ReSharper", "PropertyCanBeMadeInitOnly.Global")] - public EventContent? TypedContent { + public LegacyEventContent? TypedContent { get { // if (Type == "m.receipt") { // return null; // } try { var mappedType = GetStateEventType(Type); - if (mappedType == typeof(UnknownEventContent)) + if (mappedType == typeof(UnknownLegacyEventContent)) Console.WriteLine($"Warning: unknown event type '{Type}'"); - var deserialisedContent = (EventContent)RawContent.Deserialize(mappedType, TypedContentSerializerOptions)!; + var deserialisedContent = (LegacyEventContent)RawContent.Deserialize(mappedType, TypedContentSerializerOptions)!; return deserialisedContent; } catch (JsonException e) { diff --git a/LibMatrix/Responses/CreateRoomRequest.cs b/LibMatrix/Responses/CreateRoomRequest.cs index 6919b84..cae2a04 100644 --- a/LibMatrix/Responses/CreateRoomRequest.cs +++ b/LibMatrix/Responses/CreateRoomRequest.cs @@ -38,7 +38,7 @@ public class CreateRoomRequest { public string? Visibility { get; set; } [JsonPropertyName("power_level_content_override")] - public RoomPowerLevelEventContent? PowerLevelContentOverride { get; set; } = null!; + public RoomPowerLevelLegacyEventContent? PowerLevelContentOverride { get; set; } = null!; [JsonPropertyName("creation_content")] public JsonObject CreationContent { get; set; } = new(); @@ -57,10 +57,10 @@ public class CreateRoomRequest { InitialState.Add(stateEvent = new LegacyMatrixEvent { Type = eventType, StateKey = eventKey, - TypedContent = (EventContent)Activator.CreateInstance( + TypedContent = (LegacyEventContent)Activator.CreateInstance( LegacyMatrixEvent.KnownStateEventTypes.FirstOrDefault(x => - x.GetCustomAttributes()? - .Any(y => y.EventName == eventType) ?? false) ?? typeof(UnknownEventContent) + x.GetCustomAttributes()? + .Any(y => y.EventName == eventType) ?? false) ?? typeof(UnknownLegacyEventContent) )! }); @@ -89,7 +89,7 @@ public class CreateRoomRequest { Name = name ?? "New public Room", Visibility = "public", CreationContent = new JsonObject(), - PowerLevelContentOverride = new RoomPowerLevelEventContent { + PowerLevelContentOverride = new RoomPowerLevelLegacyEventContent { EventsDefault = 0, UsersDefault = 0, Kick = 50, @@ -97,7 +97,7 @@ public class CreateRoomRequest { Invite = 25, StateDefault = 10, Redact = 50, - NotificationsPl = new RoomPowerLevelEventContent.NotificationsPL { + NotificationsPl = new RoomPowerLevelLegacyEventContent.NotificationsPL { Room = 10 }, Events = new Dictionary { @@ -129,7 +129,7 @@ public class CreateRoomRequest { Name = name ?? "New private Room", Visibility = "private", CreationContent = new JsonObject(), - PowerLevelContentOverride = new RoomPowerLevelEventContent { + PowerLevelContentOverride = new RoomPowerLevelLegacyEventContent { EventsDefault = 0, UsersDefault = 0, Kick = 50, @@ -137,7 +137,7 @@ public class CreateRoomRequest { Invite = 25, StateDefault = 10, Redact = 50, - NotificationsPl = new RoomPowerLevelEventContent.NotificationsPL { + NotificationsPl = new RoomPowerLevelLegacyEventContent.NotificationsPL { Room = 10 }, Events = new Dictionary { diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs index 3ef2395..8fa46d3 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs @@ -205,7 +205,7 @@ public class GenericRoom { Console.WriteLine("End of GetManyAsync"); } - public async Task GetNameAsync() => (await GetStateOrNullAsync("m.room.name"))?.Name; + public async Task GetNameAsync() => (await GetStateOrNullAsync("m.room.name"))?.Name; public async Task JoinAsync(string[]? homeservers = null, string? reason = null, bool checkIfAlreadyMember = true) { if (checkIfAlreadyMember) @@ -279,42 +279,42 @@ public class GenericRoom { #region Utility shortcuts - public Task SendMessageEventAsync(RoomMessageEventContent content) => + public Task SendMessageEventAsync(RoomMessageLegacyEventContent content) => SendTimelineEventAsync("m.room.message", content); public async Task?> GetAliasesAsync() { - var res = await GetStateAsync("m.room.aliases"); + var res = await GetStateAsync("m.room.aliases"); return res.Aliases; } - public Task GetCanonicalAliasAsync() => - GetStateAsync("m.room.canonical_alias"); + public Task GetCanonicalAliasAsync() => + GetStateAsync("m.room.canonical_alias"); - public Task GetTopicAsync() => - GetStateAsync("m.room.topic"); + public Task GetTopicAsync() => + GetStateAsync("m.room.topic"); - public Task GetAvatarUrlAsync() => - GetStateAsync("m.room.avatar"); + public Task GetAvatarUrlAsync() => + GetStateAsync("m.room.avatar"); - public Task GetJoinRuleAsync() => - GetStateAsync("m.room.join_rules"); + public Task GetJoinRuleAsync() => + GetStateAsync("m.room.join_rules"); - public Task GetHistoryVisibilityAsync() => - GetStateAsync("m.room.history_visibility"); + public Task GetHistoryVisibilityAsync() => + GetStateAsync("m.room.history_visibility"); - public Task GetGuestAccessAsync() => - GetStateAsync("m.room.guest_access"); + public Task GetGuestAccessAsync() => + GetStateAsync("m.room.guest_access"); - public Task GetCreateEventAsync() => - GetStateAsync("m.room.create"); + public Task GetCreateEventAsync() => + GetStateAsync("m.room.create"); public async Task GetRoomType() { - var res = await GetStateAsync("m.room.create"); + var res = await GetStateAsync("m.room.create"); return res.Type; } - public Task GetPowerLevelsAsync() => - GetStateAsync("m.room.power_levels"); + public Task GetPowerLevelsAsync() => + GetStateAsync("m.room.power_levels"); public async Task GetNameOrFallbackAsync(int maxMemberNames = 2) { try { @@ -393,7 +393,7 @@ public class GenericRoom { new UserIdAndReason { UserId = userId }); public async Task InviteUserAsync(string userId, string? reason = null, bool skipExisting = true) { - if (skipExisting && await GetStateAsync("m.room.member", userId) is not null) + if (skipExisting && await GetStateAsync("m.room.member", userId) is not null) return; await Homeserver.ClientHttpClient.PostAsJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/invite", new UserIdAndReason(userId, reason)); } @@ -410,7 +410,7 @@ public class GenericRoom { await (await Homeserver.ClientHttpClient.PutAsJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/state/{eventType}/{stateKey}", content)) .Content.ReadFromJsonAsync(); - public async Task SendTimelineEventAsync(string eventType, TimelineEventContent content) { + public async Task SendTimelineEventAsync(string eventType, TimelineLegacyEventContent content) { var res = await Homeserver.ClientHttpClient.PutAsJsonAsync( $"/_matrix/client/v3/rooms/{RoomId}/send/{eventType}/" + Guid.NewGuid(), content, new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull @@ -420,12 +420,12 @@ public class GenericRoom { public async Task SendFileAsync(string fileName, Stream fileStream, string messageType = "m.file", string contentType = "application/octet-stream") { var url = await Homeserver.UploadFile(fileName, fileStream); - var content = new RoomMessageEventContent() { + var content = new RoomMessageLegacyEventContent() { MessageType = messageType, Url = url, Body = fileName, FileName = fileName, - FileInfo = new RoomMessageEventContent.FileInfoStruct { + FileInfo = new RoomMessageLegacyEventContent.FileInfoStruct { Size = fileStream.Length, MimeType = contentType } diff --git a/LibMatrix/Utilities/CommonSyncFilters.cs b/LibMatrix/Utilities/CommonSyncFilters.cs index 401850c..d07c225 100644 --- a/LibMatrix/Utilities/CommonSyncFilters.cs +++ b/LibMatrix/Utilities/CommonSyncFilters.cs @@ -37,11 +37,11 @@ public static class CommonSyncFilters { Ephemeral = new SyncFilter.RoomFilter.StateFilter(rooms: []), State = new SyncFilter.RoomFilter.StateFilter { Types = new List { - RoomCreateEventContent.EventId, - RoomNameEventContent.EventId, - RoomAvatarEventContent.EventId, - MjolnirShortcodeEventContent.EventId, - RoomPowerLevelEventContent.EventId + RoomCreateLegacyEventContent.EventId, + RoomNameLegacyEventContent.EventId, + RoomAvatarLegacyEventContent.EventId, + MjolnirShortcodeLegacyEventContent.EventId, + RoomPowerLevelLegacyEventContent.EventId }, LazyLoadMembers = true, IncludeRedundantMembers = false }, @@ -57,8 +57,8 @@ public static class CommonSyncFilters { Ephemeral = new SyncFilter.RoomFilter.StateFilter(rooms: []), State = new SyncFilter.RoomFilter.StateFilter { Types = new List { - SpaceChildEventContent.EventId, - SpaceParentEventContent.EventId + SpaceChildLegacyEventContent.EventId, + SpaceParentLegacyEventContent.EventId }, LazyLoadMembers = true, IncludeRedundantMembers = false }, @@ -74,7 +74,7 @@ public static class CommonSyncFilters { Ephemeral = new SyncFilter.RoomFilter.StateFilter(rooms: []), State = new SyncFilter.RoomFilter.StateFilter { Types = new List { - RoomMemberEventContent.EventId + RoomMemberLegacyEventContent.EventId }, LazyLoadMembers = true, IncludeRedundantMembers = false, Senders = ["@me"] diff --git a/Tests/TestDataGenerator/Bot/DataFetcher.cs b/Tests/TestDataGenerator/Bot/DataFetcher.cs index 1367e1c..f80d10a 100644 --- a/Tests/TestDataGenerator/Bot/DataFetcher.cs +++ b/Tests/TestDataGenerator/Bot/DataFetcher.cs @@ -26,19 +26,19 @@ public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger Directory.GetFiles("bot_data/cache").ToList().ForEach(File.Delete); _logRoom = hs.GetRoom(botConfiguration.LogRoom!); - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Test data collector started!")); - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Fetching rooms...")); + await _logRoom.SendMessageEventAsync(new RoomMessageLegacyEventContent(body: "Test data collector started!")); + await _logRoom.SendMessageEventAsync(new RoomMessageLegacyEventContent(body: "Fetching rooms...")); var rooms = await hs.GetJoinedRooms(); - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: $"Fetched {rooms.Count} rooms!")); + await _logRoom.SendMessageEventAsync(new RoomMessageLegacyEventContent(body: $"Fetched {rooms.Count} rooms!")); - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Fetching room data...")); + await _logRoom.SendMessageEventAsync(new RoomMessageLegacyEventContent(body: "Fetching room data...")); var roomAliasTasks = rooms.Select(room => room.GetCanonicalAliasAsync()).ToAsyncEnumerable(); List> aliasResolutionTasks = new(); await foreach (var @event in roomAliasTasks) if (@event?.Alias != null) { - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: $"Fetched room alias {@event.Alias}!")); + await _logRoom.SendMessageEventAsync(new RoomMessageLegacyEventContent(body: $"Fetched room alias {@event.Alias}!")); aliasResolutionTasks.Add(Task.Run(async () => { var alias = await hs.ResolveRoomAliasAsync(@event.Alias); return (@event.Alias, alias.RoomId); @@ -47,7 +47,7 @@ public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger var aliasResolutionTaskEnumerator = aliasResolutionTasks.ToAsyncEnumerable(); await foreach (var result in aliasResolutionTaskEnumerator) - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: $"Resolved room alias {result.Item1} to {result.Item2}!")); + await _logRoom.SendMessageEventAsync(new RoomMessageLegacyEventContent(body: $"Resolved room alias {result.Item1} to {result.Item2}!")); } /// Triggered when the application host is performing a graceful shutdown. diff --git a/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs b/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs index 6348085..95af553 100644 --- a/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs +++ b/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs @@ -7,7 +7,7 @@ using LibMatrix.LegacyEvents.EventTypes; // var asm = Assembly.LoadFrom(binary); File.Delete("EventSerializerContexts.g.cs"); var stream = File.OpenWrite("EventSerializerContexts.g.cs"); -var eventContentTypes = new ClassCollector().ResolveFromAllAccessibleAssemblies(); +var eventContentTypes = new ClassCollector().ResolveFromAllAccessibleAssemblies(); stream.WriteString("using System.Text.Json.Serialization;\n"); diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs index 68fc884..aaa61ed 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs @@ -19,7 +19,7 @@ public class AliassesCommand(IServiceProvider services) : ICommand { var commands = services.GetServices().Where(x => !x.Unlisted).ToList(); foreach (var command in commands) sb.AppendLine($"- {command.Name}: {command.Description}"); - await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent("m.notice", sb.ToString())); + await ctx.Room.SendMessageEventAsync(new RoomMessageLegacyEventContent("m.notice", sb.ToString())); var msb = new MessageBuilder("m.notice"); msb.WithHtmlTag("table", tb => { diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs index 04d5124..15a1ea1 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs @@ -9,5 +9,5 @@ public class PingCommand : ICommand { public string Description { get; } = "Pong!"; public bool Unlisted { get; } - public async Task Invoke(CommandContext ctx) => await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: "pong!")); + public async Task Invoke(CommandContext ctx) => await ctx.Room.SendMessageEventAsync(new RoomMessageLegacyEventContent(body: "pong!")); } \ No newline at end of file diff --git a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs index c171dfe..1b69c89 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs @@ -9,7 +9,7 @@ public class CommandContext { public required LegacyMatrixEventResponse MessageEvent { get; set; } public string MessageContentWithoutReply => - (MessageEvent.TypedContent as RoomMessageEventContent)! + (MessageEvent.TypedContent as RoomMessageLegacyEventContent)! .Body.Split('\n') .SkipWhile(x => x.StartsWith(">")) .Aggregate((x, y) => $"{x}\n{y}"); @@ -18,7 +18,7 @@ public class CommandContext { public required string[] Args; public required AuthenticatedHomeserverGeneric Homeserver { get; set; } - public async Task Reply(RoomMessageEventContent content) => await Room.SendMessageEventAsync(content); + public async Task Reply(RoomMessageLegacyEventContent content) => await Room.SendMessageEventAsync(content); } public class CommandResult { diff --git a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs index feb174b..46638e4 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs @@ -61,7 +61,7 @@ public class CommandListenerHostedService : IHostedService { try { var room = _hs.GetRoom(@event.RoomId); // _logger.LogInformation(eventResponse.ToJson(indent: false)); - if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventContent message }) + if (@event is { Type: "m.room.message", TypedContent: RoomMessageLegacyEventContent message }) if (message is { MessageType: "m.text" }) { var usedPrefix = await GetUsedPrefix(@event); if (usedPrefix is null) return; @@ -89,12 +89,12 @@ public class CommandListenerHostedService : IHostedService { } private async Task GetUsedPrefix(LegacyMatrixEventResponse evt) { - var messageContent = evt.TypedContent as RoomMessageEventContent; + var messageContent = evt.TypedContent as RoomMessageLegacyEventContent; var message = messageContent!.BodyWithoutReplyFallback; var prefix = _config.Prefixes.OrderByDescending(x => x.Length).FirstOrDefault(message.StartsWith); if (prefix is null && _config.MentionPrefix) { var profile = await _hs.GetProfileAsync(_hs.WhoAmI.UserId); - var roomProfile = await _hs.GetRoom(evt.RoomId!).GetStateAsync(RoomMemberEventContent.EventId, _hs.WhoAmI.UserId); + var roomProfile = await _hs.GetRoom(evt.RoomId!).GetStateAsync(RoomMemberLegacyEventContent.EventId, _hs.WhoAmI.UserId); if (message.StartsWith(_hs.WhoAmI.UserId + ": ")) prefix = profile.DisplayName + ": "; // `@bot:server.xyz: ` else if (message.StartsWith(_hs.WhoAmI.UserId + " ")) prefix = profile.DisplayName + " "; // `@bot:server.xyz ` else if (!string.IsNullOrWhiteSpace(roomProfile?.DisplayName) && message.StartsWith(roomProfile.DisplayName + ": ")) @@ -109,7 +109,7 @@ public class CommandListenerHostedService : IHostedService { } private async Task InvokeCommand(LegacyMatrixEventResponse evt, string usedPrefix) { - var message = evt.TypedContent as RoomMessageEventContent; + var message = evt.TypedContent as RoomMessageLegacyEventContent; var room = _hs.GetRoom(evt.RoomId!); var commandWithoutPrefix = message.BodyWithoutReplyFallback[usedPrefix.Length..].Trim(); @@ -124,7 +124,7 @@ public class CommandListenerHostedService : IHostedService { var command = _commands.SingleOrDefault(x => x.Name == commandWithoutPrefix.Split(' ')[0] || x.Aliases?.Contains(commandWithoutPrefix.Split(' ')[0]) == true); if (command == null) { await room.SendMessageEventAsync( - new RoomMessageEventContent("m.notice", $"Command \"{ctx.CommandName}\" not found!")); + new RoomMessageLegacyEventContent("m.notice", $"Command \"{ctx.CommandName}\" not found!")); return new() { Success = false, Result = CommandResult.CommandResultType.Failure_InvalidCommand, @@ -153,7 +153,7 @@ public class CommandListenerHostedService : IHostedService { Success = false }; // await room.SendMessageEventAsync( - // new RoomMessageEventContent("m.notice", "You do not have permission to run this command!")); + // new RoomMessageLegacyEventContent("m.notice", "You do not have permission to run this command!")); return new CommandResult() { Context = ctx, @@ -176,8 +176,8 @@ public class CommandListenerHostedService : IHostedService { var room = res.Context.Room; var msg = res.Result switch { CommandResult.CommandResultType.Failure_Exception => MessageFormatter.FormatException("An error occurred during the execution of this command", res.Exception!), - CommandResult.CommandResultType.Failure_NoPermission => new RoomMessageEventContent("m.notice", "You do not have permission to run this command!"), - CommandResult.CommandResultType.Failure_InvalidCommand => new RoomMessageEventContent("m.notice", $"Command \"{res.Context.CommandName}\" not found!"), + CommandResult.CommandResultType.Failure_NoPermission => new RoomMessageLegacyEventContent("m.notice", "You do not have permission to run this command!"), + CommandResult.CommandResultType.Failure_InvalidCommand => new RoomMessageLegacyEventContent("m.notice", $"Command \"{res.Context.CommandName}\" not found!"), _ => throw new ArgumentOutOfRangeException() }; -- cgit 1.4.1