From 08f5483df2c01eba7c764cdaec94fca71e4976b8 Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 30 May 2024 09:31:29 +0000 Subject: Clarify LegacyEvent types --- .../Common/MjolnirShortcodeEventContent.cs | 11 --- .../Common/RoomEmotesEventContent.cs | 24 ----- LibMatrix.EventTypes/EventContent.cs | 48 --------- LibMatrix.EventTypes/LibMatrix.EventTypes.csproj | 13 --- LibMatrix.EventTypes/MatrixEventAttribute.cs | 7 -- .../Spec/Ephemeral/PresenceStateEventContent.cs | 30 ------ .../Spec/Ephemeral/RoomTypingEventContent.cs | 11 --- .../Spec/RoomMessageEventContent.cs | 56 ----------- .../Spec/RoomMessageReactionEventContent.cs | 6 -- .../State/Policy/PolicyRuleStateEventContent.cs | 107 --------------------- .../Spec/State/RoomInfo/RoomAliasEventContent.cs | 11 --- .../Spec/State/RoomInfo/RoomAvatarEventContent.cs | 28 ------ .../RoomInfo/RoomCanonicalAliasEventContent.cs | 14 --- .../Spec/State/RoomInfo/RoomCreateEventContent.cs | 31 ------ .../State/RoomInfo/RoomEncryptionEventContent.cs | 17 ---- .../State/RoomInfo/RoomGuestAccessEventContent.cs | 17 ---- .../RoomInfo/RoomHistoryVisibilityEventContent.cs | 11 --- .../State/RoomInfo/RoomJoinRulesEventContent.cs | 60 ------------ .../Spec/State/RoomInfo/RoomMemberEventContent.cs | 37 ------- .../Spec/State/RoomInfo/RoomNameEventContent.cs | 11 --- .../Spec/State/RoomInfo/RoomPinnedEventContent.cs | 11 --- .../State/RoomInfo/RoomPowerLevelEventContent.cs | 93 ------------------ .../State/RoomInfo/RoomServerACLEventContent.cs | 17 ---- .../Spec/State/RoomInfo/RoomTopicEventContent.cs | 12 --- .../Spec/State/Space/SpaceChildEventContent.cs | 17 ---- .../Spec/State/Space/SpaceParentEventContent.cs | 14 --- .../Common/MjolnirShortcodeEventContent.cs | 11 +++ .../Common/RoomEmotesEventContent.cs | 24 +++++ LibMatrix.LegacyEvents.EventTypes/EventContent.cs | 48 +++++++++ .../LibMatrix.LegacyEvents.EventTypes.csproj | 22 +++++ .../MatrixEventAttribute.cs | 7 ++ .../Spec/Ephemeral/PresenceStateEventContent.cs | 30 ++++++ .../Spec/Ephemeral/RoomTypingEventContent.cs | 11 +++ .../Spec/RoomMessageEventContent.cs | 56 +++++++++++ .../Spec/RoomMessageReactionEventContent.cs | 6 ++ .../State/Policy/PolicyRuleStateEventContent.cs | 107 +++++++++++++++++++++ .../Spec/State/RoomInfo/RoomAliasEventContent.cs | 11 +++ .../Spec/State/RoomInfo/RoomAvatarEventContent.cs | 28 ++++++ .../RoomInfo/RoomCanonicalAliasEventContent.cs | 14 +++ .../Spec/State/RoomInfo/RoomCreateEventContent.cs | 31 ++++++ .../State/RoomInfo/RoomEncryptionEventContent.cs | 17 ++++ .../State/RoomInfo/RoomGuestAccessEventContent.cs | 17 ++++ .../RoomInfo/RoomHistoryVisibilityEventContent.cs | 11 +++ .../State/RoomInfo/RoomJoinRulesEventContent.cs | 60 ++++++++++++ .../Spec/State/RoomInfo/RoomMemberEventContent.cs | 37 +++++++ .../Spec/State/RoomInfo/RoomNameEventContent.cs | 11 +++ .../Spec/State/RoomInfo/RoomPinnedEventContent.cs | 11 +++ .../State/RoomInfo/RoomPowerLevelEventContent.cs | 93 ++++++++++++++++++ .../State/RoomInfo/RoomServerACLEventContent.cs | 17 ++++ .../Spec/State/RoomInfo/RoomTopicEventContent.cs | 12 +++ .../Spec/State/Space/SpaceChildEventContent.cs | 17 ++++ .../Spec/State/Space/SpaceParentEventContent.cs | 14 +++ LibMatrix.sln | 8 +- LibMatrix.sln.DotSettings.user | 4 +- LibMatrix/Helpers/MessageBuilder.cs | 2 +- LibMatrix/Helpers/MessageFormatter.cs | 2 +- .../Homeservers/AuthenticatedHomeserverGeneric.cs | 2 +- LibMatrix/LegacyMatrixEvent.cs | 2 +- LibMatrix/LibMatrix.csproj | 6 +- LibMatrix/Responses/CreateRoomRequest.cs | 4 +- LibMatrix/RoomTypes/GenericRoom.cs | 8 +- LibMatrix/Utilities/CommonSyncFilters.cs | 6 +- Tests/TestDataGenerator/Bot/DataFetcher.cs | 2 +- ...LibMatrix.JsonSerializerContextGenerator.csproj | 1 + .../Program.cs | 2 +- .../LibMatrix.Utilities.Bot/BotCommandInstaller.cs | 2 - .../Commands/AliassesCommand.cs | 3 +- .../Commands/HelpCommand.cs | 3 - .../Commands/PingCommand.cs | 2 +- .../Interfaces/CommandContext.cs | 2 +- .../LibMatrix.Utilities.Bot/Interfaces/ICommand.cs | 4 - .../LibMatrixBotConfiguration.cs | 1 - .../Services/CommandListenerHostedService.cs | 6 +- .../Services/InviteListenerHostedService.cs | 6 -- 74 files changed, 758 insertions(+), 757 deletions(-) delete mode 100644 LibMatrix.EventTypes/Common/MjolnirShortcodeEventContent.cs delete mode 100644 LibMatrix.EventTypes/Common/RoomEmotesEventContent.cs delete mode 100644 LibMatrix.EventTypes/EventContent.cs delete mode 100644 LibMatrix.EventTypes/MatrixEventAttribute.cs delete mode 100644 LibMatrix.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/RoomMessageEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/RoomMessageReactionEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/Space/SpaceChildEventContent.cs delete mode 100644 LibMatrix.EventTypes/Spec/State/Space/SpaceParentEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Common/MjolnirShortcodeEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Common/RoomEmotesEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/EventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/LibMatrix.LegacyEvents.EventTypes.csproj create mode 100644 LibMatrix.LegacyEvents.EventTypes/MatrixEventAttribute.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageReactionEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceChildEventContent.cs create mode 100644 LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceParentEventContent.cs diff --git a/LibMatrix.EventTypes/Common/MjolnirShortcodeEventContent.cs b/LibMatrix.EventTypes/Common/MjolnirShortcodeEventContent.cs deleted file mode 100644 index a31cbbb..0000000 --- a/LibMatrix.EventTypes/Common/MjolnirShortcodeEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Common/RoomEmotesEventContent.cs b/LibMatrix.EventTypes/Common/RoomEmotesEventContent.cs deleted file mode 100644 index b9a837f..0000000 --- a/LibMatrix.EventTypes/Common/RoomEmotesEventContent.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/EventContent.cs b/LibMatrix.EventTypes/EventContent.cs deleted file mode 100644 index c582cf2..0000000 --- a/LibMatrix.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.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.EventTypes/LibMatrix.EventTypes.csproj b/LibMatrix.EventTypes/LibMatrix.EventTypes.csproj index 4276003..3a63532 100644 --- a/LibMatrix.EventTypes/LibMatrix.EventTypes.csproj +++ b/LibMatrix.EventTypes/LibMatrix.EventTypes.csproj @@ -6,17 +6,4 @@ enable - - - - - - - - - diff --git a/LibMatrix.EventTypes/MatrixEventAttribute.cs b/LibMatrix.EventTypes/MatrixEventAttribute.cs deleted file mode 100644 index 5f06cec..0000000 --- a/LibMatrix.EventTypes/MatrixEventAttribute.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LibMatrix.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.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs b/LibMatrix.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs deleted file mode 100644 index fc2c355..0000000 --- a/LibMatrix.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs b/LibMatrix.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs deleted file mode 100644 index 494936d..0000000 --- a/LibMatrix.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/RoomMessageEventContent.cs b/LibMatrix.EventTypes/Spec/RoomMessageEventContent.cs deleted file mode 100644 index ae893f8..0000000 --- a/LibMatrix.EventTypes/Spec/RoomMessageEventContent.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/RoomMessageReactionEventContent.cs b/LibMatrix.EventTypes/Spec/RoomMessageReactionEventContent.cs deleted file mode 100644 index e2c0c8f..0000000 --- a/LibMatrix.EventTypes/Spec/RoomMessageReactionEventContent.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace LibMatrix.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.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs deleted file mode 100644 index 6006048..0000000 --- a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System.Text.Json.Serialization; -using ArcaneLibs.Attributes; - -namespace LibMatrix.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 -[FriendlyName(Name = "Server policy", NamePlural = "Server policies")] -public class ServerPolicyRuleEventContent : PolicyRuleEventContent { - 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 -[FriendlyName(Name = "User policy", NamePlural = "User policies")] -public class UserPolicyRuleEventContent : PolicyRuleEventContent { - 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 -[FriendlyName(Name = "Room policy", NamePlural = "Room policies")] -public class RoomPolicyRuleEventContent : PolicyRuleEventContent { - public const string EventId = "m.policy.rule.room"; -} - -public abstract class PolicyRuleEventContent : EventContent { - public PolicyRuleEventContent() => Console.WriteLine($"init policy {GetType().Name}"); - private string? _reason; - - /// - /// Entity this ban applies to, can use * and ? as globs. - /// Policy is invalid if entity is null - /// - [JsonPropertyName("entity")] - [FriendlyName(Name = "Entity")] - public string? Entity { get; set; } - - private bool init; - - /// - /// Reason this user is banned - /// - [JsonPropertyName("reason")] - [FriendlyName(Name = "Reason")] - public virtual string? Reason { - get => - // Console.WriteLine($"Read policy reason: {_reason}"); - _reason; - set => - // Console.WriteLine($"Set policy reason: {value}"); - // if(init) - // Console.WriteLine(string.Join('\n', Environment.StackTrace.Split('\n')[..5])); - // init = true; - _reason = value; - } - - /// - /// Suggested action to take - /// - [JsonPropertyName("recommendation")] - [FriendlyName(Name = "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 - [TableHide] - public long? Expiry { get; set; } - - //utils - /// - /// Readable expiry time, provided for easy interaction - /// - [JsonPropertyName("gay.rory.matrix_room_utils.readable_expiry_time_utc")] - [FriendlyName(Name = "Expires at")] - public DateTime? ExpiryDateTime { - get => Expiry == null ? null : DateTimeOffset.FromUnixTimeMilliseconds(Expiry.Value).DateTime; - set { - if (value is not null) - 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 -} - -// public class PolicySchemaDefinition { -// public required string Name { get; set; } -// public required bool Optional { get; set; } -// -// } \ No newline at end of file diff --git a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs deleted file mode 100644 index 4e82ac1..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs deleted file mode 100644 index c718826..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs deleted file mode 100644 index 93f13ac..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs deleted file mode 100644 index c619d0e..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs deleted file mode 100644 index b49abfa..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs deleted file mode 100644 index a7811bf..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs deleted file mode 100644 index 7676dad..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs deleted file mode 100644 index 349c8a7..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs deleted file mode 100644 index b2d5596..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs deleted file mode 100644 index 3ea5730..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs deleted file mode 100644 index b4474e9..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs deleted file mode 100644 index 49a1b62..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs deleted file mode 100644 index be83e37..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs b/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs deleted file mode 100644 index 92fa75d..0000000 --- a/LibMatrix.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/Space/SpaceChildEventContent.cs b/LibMatrix.EventTypes/Spec/State/Space/SpaceChildEventContent.cs deleted file mode 100644 index d233be4..0000000 --- a/LibMatrix.EventTypes/Spec/State/Space/SpaceChildEventContent.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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.EventTypes/Spec/State/Space/SpaceParentEventContent.cs b/LibMatrix.EventTypes/Spec/State/Space/SpaceParentEventContent.cs deleted file mode 100644 index 2ab79a4..0000000 --- a/LibMatrix.EventTypes/Spec/State/Space/SpaceParentEventContent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.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/Common/MjolnirShortcodeEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Common/MjolnirShortcodeEventContent.cs new file mode 100644 index 0000000..be8c154 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Common/MjolnirShortcodeEventContent.cs @@ -0,0 +1,11 @@ +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/RoomEmotesEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Common/RoomEmotesEventContent.cs new file mode 100644 index 0000000..ee268d9 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Common/RoomEmotesEventContent.cs @@ -0,0 +1,24 @@ +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/EventContent.cs b/LibMatrix.LegacyEvents.EventTypes/EventContent.cs new file mode 100644 index 0000000..3e76459 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/EventContent.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 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/LibMatrix.LegacyEvents.EventTypes.csproj b/LibMatrix.LegacyEvents.EventTypes/LibMatrix.LegacyEvents.EventTypes.csproj new file mode 100644 index 0000000..4276003 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/LibMatrix.LegacyEvents.EventTypes.csproj @@ -0,0 +1,22 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + diff --git a/LibMatrix.LegacyEvents.EventTypes/MatrixEventAttribute.cs b/LibMatrix.LegacyEvents.EventTypes/MatrixEventAttribute.cs new file mode 100644 index 0000000..708dad1 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/MatrixEventAttribute.cs @@ -0,0 +1,7 @@ +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/PresenceStateEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs new file mode 100644 index 0000000..676f36d --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/PresenceStateEventContent.cs @@ -0,0 +1,30 @@ +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 new file mode 100644 index 0000000..97b86fc --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/Ephemeral/RoomTypingEventContent.cs @@ -0,0 +1,11 @@ +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/RoomMessageEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageEventContent.cs new file mode 100644 index 0000000..ef26ab0 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageEventContent.cs @@ -0,0 +1,56 @@ +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/RoomMessageReactionEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageReactionEventContent.cs new file mode 100644 index 0000000..3649a6b --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/RoomMessageReactionEventContent.cs @@ -0,0 +1,6 @@ +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/State/Policy/PolicyRuleStateEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs new file mode 100644 index 0000000..c61f2bf --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs @@ -0,0 +1,107 @@ +using System.Text.Json.Serialization; +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 +[FriendlyName(Name = "Server policy", NamePlural = "Server policies")] +public class ServerPolicyRuleEventContent : PolicyRuleEventContent { + 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 +[FriendlyName(Name = "User policy", NamePlural = "User policies")] +public class UserPolicyRuleEventContent : PolicyRuleEventContent { + 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 +[FriendlyName(Name = "Room policy", NamePlural = "Room policies")] +public class RoomPolicyRuleEventContent : PolicyRuleEventContent { + public const string EventId = "m.policy.rule.room"; +} + +public abstract class PolicyRuleEventContent : EventContent { + public PolicyRuleEventContent() => Console.WriteLine($"init policy {GetType().Name}"); + private string? _reason; + + /// + /// Entity this ban applies to, can use * and ? as globs. + /// Policy is invalid if entity is null + /// + [JsonPropertyName("entity")] + [FriendlyName(Name = "Entity")] + public string? Entity { get; set; } + + private bool init; + + /// + /// Reason this user is banned + /// + [JsonPropertyName("reason")] + [FriendlyName(Name = "Reason")] + public virtual string? Reason { + get => + // Console.WriteLine($"Read policy reason: {_reason}"); + _reason; + set => + // Console.WriteLine($"Set policy reason: {value}"); + // if(init) + // Console.WriteLine(string.Join('\n', Environment.StackTrace.Split('\n')[..5])); + // init = true; + _reason = value; + } + + /// + /// Suggested action to take + /// + [JsonPropertyName("recommendation")] + [FriendlyName(Name = "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 + [TableHide] + public long? Expiry { get; set; } + + //utils + /// + /// Readable expiry time, provided for easy interaction + /// + [JsonPropertyName("gay.rory.matrix_room_utils.readable_expiry_time_utc")] + [FriendlyName(Name = "Expires at")] + public DateTime? ExpiryDateTime { + get => Expiry == null ? null : DateTimeOffset.FromUnixTimeMilliseconds(Expiry.Value).DateTime; + set { + if (value is not null) + 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 +} + +// public class PolicySchemaDefinition { +// public required string Name { get; set; } +// public required bool Optional { get; set; } +// +// } \ No newline at end of file diff --git a/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs new file mode 100644 index 0000000..197fe4b --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAliasEventContent.cs @@ -0,0 +1,11 @@ +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/RoomAvatarEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs new file mode 100644 index 0000000..bc70d65 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomAvatarEventContent.cs @@ -0,0 +1,28 @@ +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/RoomCanonicalAliasEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs new file mode 100644 index 0000000..790f80b --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCanonicalAliasEventContent.cs @@ -0,0 +1,14 @@ +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/RoomCreateEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs new file mode 100644 index 0000000..c6d259d --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomCreateEventContent.cs @@ -0,0 +1,31 @@ +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/RoomEncryptionEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs new file mode 100644 index 0000000..2fed1f3 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomEncryptionEventContent.cs @@ -0,0 +1,17 @@ +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/RoomGuestAccessEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs new file mode 100644 index 0000000..be66dbf --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomGuestAccessEventContent.cs @@ -0,0 +1,17 @@ +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/RoomHistoryVisibilityEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs new file mode 100644 index 0000000..0be42d6 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomHistoryVisibilityEventContent.cs @@ -0,0 +1,11 @@ +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/RoomJoinRulesEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs new file mode 100644 index 0000000..48202a5 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomJoinRulesEventContent.cs @@ -0,0 +1,60 @@ +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/RoomMemberEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs new file mode 100644 index 0000000..1926417 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomMemberEventContent.cs @@ -0,0 +1,37 @@ +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/RoomNameEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs new file mode 100644 index 0000000..165a1a3 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomNameEventContent.cs @@ -0,0 +1,11 @@ +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/RoomPinnedEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs new file mode 100644 index 0000000..4c08396 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPinnedEventContent.cs @@ -0,0 +1,11 @@ +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/RoomPowerLevelEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs new file mode 100644 index 0000000..e7b58ee --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomPowerLevelEventContent.cs @@ -0,0 +1,93 @@ +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/RoomServerACLEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs new file mode 100644 index 0000000..506203f --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomServerACLEventContent.cs @@ -0,0 +1,17 @@ +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/RoomTopicEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs new file mode 100644 index 0000000..d9e1ba9 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/RoomInfo/RoomTopicEventContent.cs @@ -0,0 +1,12 @@ +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/Space/SpaceChildEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceChildEventContent.cs new file mode 100644 index 0000000..bd8ff64 --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceChildEventContent.cs @@ -0,0 +1,17 @@ +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/SpaceParentEventContent.cs b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceParentEventContent.cs new file mode 100644 index 0000000..4e9903f --- /dev/null +++ b/LibMatrix.LegacyEvents.EventTypes/Spec/State/Space/SpaceParentEventContent.cs @@ -0,0 +1,14 @@ +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.sln b/LibMatrix.sln index c068216..257a8f2 100644 --- a/LibMatrix.sln +++ b/LibMatrix.sln @@ -33,10 +33,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ArcaneLibs", "ArcaneLibs", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArcaneLibs", "ArcaneLibs\ArcaneLibs\ArcaneLibs.csproj", "{13A797D1-7E13-4789-A167-8628B1641AC0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.EventTypes", "LibMatrix.EventTypes\LibMatrix.EventTypes.csproj", "{CD13665B-B964-4AB0-991B-12F067B16DA3}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.LegacyEvents.EventTypes", "LibMatrix.LegacyEvents.EventTypes\LibMatrix.LegacyEvents.EventTypes.csproj", "{CD13665B-B964-4AB0-991B-12F067B16DA3}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.HomeserverEmulator", "Tests\LibMatrix.HomeserverEmulator\LibMatrix.HomeserverEmulator.csproj", "{D44DB78D-9BAD-4AB6-A054-839ECA9D68D2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.EventTypes", "LibMatrix.EventTypes\LibMatrix.EventTypes.csproj", "{E9E9567D-58F4-4E17-BBC1-D4746C2526DB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -98,6 +100,10 @@ Global {D44DB78D-9BAD-4AB6-A054-839ECA9D68D2}.Debug|Any CPU.Build.0 = Debug|Any CPU {D44DB78D-9BAD-4AB6-A054-839ECA9D68D2}.Release|Any CPU.ActiveCfg = Release|Any CPU {D44DB78D-9BAD-4AB6-A054-839ECA9D68D2}.Release|Any CPU.Build.0 = Release|Any CPU + {E9E9567D-58F4-4E17-BBC1-D4746C2526DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9E9567D-58F4-4E17-BBC1-D4746C2526DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9E9567D-58F4-4E17-BBC1-D4746C2526DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9E9567D-58F4-4E17-BBC1-D4746C2526DB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {1B1B2197-61FB-416F-B6C8-845F2E5A0442} = {840309F0-435B-43A7-8471-8C2BE643889D} diff --git a/LibMatrix.sln.DotSettings.user b/LibMatrix.sln.DotSettings.user index e26043a..ec6bdc7 100644 --- a/LibMatrix.sln.DotSettings.user +++ b/LibMatrix.sln.DotSettings.user @@ -3,4 +3,6 @@ ShowAndRun <AssemblyExplorer> <Assembly Path="/home/root@Rory/.cache/NuGetPackages/microsoft.extensions.hosting.abstractions/7.0.0/lib/net7.0/Microsoft.Extensions.Hosting.Abstractions.dll" /> -</AssemblyExplorer> \ No newline at end of file +</AssemblyExplorer> + True + True \ No newline at end of file diff --git a/LibMatrix/Helpers/MessageBuilder.cs b/LibMatrix/Helpers/MessageBuilder.cs index d897078..54de7ad 100644 --- a/LibMatrix/Helpers/MessageBuilder.cs +++ b/LibMatrix/Helpers/MessageBuilder.cs @@ -1,4 +1,4 @@ -using LibMatrix.EventTypes.Spec; +using LibMatrix.LegacyEvents.EventTypes.Spec; namespace LibMatrix.Helpers; diff --git a/LibMatrix/Helpers/MessageFormatter.cs b/LibMatrix/Helpers/MessageFormatter.cs index 1b9b4f3..f234d8f 100644 --- a/LibMatrix/Helpers/MessageFormatter.cs +++ b/LibMatrix/Helpers/MessageFormatter.cs @@ -1,5 +1,5 @@ using ArcaneLibs.Extensions; -using LibMatrix.EventTypes.Spec; +using LibMatrix.LegacyEvents.EventTypes.Spec; namespace LibMatrix.Helpers; diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs index c729a44..86977ec 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs @@ -5,7 +5,7 @@ using System.Text.Json.Nodes; using System.Text.Json.Serialization; using System.Web; using ArcaneLibs.Extensions; -using LibMatrix.EventTypes.Spec.State; +using LibMatrix.LegacyEvents.EventTypes.Spec.State; using LibMatrix.Extensions; using LibMatrix.Filters; using LibMatrix.Helpers; diff --git a/LibMatrix/LegacyMatrixEvent.cs b/LibMatrix/LegacyMatrixEvent.cs index 1cfc879..1c1ebf3 100644 --- a/LibMatrix/LegacyMatrixEvent.cs +++ b/LibMatrix/LegacyMatrixEvent.cs @@ -7,7 +7,7 @@ using System.Text.Json.Serialization; using ArcaneLibs; using ArcaneLibs.Attributes; using ArcaneLibs.Extensions; -using LibMatrix.EventTypes; +using LibMatrix.LegacyEvents.EventTypes; using LibMatrix.Extensions; namespace LibMatrix; diff --git a/LibMatrix/LibMatrix.csproj b/LibMatrix/LibMatrix.csproj index b85df52..42ef17d 100644 --- a/LibMatrix/LibMatrix.csproj +++ b/LibMatrix/LibMatrix.csproj @@ -23,9 +23,11 @@ If you want to use a time-appropriate version of the library, recursively clone https://cgit.rory.gay/matrix/MatrixUtils.git instead, since this will be locked by the MatrixUtils project, which contains both LibMatrix and ArcaneLibs as a submodule. --> - - + + + + diff --git a/LibMatrix/Responses/CreateRoomRequest.cs b/LibMatrix/Responses/CreateRoomRequest.cs index f5218b9..6919b84 100644 --- a/LibMatrix/Responses/CreateRoomRequest.cs +++ b/LibMatrix/Responses/CreateRoomRequest.cs @@ -2,8 +2,8 @@ using System.Reflection; using System.Text.Json.Nodes; using System.Text.Json.Serialization; using System.Text.RegularExpressions; -using LibMatrix.EventTypes; -using LibMatrix.EventTypes.Spec.State; +using LibMatrix.LegacyEvents.EventTypes; +using LibMatrix.LegacyEvents.EventTypes.Spec.State; using LibMatrix.Homeservers; namespace LibMatrix.Responses; diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs index 5d85abd..3ef2395 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs @@ -6,10 +6,10 @@ using System.Text.Json.Nodes; using System.Text.Json.Serialization; using System.Web; using ArcaneLibs.Extensions; -using LibMatrix.EventTypes; -using LibMatrix.EventTypes.Spec; -using LibMatrix.EventTypes.Spec.State; -using LibMatrix.EventTypes.Spec.State.RoomInfo; +using LibMatrix.LegacyEvents.EventTypes; +using LibMatrix.LegacyEvents.EventTypes.Spec; +using LibMatrix.LegacyEvents.EventTypes.Spec.State; +using LibMatrix.LegacyEvents.EventTypes.Spec.State.RoomInfo; using LibMatrix.Filters; using LibMatrix.Helpers; using LibMatrix.Homeservers; diff --git a/LibMatrix/Utilities/CommonSyncFilters.cs b/LibMatrix/Utilities/CommonSyncFilters.cs index bf8b987..401850c 100644 --- a/LibMatrix/Utilities/CommonSyncFilters.cs +++ b/LibMatrix/Utilities/CommonSyncFilters.cs @@ -1,7 +1,7 @@ using System.Collections.Frozen; -using LibMatrix.EventTypes.Common; -using LibMatrix.EventTypes.Spec.State; -using LibMatrix.EventTypes.Spec.State.RoomInfo; +using LibMatrix.LegacyEvents.EventTypes.Common; +using LibMatrix.LegacyEvents.EventTypes.Spec.State; +using LibMatrix.LegacyEvents.EventTypes.Spec.State.RoomInfo; using LibMatrix.Filters; namespace LibMatrix.Utilities; diff --git a/Tests/TestDataGenerator/Bot/DataFetcher.cs b/Tests/TestDataGenerator/Bot/DataFetcher.cs index 66b8a03..1367e1c 100644 --- a/Tests/TestDataGenerator/Bot/DataFetcher.cs +++ b/Tests/TestDataGenerator/Bot/DataFetcher.cs @@ -1,6 +1,6 @@ using ArcaneLibs.Extensions; -using LibMatrix.EventTypes.Spec; using LibMatrix.Homeservers; +using LibMatrix.LegacyEvents.EventTypes.Spec; using LibMatrix.RoomTypes; using LibMatrix.Utilities.Bot; using Microsoft.Extensions.Hosting; diff --git a/Utilities/LibMatrix.JsonSerializerContextGenerator/LibMatrix.JsonSerializerContextGenerator.csproj b/Utilities/LibMatrix.JsonSerializerContextGenerator/LibMatrix.JsonSerializerContextGenerator.csproj index 35cb9f8..62dc202 100644 --- a/Utilities/LibMatrix.JsonSerializerContextGenerator/LibMatrix.JsonSerializerContextGenerator.csproj +++ b/Utilities/LibMatrix.JsonSerializerContextGenerator/LibMatrix.JsonSerializerContextGenerator.csproj @@ -9,6 +9,7 @@ + diff --git a/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs b/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs index f33efeb..6348085 100644 --- a/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs +++ b/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs @@ -1,6 +1,6 @@ using ArcaneLibs; using ArcaneLibs.Extensions.Streams; -using LibMatrix.EventTypes; +using LibMatrix.LegacyEvents.EventTypes; // string binary = args.Length > 1 ? args[0] : Console.ReadLine()!; diff --git a/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs b/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs index 215f28a..c91721e 100644 --- a/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs +++ b/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs @@ -1,7 +1,5 @@ using ArcaneLibs; -using LibMatrix.EventTypes.Spec.State; using LibMatrix.Homeservers; -using LibMatrix.Responses; using LibMatrix.Services; using LibMatrix.Utilities.Bot.Interfaces; using LibMatrix.Utilities.Bot.Services; diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs index 5c9c480..68fc884 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs @@ -1,7 +1,6 @@ -using System.Collections.Frozen; using System.Text; -using LibMatrix.EventTypes.Spec; using LibMatrix.Helpers; +using LibMatrix.LegacyEvents.EventTypes.Spec; using LibMatrix.Utilities.Bot.Interfaces; using Microsoft.Extensions.DependencyInjection; diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs index 0abc76b..d55c67c 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs @@ -1,6 +1,3 @@ -using System.Collections.Frozen; -using System.Text; -using LibMatrix.EventTypes.Spec; using LibMatrix.Helpers; using LibMatrix.Utilities.Bot.Interfaces; using Microsoft.Extensions.DependencyInjection; diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs index 76e48f5..04d5124 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs @@ -1,4 +1,4 @@ -using LibMatrix.EventTypes.Spec; +using LibMatrix.LegacyEvents.EventTypes.Spec; using LibMatrix.Utilities.Bot.Interfaces; namespace LibMatrix.Utilities.Bot.Commands; diff --git a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs index 541b720..c171dfe 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs @@ -1,5 +1,5 @@ -using LibMatrix.EventTypes.Spec; using LibMatrix.Homeservers; +using LibMatrix.LegacyEvents.EventTypes.Spec; using LibMatrix.RoomTypes; namespace LibMatrix.Utilities.Bot.Interfaces; diff --git a/Utilities/LibMatrix.Utilities.Bot/Interfaces/ICommand.cs b/Utilities/LibMatrix.Utilities.Bot/Interfaces/ICommand.cs index 941d69e..7b4afa9 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Interfaces/ICommand.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Interfaces/ICommand.cs @@ -1,7 +1,3 @@ -using System.Collections.Frozen; -using System.Collections.Immutable; -using Microsoft.Extensions.DependencyInjection; - namespace LibMatrix.Utilities.Bot.Interfaces; public interface ICommand { diff --git a/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs b/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs index 245442f..aa4ca4d 100644 --- a/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs +++ b/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs @@ -1,4 +1,3 @@ -using LibMatrix.Utilities.Bot.Interfaces; using Microsoft.Extensions.Configuration; namespace LibMatrix.Utilities.Bot; diff --git a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs index b322362..feb174b 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs @@ -1,10 +1,8 @@ -using System.Reflection.Metadata; -using ArcaneLibs.Extensions; -using LibMatrix.EventTypes.Spec; -using LibMatrix.EventTypes.Spec.State; using LibMatrix.Filters; using LibMatrix.Helpers; using LibMatrix.Homeservers; +using LibMatrix.LegacyEvents.EventTypes.Spec; +using LibMatrix.LegacyEvents.EventTypes.Spec.State; using LibMatrix.Utilities.Bot.Interfaces; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; diff --git a/Utilities/LibMatrix.Utilities.Bot/Services/InviteListenerHostedService.cs b/Utilities/LibMatrix.Utilities.Bot/Services/InviteListenerHostedService.cs index 9d79e44..c2aed04 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Services/InviteListenerHostedService.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Services/InviteListenerHostedService.cs @@ -1,12 +1,6 @@ -using System.Reflection.Metadata; -using ArcaneLibs.Extensions; -using LibMatrix.EventTypes.Spec; using LibMatrix.Filters; using LibMatrix.Helpers; using LibMatrix.Homeservers; -using LibMatrix.Responses; -using LibMatrix.Utilities.Bot.Interfaces; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -- cgit 1.4.1