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 --- .../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 +++ 28 files changed, 370 insertions(+), 370 deletions(-) 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 (limited to 'LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo') 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 -- cgit 1.4.1