From e5591eef3850a9796cc87386128651a828b70697 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Fri, 6 Oct 2023 18:29:15 +0200 Subject: Small refactors --- .../Common/MjolnirShortcodeEventContent.cs | 11 +++++ .../EventTypes/Common/MjolnirShortcodeEventData.cs | 11 ----- .../EventTypes/Common/RoomEmotesEventContent.cs | 26 ++++++++++ LibMatrix/EventTypes/Common/RoomEmotesEventData.cs | 26 ---------- LibMatrix/EventTypes/MatrixEventAttribute.cs | 7 +++ .../Spec/Ephemeral/PresenceStateEventContent.cs | 21 ++++++++ .../Spec/Ephemeral/RoomTypingEventContent.cs | 11 +++++ .../EventTypes/Spec/RoomMessageEventContent.cs | 33 +++++++++++++ LibMatrix/EventTypes/Spec/RoomMessageEventData.cs | 33 ------------- .../Spec/State/CanonicalAliasEventContent.cs | 13 ----- .../EventTypes/Spec/State/GuestAccessEventData.cs | 16 ------- .../Spec/State/HistoryVisibilityEventData.cs | 11 ----- .../EventTypes/Spec/State/JoinRulesEventData.cs | 30 ------------ .../State/Policy/PolicyRuleStateEventContent.cs | 56 ++++++++++++++++++++++ .../Spec/State/PolicyRuleStateEventData.cs | 56 ---------------------- .../Spec/State/PresenceStateEventData.cs | 21 -------- .../Spec/State/ProfileResponseEventContent.cs | 12 +++++ .../Spec/State/ProfileResponseEventData.cs | 12 ----- .../EventTypes/Spec/State/RoomAliasEventData.cs | 11 ----- .../EventTypes/Spec/State/RoomAvatarEventData.cs | 28 ----------- .../EventTypes/Spec/State/RoomCreateEventData.cs | 31 ------------ .../Spec/State/RoomEncryptionEventData.cs | 15 ------ .../Spec/State/RoomInfo/RoomAliasEventContent.cs | 11 +++++ .../Spec/State/RoomInfo/RoomAvatarEventContent.cs | 28 +++++++++++ .../RoomInfo/RoomCanonicalAliasEventContent.cs | 13 +++++ .../Spec/State/RoomInfo/RoomCreateEventContent.cs | 31 ++++++++++++ .../State/RoomInfo/RoomEncryptionEventContent.cs | 15 ++++++ .../State/RoomInfo/RoomGuestAccessEventContent.cs | 16 +++++++ .../RoomInfo/RoomHistoryVisibilityEventContent.cs | 11 +++++ .../State/RoomInfo/RoomJoinRulesEventContent.cs | 30 ++++++++++++ .../Spec/State/RoomInfo/RoomMemberEventContent.cs | 29 +++++++++++ .../Spec/State/RoomInfo/RoomNameEventContent.cs | 11 +++++ .../Spec/State/RoomInfo/RoomPinnedEventContent.cs | 11 +++++ .../State/RoomInfo/RoomPowerLevelEventContent.cs | 56 ++++++++++++++++++++++ .../State/RoomInfo/RoomServerACLEventContent.cs | 17 +++++++ .../Spec/State/RoomInfo/RoomTopicEventContent.cs | 12 +++++ .../EventTypes/Spec/State/RoomMemberEventData.cs | 29 ----------- .../EventTypes/Spec/State/RoomNameEventData.cs | 11 ----- .../EventTypes/Spec/State/RoomPinnedEventData.cs | 11 ----- .../Spec/State/RoomPowerLevelEventData.cs | 56 ---------------------- .../EventTypes/Spec/State/RoomTopicEventData.cs | 12 ----- .../EventTypes/Spec/State/RoomTypingEventData.cs | 11 ----- .../EventTypes/Spec/State/ServerACLEventData.cs | 17 ------- .../Spec/State/Space/SpaceChildEventContent.cs | 15 ++++++ .../Spec/State/Space/SpaceParentEventContent.cs | 14 ++++++ .../EventTypes/Spec/State/SpaceChildEventData.cs | 15 ------ .../EventTypes/Spec/State/SpaceParentEventData.cs | 14 ------ LibMatrix/EventTypes/UnknownStateEventContent.cs | 7 +++ LibMatrix/EventTypes/UnknownStateEventData.cs | 7 --- 49 files changed, 504 insertions(+), 497 deletions(-) create mode 100644 LibMatrix/EventTypes/Common/MjolnirShortcodeEventContent.cs delete mode 100644 LibMatrix/EventTypes/Common/MjolnirShortcodeEventData.cs create mode 100644 LibMatrix/EventTypes/Common/RoomEmotesEventContent.cs delete mode 100644 LibMatrix/EventTypes/Common/RoomEmotesEventData.cs create mode 100644 LibMatrix/EventTypes/MatrixEventAttribute.cs create mode 100644 LibMatrix/EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/RoomMessageEventContent.cs delete mode 100644 LibMatrix/EventTypes/Spec/RoomMessageEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/CanonicalAliasEventContent.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/GuestAccessEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/HistoryVisibilityEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/JoinRulesEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/PolicyRuleStateEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/PresenceStateEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/ProfileResponseEventContent.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/ProfileResponseEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/RoomAliasEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/RoomAvatarEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/RoomCreateEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/RoomEncryptionEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/RoomMemberEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/RoomNameEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/RoomPinnedEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/RoomPowerLevelEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/RoomTopicEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/RoomTypingEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/ServerACLEventData.cs create mode 100644 LibMatrix/EventTypes/Spec/State/Space/SpaceChildEventContent.cs create mode 100644 LibMatrix/EventTypes/Spec/State/Space/SpaceParentEventContent.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/SpaceChildEventData.cs delete mode 100644 LibMatrix/EventTypes/Spec/State/SpaceParentEventData.cs create mode 100644 LibMatrix/EventTypes/UnknownStateEventContent.cs delete mode 100644 LibMatrix/EventTypes/UnknownStateEventData.cs (limited to 'LibMatrix/EventTypes') diff --git a/LibMatrix/EventTypes/Common/MjolnirShortcodeEventContent.cs b/LibMatrix/EventTypes/Common/MjolnirShortcodeEventContent.cs new file mode 100644 index 0000000..9067351 --- /dev/null +++ b/LibMatrix/EventTypes/Common/MjolnirShortcodeEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Common; + +[MatrixEvent(EventName = "org.matrix.mjolnir.shortcode")] +public class MjolnirShortcodeEventContent : EventContent { + [JsonPropertyName("shortcode")] + public string? Shortcode { get; set; } +} diff --git a/LibMatrix/EventTypes/Common/MjolnirShortcodeEventData.cs b/LibMatrix/EventTypes/Common/MjolnirShortcodeEventData.cs deleted file mode 100644 index 9067351..0000000 --- a/LibMatrix/EventTypes/Common/MjolnirShortcodeEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Common; - -[MatrixEvent(EventName = "org.matrix.mjolnir.shortcode")] -public class MjolnirShortcodeEventContent : EventContent { - [JsonPropertyName("shortcode")] - public string? Shortcode { get; set; } -} diff --git a/LibMatrix/EventTypes/Common/RoomEmotesEventContent.cs b/LibMatrix/EventTypes/Common/RoomEmotesEventContent.cs new file mode 100644 index 0000000..abf936c --- /dev/null +++ b/LibMatrix/EventTypes/Common/RoomEmotesEventContent.cs @@ -0,0 +1,26 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Common; + +[MatrixEvent(EventName = "im.ponies.room_emotes")] +public class RoomEmotesEventContent : EventContent { + [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 { + + } +} diff --git a/LibMatrix/EventTypes/Common/RoomEmotesEventData.cs b/LibMatrix/EventTypes/Common/RoomEmotesEventData.cs deleted file mode 100644 index abf936c..0000000 --- a/LibMatrix/EventTypes/Common/RoomEmotesEventData.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Common; - -[MatrixEvent(EventName = "im.ponies.room_emotes")] -public class RoomEmotesEventContent : EventContent { - [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 { - - } -} diff --git a/LibMatrix/EventTypes/MatrixEventAttribute.cs b/LibMatrix/EventTypes/MatrixEventAttribute.cs new file mode 100644 index 0000000..92334d0 --- /dev/null +++ b/LibMatrix/EventTypes/MatrixEventAttribute.cs @@ -0,0 +1,7 @@ +namespace LibMatrix.EventTypes; + +[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] +public class MatrixEventAttribute : Attribute { + public string EventName { get; set; } + public bool Legacy { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs b/LibMatrix/EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs new file mode 100644 index 0000000..b12da5b --- /dev/null +++ b/LibMatrix/EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs @@ -0,0 +1,21 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.presence")] +public class PresenceEventContent : EventContent { + [JsonPropertyName("presence")] + 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")] + public string StatusMessage { get; set; } + [JsonPropertyName("avatar_url")] + public string AvatarUrl { get; set; } + [JsonPropertyName("displayname")] + public string DisplayName { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs b/LibMatrix/EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs new file mode 100644 index 0000000..01cfacf --- /dev/null +++ b/LibMatrix/EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.typing")] +public class RoomTypingEventContent : EventContent { + [JsonPropertyName("user_ids")] + public string[]? UserIds { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/RoomMessageEventContent.cs b/LibMatrix/EventTypes/Spec/RoomMessageEventContent.cs new file mode 100644 index 0000000..f8ee58b --- /dev/null +++ b/LibMatrix/EventTypes/Spec/RoomMessageEventContent.cs @@ -0,0 +1,33 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec; + +[MatrixEvent(EventName = "m.room.message")] +public class RoomMessageEventContent : EventContent { + 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; } +} diff --git a/LibMatrix/EventTypes/Spec/RoomMessageEventData.cs b/LibMatrix/EventTypes/Spec/RoomMessageEventData.cs deleted file mode 100644 index f8ee58b..0000000 --- a/LibMatrix/EventTypes/Spec/RoomMessageEventData.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec; - -[MatrixEvent(EventName = "m.room.message")] -public class RoomMessageEventContent : EventContent { - 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; } -} diff --git a/LibMatrix/EventTypes/Spec/State/CanonicalAliasEventContent.cs b/LibMatrix/EventTypes/Spec/State/CanonicalAliasEventContent.cs deleted file mode 100644 index 71f3d0d..0000000 --- a/LibMatrix/EventTypes/Spec/State/CanonicalAliasEventContent.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.canonical_alias")] -public class CanonicalAliasEventContent : EventContent { - [JsonPropertyName("alias")] - public string? Alias { get; set; } - [JsonPropertyName("alt_aliases")] - public string[]? AltAliases { get; set; } -} diff --git a/LibMatrix/EventTypes/Spec/State/GuestAccessEventData.cs b/LibMatrix/EventTypes/Spec/State/GuestAccessEventData.cs deleted file mode 100644 index af1b2ce..0000000 --- a/LibMatrix/EventTypes/Spec/State/GuestAccessEventData.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.guest_access")] -public class GuestAccessEventContent : EventContent { - [JsonPropertyName("guest_access")] - public string GuestAccess { get; set; } - - public bool IsGuestAccessEnabled { - get => GuestAccess == "can_join"; - set => GuestAccess = value ? "can_join" : "forbidden"; - } -} diff --git a/LibMatrix/EventTypes/Spec/State/HistoryVisibilityEventData.cs b/LibMatrix/EventTypes/Spec/State/HistoryVisibilityEventData.cs deleted file mode 100644 index b57ade5..0000000 --- a/LibMatrix/EventTypes/Spec/State/HistoryVisibilityEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.history_visibility")] -public class HistoryVisibilityEventContent : EventContent { - [JsonPropertyName("history_visibility")] - public string HistoryVisibility { get; set; } -} diff --git a/LibMatrix/EventTypes/Spec/State/JoinRulesEventData.cs b/LibMatrix/EventTypes/Spec/State/JoinRulesEventData.cs deleted file mode 100644 index 0098bef..0000000 --- a/LibMatrix/EventTypes/Spec/State/JoinRulesEventData.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.join_rules")] -public class JoinRulesEventContent : EventContent { - private static string Public = "public"; - private static string Invite = "invite"; - private static string Knock = "knock"; - - /// - /// one of ["public", "invite", "knock", "restricted", "knock_restricted"] - /// "private" is reserved without implementation! - /// - [JsonPropertyName("join_rule")] - public string JoinRule { get; set; } - - [JsonPropertyName("allow")] - public List Allow { get; set; } - - public class AllowEntry { - [JsonPropertyName("type")] - public string Type { get; set; } - - [JsonPropertyName("room_id")] - public string RoomId { get; set; } - } -} diff --git a/LibMatrix/EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs b/LibMatrix/EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs new file mode 100644 index 0000000..fde02c1 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs @@ -0,0 +1,56 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.policy.rule.user")] +[MatrixEvent(EventName = "m.policy.rule.server")] +[MatrixEvent(EventName = "org.matrix.mjolnir.rule.server")] +public class PolicyRuleEventContent : EventContent { + /// + /// Entity this ban applies to, can use * and ? as globs. + /// + [JsonPropertyName("entity")] + public string Entity { get; set; } + + /// + /// Reason this user is banned + /// + [JsonPropertyName("reason")] + public string? Reason { get; set; } + + /// + /// Suggested action to take + /// + [JsonPropertyName("recommendation")] + public string? Recommendation { get; set; } + + /// + /// Expiry time in milliseconds since the unix epoch, or null if the ban has no expiry. + /// + [JsonPropertyName("support.feline.policy.expiry.rev.2")] //stable prefix: expiry, msc pending + public long? Expiry { get; set; } + + //utils + /// + /// Readable expiry time, provided for easy interaction + /// + [JsonPropertyName("gay.rory.matrix_room_utils.readable_expiry_time_utc")] + public DateTime? ExpiryDateTime { + get => Expiry == null ? null : DateTimeOffset.FromUnixTimeMilliseconds(Expiry.Value).DateTime; + set => Expiry = ((DateTimeOffset)value).ToUnixTimeMilliseconds(); + } +} + +public static class PolicyRecommendationTypes { + /// + /// Ban this user + /// + public static string Ban = "m.ban"; + + /// + /// Mute this user + /// + public static string Mute = "support.feline.policy.recommendation_mute"; //stable prefix: m.mute, msc pending +} diff --git a/LibMatrix/EventTypes/Spec/State/PolicyRuleStateEventData.cs b/LibMatrix/EventTypes/Spec/State/PolicyRuleStateEventData.cs deleted file mode 100644 index fde02c1..0000000 --- a/LibMatrix/EventTypes/Spec/State/PolicyRuleStateEventData.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.policy.rule.user")] -[MatrixEvent(EventName = "m.policy.rule.server")] -[MatrixEvent(EventName = "org.matrix.mjolnir.rule.server")] -public class PolicyRuleEventContent : EventContent { - /// - /// Entity this ban applies to, can use * and ? as globs. - /// - [JsonPropertyName("entity")] - public string Entity { get; set; } - - /// - /// Reason this user is banned - /// - [JsonPropertyName("reason")] - public string? Reason { get; set; } - - /// - /// Suggested action to take - /// - [JsonPropertyName("recommendation")] - public string? Recommendation { get; set; } - - /// - /// Expiry time in milliseconds since the unix epoch, or null if the ban has no expiry. - /// - [JsonPropertyName("support.feline.policy.expiry.rev.2")] //stable prefix: expiry, msc pending - public long? Expiry { get; set; } - - //utils - /// - /// Readable expiry time, provided for easy interaction - /// - [JsonPropertyName("gay.rory.matrix_room_utils.readable_expiry_time_utc")] - public DateTime? ExpiryDateTime { - get => Expiry == null ? null : DateTimeOffset.FromUnixTimeMilliseconds(Expiry.Value).DateTime; - set => Expiry = ((DateTimeOffset)value).ToUnixTimeMilliseconds(); - } -} - -public static class PolicyRecommendationTypes { - /// - /// Ban this user - /// - public static string Ban = "m.ban"; - - /// - /// Mute this user - /// - public static string Mute = "support.feline.policy.recommendation_mute"; //stable prefix: m.mute, msc pending -} diff --git a/LibMatrix/EventTypes/Spec/State/PresenceStateEventData.cs b/LibMatrix/EventTypes/Spec/State/PresenceStateEventData.cs deleted file mode 100644 index b12da5b..0000000 --- a/LibMatrix/EventTypes/Spec/State/PresenceStateEventData.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.presence")] -public class PresenceEventContent : EventContent { - [JsonPropertyName("presence")] - 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")] - public string StatusMessage { get; set; } - [JsonPropertyName("avatar_url")] - public string AvatarUrl { get; set; } - [JsonPropertyName("displayname")] - public string DisplayName { get; set; } -} diff --git a/LibMatrix/EventTypes/Spec/State/ProfileResponseEventContent.cs b/LibMatrix/EventTypes/Spec/State/ProfileResponseEventContent.cs new file mode 100644 index 0000000..893fce1 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/ProfileResponseEventContent.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +public class ProfileResponseEventContent : EventContent { + [JsonPropertyName("avatar_url")] + public string? AvatarUrl { get; set; } + + [JsonPropertyName("displayname")] + public string? DisplayName { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/ProfileResponseEventData.cs b/LibMatrix/EventTypes/Spec/State/ProfileResponseEventData.cs deleted file mode 100644 index 893fce1..0000000 --- a/LibMatrix/EventTypes/Spec/State/ProfileResponseEventData.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -public class ProfileResponseEventContent : EventContent { - [JsonPropertyName("avatar_url")] - public string? AvatarUrl { get; set; } - - [JsonPropertyName("displayname")] - public string? DisplayName { get; set; } -} diff --git a/LibMatrix/EventTypes/Spec/State/RoomAliasEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomAliasEventData.cs deleted file mode 100644 index 5b0e914..0000000 --- a/LibMatrix/EventTypes/Spec/State/RoomAliasEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.alias")] -public class RoomAliasEventContent : EventContent { - [JsonPropertyName("aliases")] - public List? Aliases { get; set; } -} diff --git a/LibMatrix/EventTypes/Spec/State/RoomAvatarEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomAvatarEventData.cs deleted file mode 100644 index 601d014..0000000 --- a/LibMatrix/EventTypes/Spec/State/RoomAvatarEventData.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.avatar")] -public class RoomAvatarEventContent : EventContent { - [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; } - } -} diff --git a/LibMatrix/EventTypes/Spec/State/RoomCreateEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomCreateEventData.cs deleted file mode 100644 index c5bf14e..0000000 --- a/LibMatrix/EventTypes/Spec/State/RoomCreateEventData.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.create")] -public class RoomCreateEventContent : EventContent { - [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; } - } -} diff --git a/LibMatrix/EventTypes/Spec/State/RoomEncryptionEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomEncryptionEventData.cs deleted file mode 100644 index 6ffa4c5..0000000 --- a/LibMatrix/EventTypes/Spec/State/RoomEncryptionEventData.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.encryption")] -public class RoomEncryptionEventContent : EventContent { - [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; } -} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs new file mode 100644 index 0000000..5b0e914 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.alias")] +public class RoomAliasEventContent : EventContent { + [JsonPropertyName("aliases")] + public List? Aliases { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs new file mode 100644 index 0000000..601d014 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs @@ -0,0 +1,28 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.avatar")] +public class RoomAvatarEventContent : EventContent { + [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; } + } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs new file mode 100644 index 0000000..046222e --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs @@ -0,0 +1,13 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.canonical_alias")] +public class RoomCanonicalAliasEventContent : EventContent { + [JsonPropertyName("alias")] + public string? Alias { get; set; } + [JsonPropertyName("alt_aliases")] + public string[]? AltAliases { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs new file mode 100644 index 0000000..c5bf14e --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs @@ -0,0 +1,31 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.create")] +public class RoomCreateEventContent : EventContent { + [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; } + } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs new file mode 100644 index 0000000..6ffa4c5 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.encryption")] +public class RoomEncryptionEventContent : EventContent { + [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; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs new file mode 100644 index 0000000..2bb4d36 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.guest_access")] +public class RoomGuestAccessEventContent : EventContent { + [JsonPropertyName("guest_access")] + public string GuestAccess { get; set; } + + public bool IsGuestAccessEnabled { + get => GuestAccess == "can_join"; + set => GuestAccess = value ? "can_join" : "forbidden"; + } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs new file mode 100644 index 0000000..a32fed2 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.history_visibility")] +public class RoomHistoryVisibilityEventContent : EventContent { + [JsonPropertyName("history_visibility")] + public string HistoryVisibility { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs new file mode 100644 index 0000000..2c2a91b --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs @@ -0,0 +1,30 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.join_rules")] +public class RoomJoinRulesEventContent : EventContent { + private static string Public = "public"; + private static string Invite = "invite"; + private static string Knock = "knock"; + + /// + /// one of ["public", "invite", "knock", "restricted", "knock_restricted"] + /// "private" is reserved without implementation! + /// + [JsonPropertyName("join_rule")] + public string JoinRule { get; set; } + + [JsonPropertyName("allow")] + public List Allow { get; set; } + + public class AllowEntry { + [JsonPropertyName("type")] + public string Type { get; set; } + + [JsonPropertyName("room_id")] + public string RoomId { get; set; } + } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs new file mode 100644 index 0000000..52cb293 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs @@ -0,0 +1,29 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.member")] +public class RoomMemberEventContent : EventContent { + [JsonPropertyName("reason")] + public string? Reason { get; set; } + + [JsonPropertyName("membership")] + public string Membership { get; set; } = null!; + + [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; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs new file mode 100644 index 0000000..7cb881a --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.name")] +public class RoomNameEventContent : EventContent { + [JsonPropertyName("name")] + public string? Name { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs new file mode 100644 index 0000000..eb02cc7 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.pinned_events")] +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 new file mode 100644 index 0000000..2ae9593 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs @@ -0,0 +1,56 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.power_levels")] +public class RoomPowerLevelEventContent : EventContent { + [JsonPropertyName("ban")] + public long? Ban { get; set; } = 50; + + [JsonPropertyName("events_default")] + public long EventsDefault { get; set; } = 0; + + [JsonPropertyName("events")] + public Dictionary? Events { get; set; } // = null!; + + [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("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) { + return Users.TryGetValue(userId, out var level) && level >= Events.Max(x => x.Value); + } + + public bool UserHasPermission(string userId, string eventType) { + return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, EventsDefault); + } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs new file mode 100644 index 0000000..5c5627c --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.server_acl")] +public class RoomServerACLEventContent : EventContent { + [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; +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs new file mode 100644 index 0000000..52c7e42 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.room.topic")] +[MatrixEvent(EventName = "org.matrix.msc3765.topic", Legacy = true)] +public class RoomTopicEventContent : EventContent { + [JsonPropertyName("topic")] + public string? Topic { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/RoomMemberEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomMemberEventData.cs deleted file mode 100644 index da158f1..0000000 --- a/LibMatrix/EventTypes/Spec/State/RoomMemberEventData.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.member")] -public class RoomMemberEventContent : EventContent { - [JsonPropertyName("reason")] - public string? Reason { get; set; } - - [JsonPropertyName("membership")] - public string Membership { get; set; } = null!; - - [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; } -} diff --git a/LibMatrix/EventTypes/Spec/State/RoomNameEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomNameEventData.cs deleted file mode 100644 index 7cb881a..0000000 --- a/LibMatrix/EventTypes/Spec/State/RoomNameEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.name")] -public class RoomNameEventContent : EventContent { - [JsonPropertyName("name")] - public string? Name { get; set; } -} diff --git a/LibMatrix/EventTypes/Spec/State/RoomPinnedEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomPinnedEventData.cs deleted file mode 100644 index eb02cc7..0000000 --- a/LibMatrix/EventTypes/Spec/State/RoomPinnedEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.pinned_events")] -public class RoomPinnedEventContent : EventContent { - [JsonPropertyName("pinned")] - public string[]? PinnedEvents { get; set; } -} diff --git a/LibMatrix/EventTypes/Spec/State/RoomPowerLevelEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomPowerLevelEventData.cs deleted file mode 100644 index 2ae9593..0000000 --- a/LibMatrix/EventTypes/Spec/State/RoomPowerLevelEventData.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.power_levels")] -public class RoomPowerLevelEventContent : EventContent { - [JsonPropertyName("ban")] - public long? Ban { get; set; } = 50; - - [JsonPropertyName("events_default")] - public long EventsDefault { get; set; } = 0; - - [JsonPropertyName("events")] - public Dictionary? Events { get; set; } // = null!; - - [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("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) { - return Users.TryGetValue(userId, out var level) && level >= Events.Max(x => x.Value); - } - - public bool UserHasPermission(string userId, string eventType) { - return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, EventsDefault); - } -} diff --git a/LibMatrix/EventTypes/Spec/State/RoomTopicEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomTopicEventData.cs deleted file mode 100644 index 52c7e42..0000000 --- a/LibMatrix/EventTypes/Spec/State/RoomTopicEventData.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.topic")] -[MatrixEvent(EventName = "org.matrix.msc3765.topic", Legacy = true)] -public class RoomTopicEventContent : EventContent { - [JsonPropertyName("topic")] - public string? Topic { get; set; } -} diff --git a/LibMatrix/EventTypes/Spec/State/RoomTypingEventData.cs b/LibMatrix/EventTypes/Spec/State/RoomTypingEventData.cs deleted file mode 100644 index 01cfacf..0000000 --- a/LibMatrix/EventTypes/Spec/State/RoomTypingEventData.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.typing")] -public class RoomTypingEventContent : EventContent { - [JsonPropertyName("user_ids")] - public string[]? UserIds { get; set; } -} diff --git a/LibMatrix/EventTypes/Spec/State/ServerACLEventData.cs b/LibMatrix/EventTypes/Spec/State/ServerACLEventData.cs deleted file mode 100644 index f18fe43..0000000 --- a/LibMatrix/EventTypes/Spec/State/ServerACLEventData.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.room.server_acl")] -public class ServerACLEventContent : EventContent { - [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; -} diff --git a/LibMatrix/EventTypes/Spec/State/Space/SpaceChildEventContent.cs b/LibMatrix/EventTypes/Spec/State/Space/SpaceChildEventContent.cs new file mode 100644 index 0000000..0a897dc --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/Space/SpaceChildEventContent.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.space.child")] +public class SpaceChildEventContent : EventContent { + [JsonPropertyName("auto_join")] + public bool? AutoJoin { get; set; } + [JsonPropertyName("via")] + public List? Via { get; set; } + [JsonPropertyName("suggested")] + public bool? Suggested { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/Space/SpaceParentEventContent.cs b/LibMatrix/EventTypes/Spec/State/Space/SpaceParentEventContent.cs new file mode 100644 index 0000000..0ffa193 --- /dev/null +++ b/LibMatrix/EventTypes/Spec/State/Space/SpaceParentEventContent.cs @@ -0,0 +1,14 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes.Spec.State; + +[MatrixEvent(EventName = "m.space.parent")] +public class SpaceParentEventContent : EventContent { + [JsonPropertyName("via")] + public string[]? Via { get; set; } + + [JsonPropertyName("canonical")] + public bool? Canonical { get; set; } +} diff --git a/LibMatrix/EventTypes/Spec/State/SpaceChildEventData.cs b/LibMatrix/EventTypes/Spec/State/SpaceChildEventData.cs deleted file mode 100644 index 0a897dc..0000000 --- a/LibMatrix/EventTypes/Spec/State/SpaceChildEventData.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.space.child")] -public class SpaceChildEventContent : EventContent { - [JsonPropertyName("auto_join")] - public bool? AutoJoin { get; set; } - [JsonPropertyName("via")] - public List? Via { get; set; } - [JsonPropertyName("suggested")] - public bool? Suggested { get; set; } -} diff --git a/LibMatrix/EventTypes/Spec/State/SpaceParentEventData.cs b/LibMatrix/EventTypes/Spec/State/SpaceParentEventData.cs deleted file mode 100644 index 0ffa193..0000000 --- a/LibMatrix/EventTypes/Spec/State/SpaceParentEventData.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.Helpers; -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes.Spec.State; - -[MatrixEvent(EventName = "m.space.parent")] -public class SpaceParentEventContent : EventContent { - [JsonPropertyName("via")] - public string[]? Via { get; set; } - - [JsonPropertyName("canonical")] - public bool? Canonical { get; set; } -} diff --git a/LibMatrix/EventTypes/UnknownStateEventContent.cs b/LibMatrix/EventTypes/UnknownStateEventContent.cs new file mode 100644 index 0000000..9a276c8 --- /dev/null +++ b/LibMatrix/EventTypes/UnknownStateEventContent.cs @@ -0,0 +1,7 @@ +using LibMatrix.Interfaces; + +namespace LibMatrix.EventTypes; + +public class UnknownEventContent : EventContent { + +} diff --git a/LibMatrix/EventTypes/UnknownStateEventData.cs b/LibMatrix/EventTypes/UnknownStateEventData.cs deleted file mode 100644 index 9a276c8..0000000 --- a/LibMatrix/EventTypes/UnknownStateEventData.cs +++ /dev/null @@ -1,7 +0,0 @@ -using LibMatrix.Interfaces; - -namespace LibMatrix.EventTypes; - -public class UnknownEventContent : EventContent { - -} -- cgit 1.4.1