diff --git a/LibMatrix/StateEventTypes/Common/MjolnirShortcodeEventData.cs b/LibMatrix/StateEventTypes/Common/MjolnirShortcodeEventData.cs
new file mode 100644
index 0000000..808a0db
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Common/MjolnirShortcodeEventData.cs
@@ -0,0 +1,11 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Common;
+
+[MatrixEvent(EventName = "org.matrix.mjolnir.shortcode")]
+public class MjolnirShortcodeEventData : IStateEventType {
+ [JsonPropertyName("shortcode")]
+ public string? Shortcode { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Common/RoomEmotesEventData.cs b/LibMatrix/StateEventTypes/Common/RoomEmotesEventData.cs
new file mode 100644
index 0000000..af1c09e
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Common/RoomEmotesEventData.cs
@@ -0,0 +1,26 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Common;
+
+[MatrixEvent(EventName = "im.ponies.room_emotes")]
+public class RoomEmotesEventData : IStateEventType {
+ [JsonPropertyName("emoticons")]
+ public Dictionary<string, EmoticonData>? Emoticons { get; set; }
+
+ [JsonPropertyName("images")]
+ public Dictionary<string, EmoticonData>? Images { get; set; }
+
+ [JsonPropertyName("pack")]
+ public PackInfo? Pack { get; set; }
+
+ public class EmoticonData {
+ [JsonPropertyName("url")]
+ public string? Url { get; set; }
+ }
+
+ public class PackInfo {
+
+ }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/CanonicalAliasEventData.cs b/LibMatrix/StateEventTypes/Spec/CanonicalAliasEventData.cs
new file mode 100644
index 0000000..36cc90e
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/CanonicalAliasEventData.cs
@@ -0,0 +1,13 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.canonical_alias")]
+public class CanonicalAliasEventData : IStateEventType {
+ [JsonPropertyName("alias")]
+ public string? Alias { get; set; }
+ [JsonPropertyName("alt_aliases")]
+ public string[]? AltAliases { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/GuestAccessEventData.cs b/LibMatrix/StateEventTypes/Spec/GuestAccessEventData.cs
new file mode 100644
index 0000000..b6ddd93
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/GuestAccessEventData.cs
@@ -0,0 +1,16 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.guest_access")]
+public class GuestAccessEventData : IStateEventType {
+ [JsonPropertyName("guest_access")]
+ public string GuestAccess { get; set; }
+
+ public bool IsGuestAccessEnabled {
+ get => GuestAccess == "can_join";
+ set => GuestAccess = value ? "can_join" : "forbidden";
+ }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/HistoryVisibilityEventData.cs b/LibMatrix/StateEventTypes/Spec/HistoryVisibilityEventData.cs
new file mode 100644
index 0000000..8836fc0
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/HistoryVisibilityEventData.cs
@@ -0,0 +1,11 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.history_visibility")]
+public class HistoryVisibilityEventData : IStateEventType {
+ [JsonPropertyName("history_visibility")]
+ public string HistoryVisibility { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/JoinRulesEventData.cs b/LibMatrix/StateEventTypes/Spec/JoinRulesEventData.cs
new file mode 100644
index 0000000..0393395
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/JoinRulesEventData.cs
@@ -0,0 +1,18 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.join_rules")]
+public class JoinRulesEventData : IStateEventType {
+ private static string Public = "public";
+ private static string Invite = "invite";
+ private static string Knock = "knock";
+
+ [JsonPropertyName("join_rule")]
+ public string JoinRule { get; set; }
+
+ [JsonPropertyName("allow")]
+ public List<string> Allow { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/PolicyRuleStateEventData.cs b/LibMatrix/StateEventTypes/Spec/PolicyRuleStateEventData.cs
new file mode 100644
index 0000000..963864f
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/PolicyRuleStateEventData.cs
@@ -0,0 +1,56 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.policy.rule.user")]
+[MatrixEvent(EventName = "m.policy.rule.server")]
+[MatrixEvent(EventName = "org.matrix.mjolnir.rule.server")]
+public class PolicyRuleStateEventData : IStateEventType {
+ /// <summary>
+ /// Entity this ban applies to, can use * and ? as globs.
+ /// </summary>
+ [JsonPropertyName("entity")]
+ public string Entity { get; set; }
+
+ /// <summary>
+ /// Reason this user is banned
+ /// </summary>
+ [JsonPropertyName("reason")]
+ public string? Reason { get; set; }
+
+ /// <summary>
+ /// Suggested action to take
+ /// </summary>
+ [JsonPropertyName("recommendation")]
+ public string? Recommendation { get; set; }
+
+ /// <summary>
+ /// Expiry time in milliseconds since the unix epoch, or null if the ban has no expiry.
+ /// </summary>
+ [JsonPropertyName("support.feline.policy.expiry.rev.2")] //stable prefix: expiry, msc pending
+ public long? Expiry { get; set; }
+
+ //utils
+ /// <summary>
+ /// Readable expiry time, provided for easy interaction
+ /// </summary>
+ [JsonPropertyName("gay.rory.matrix_room_utils.readable_expiry_time_utc")]
+ public DateTime? ExpiryDateTime {
+ get => Expiry == null ? null : DateTimeOffset.FromUnixTimeMilliseconds(Expiry.Value).DateTime;
+ set => Expiry = ((DateTimeOffset)value).ToUnixTimeMilliseconds();
+ }
+}
+
+public static class PolicyRecommendationTypes {
+ /// <summary>
+ /// Ban this user
+ /// </summary>
+ public static string Ban = "m.ban";
+
+ /// <summary>
+ /// Mute this user
+ /// </summary>
+ public static string Mute = "support.feline.policy.recommendation_mute"; //stable prefix: m.mute, msc pending
+}
diff --git a/LibMatrix/StateEventTypes/Spec/PresenceStateEventData.cs b/LibMatrix/StateEventTypes/Spec/PresenceStateEventData.cs
new file mode 100644
index 0000000..fa75a88
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/PresenceStateEventData.cs
@@ -0,0 +1,17 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.presence")]
+public class PresenceStateEventData : IStateEventType {
+ [JsonPropertyName("presence")]
+ public string Presence { get; set; }
+ [JsonPropertyName("last_active_ago")]
+ public long LastActiveAgo { get; set; }
+ [JsonPropertyName("currently_active")]
+ public bool CurrentlyActive { get; set; }
+ [JsonPropertyName("status_msg")]
+ public string StatusMessage { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/ProfileResponseEventData.cs b/LibMatrix/StateEventTypes/Spec/ProfileResponseEventData.cs
new file mode 100644
index 0000000..d2340f5
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/ProfileResponseEventData.cs
@@ -0,0 +1,12 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+public class ProfileResponseEventData : IStateEventType {
+ [JsonPropertyName("avatar_url")]
+ public string? AvatarUrl { get; set; } = "";
+
+ [JsonPropertyName("displayname")]
+ public string? DisplayName { get; set; } = "";
+}
diff --git a/LibMatrix/StateEventTypes/Spec/RoomAliasEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomAliasEventData.cs
new file mode 100644
index 0000000..8d921b2
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/RoomAliasEventData.cs
@@ -0,0 +1,11 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.alias")]
+public class RoomAliasEventData : IStateEventType {
+ [JsonPropertyName("aliases")]
+ public List<string>? Aliases { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/RoomAvatarEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomAvatarEventData.cs
new file mode 100644
index 0000000..cbe41dd
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/RoomAvatarEventData.cs
@@ -0,0 +1,28 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.avatar")]
+public class RoomAvatarEventData : IStateEventType {
+ [JsonPropertyName("url")]
+ public string? Url { get; set; }
+
+ [JsonPropertyName("info")]
+ public RoomAvatarInfo? Info { get; set; }
+
+ public class RoomAvatarInfo {
+ [JsonPropertyName("h")]
+ public int? Height { get; set; }
+
+ [JsonPropertyName("w")]
+ public int? Width { get; set; }
+
+ [JsonPropertyName("mimetype")]
+ public string? MimeType { get; set; }
+
+ [JsonPropertyName("size")]
+ public int? Size { get; set; }
+ }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/RoomCreateEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomCreateEventData.cs
new file mode 100644
index 0000000..b96c31e
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/RoomCreateEventData.cs
@@ -0,0 +1,27 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.create")]
+public class RoomCreateEventData : IStateEventType {
+ [JsonPropertyName("room_version")]
+ public string? RoomVersion { get; set; }
+ [JsonPropertyName("creator")]
+ public string? Creator { get; set; }
+ [JsonPropertyName("m.federate")]
+ public bool? Federate { get; set; }
+ [JsonPropertyName("predecessor")]
+ public RoomCreatePredecessor? Predecessor { get; set; }
+ [JsonPropertyName("type")]
+ public string? Type { get; set; }
+
+ public class RoomCreatePredecessor {
+ [JsonPropertyName("room_id")]
+ public string? RoomId { get; set; }
+
+ [JsonPropertyName("event_id")]
+ public string? EventId { get; set; }
+ }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/RoomEncryptionEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomEncryptionEventData.cs
new file mode 100644
index 0000000..e16716e
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/RoomEncryptionEventData.cs
@@ -0,0 +1,15 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.encryption")]
+public class RoomEncryptionEventData : IStateEventType {
+ [JsonPropertyName("algorithm")]
+ public string? Algorithm { get; set; }
+ [JsonPropertyName("rotation_period_ms")]
+ public ulong? RotationPeriodMs { get; set; }
+ [JsonPropertyName("rotation_period_msgs")]
+ public ulong? RotationPeriodMsgs { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/RoomMemberEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomMemberEventData.cs
new file mode 100644
index 0000000..623c43c
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/RoomMemberEventData.cs
@@ -0,0 +1,29 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.member")]
+public class RoomMemberEventData : IStateEventType {
+ [JsonPropertyName("reason")]
+ public string? Reason { get; set; }
+
+ [JsonPropertyName("membership")]
+ public string Membership { get; set; } = null!;
+
+ [JsonPropertyName("displayname")]
+ public string? Displayname { get; set; }
+
+ [JsonPropertyName("is_direct")]
+ public bool? IsDirect { get; set; }
+
+ [JsonPropertyName("avatar_url")]
+ public string? AvatarUrl { get; set; }
+
+ [JsonPropertyName("kind")]
+ public string? Kind { get; set; }
+
+ [JsonPropertyName("join_authorised_via_users_server")]
+ public string? JoinAuthorisedViaUsersServer { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/RoomMessageEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomMessageEventData.cs
new file mode 100644
index 0000000..14dd67a
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/RoomMessageEventData.cs
@@ -0,0 +1,19 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.message")]
+public class RoomMessageEventData : IStateEventType {
+ [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; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/RoomNameEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomNameEventData.cs
new file mode 100644
index 0000000..9d13513
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/RoomNameEventData.cs
@@ -0,0 +1,11 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.name")]
+public class RoomNameEventData : IStateEventType {
+ [JsonPropertyName("name")]
+ public string? Name { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/RoomPinnedEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomPinnedEventData.cs
new file mode 100644
index 0000000..c7d29fa
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/RoomPinnedEventData.cs
@@ -0,0 +1,11 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.pinned_events")]
+public class RoomPinnedEventData : IStateEventType {
+ [JsonPropertyName("pinned")]
+ public string[]? PinnedEvents { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/RoomPowerLevelEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomPowerLevelEventData.cs
new file mode 100644
index 0000000..c5dda78
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/RoomPowerLevelEventData.cs
@@ -0,0 +1,56 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.power_levels")]
+public class RoomPowerLevelEventData : IStateEventType {
+ [JsonPropertyName("ban")]
+ public int Ban { get; set; } // = 50;
+
+ [JsonPropertyName("events_default")]
+ public int EventsDefault { get; set; } // = 0;
+
+ [JsonPropertyName("events")]
+ public Dictionary<string, int> Events { get; set; } // = null!;
+
+ [JsonPropertyName("invite")]
+ public int Invite { get; set; } // = 50;
+
+ [JsonPropertyName("kick")]
+ public int Kick { get; set; } // = 50;
+
+ [JsonPropertyName("notifications")]
+ public NotificationsPL NotificationsPl { get; set; } // = null!;
+
+ [JsonPropertyName("redact")]
+ public int Redact { get; set; } // = 50;
+
+ [JsonPropertyName("state_default")]
+ public int StateDefault { get; set; } // = 50;
+
+ [JsonPropertyName("users")]
+ public Dictionary<string, int> Users { get; set; } // = null!;
+
+ [JsonPropertyName("users_default")]
+ public int 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 int Historical { get; set; } // = 50;
+
+ public class NotificationsPL {
+ [JsonPropertyName("room")]
+ public int Room { get; set; } = 50;
+ }
+
+ public bool IsUserAdmin(string userId) {
+ return Users.TryGetValue(userId, out var level) && level >= Events.Max(x=>x.Value);
+ }
+
+ public bool UserHasPermission(string userId, string eventType) {
+ return Users.TryGetValue(userId, out var level) && level >= Events.GetValueOrDefault(eventType, EventsDefault);
+ }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/RoomTopicEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomTopicEventData.cs
new file mode 100644
index 0000000..0fd0df6
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/RoomTopicEventData.cs
@@ -0,0 +1,12 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.topic")]
+[MatrixEvent(EventName = "org.matrix.msc3765.topic", Legacy = true)]
+public class RoomTopicEventData : IStateEventType {
+ [JsonPropertyName("topic")]
+ public string? Topic { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/RoomTypingEventData.cs b/LibMatrix/StateEventTypes/Spec/RoomTypingEventData.cs
new file mode 100644
index 0000000..857338c
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/RoomTypingEventData.cs
@@ -0,0 +1,11 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.typing")]
+public class RoomTypingEventData : IStateEventType {
+ [JsonPropertyName("user_ids")]
+ public string[]? UserIds { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/ServerACLEventData.cs b/LibMatrix/StateEventTypes/Spec/ServerACLEventData.cs
new file mode 100644
index 0000000..68bbe6b
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/ServerACLEventData.cs
@@ -0,0 +1,17 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.room.server_acl")]
+public class ServerACLEventData : IStateEventType {
+ [JsonPropertyName("allow")]
+ public List<string> Allow { get; set; } // = null!;
+
+ [JsonPropertyName("deny")]
+ public List<string> Deny { get; set; } // = null!;
+
+ [JsonPropertyName("allow_ip_literals")]
+ public bool AllowIpLiterals { get; set; } // = false;
+}
diff --git a/LibMatrix/StateEventTypes/Spec/SpaceChildEventData.cs b/LibMatrix/StateEventTypes/Spec/SpaceChildEventData.cs
new file mode 100644
index 0000000..a55e941
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/SpaceChildEventData.cs
@@ -0,0 +1,15 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.space.child")]
+public class SpaceChildEventData : IStateEventType {
+ [JsonPropertyName("auto_join")]
+ public bool? AutoJoin { get; set; }
+ [JsonPropertyName("via")]
+ public string[]? Via { get; set; }
+ [JsonPropertyName("suggested")]
+ public bool? Suggested { get; set; }
+}
diff --git a/LibMatrix/StateEventTypes/Spec/SpaceParentEventData.cs b/LibMatrix/StateEventTypes/Spec/SpaceParentEventData.cs
new file mode 100644
index 0000000..7dc7f4c
--- /dev/null
+++ b/LibMatrix/StateEventTypes/Spec/SpaceParentEventData.cs
@@ -0,0 +1,14 @@
+using System.Text.Json.Serialization;
+using LibMatrix.Extensions;
+using LibMatrix.Interfaces;
+
+namespace LibMatrix.StateEventTypes.Spec;
+
+[MatrixEvent(EventName = "m.space.parent")]
+public class SpaceParentEventData : IStateEventType {
+ [JsonPropertyName("via")]
+ public string[]? Via { get; set; }
+
+ [JsonPropertyName("canonical")]
+ public bool? Canonical { get; set; }
+}
|