From 17603f0d16182bd955aa971e3a04c0d5bdfa6eea Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Fri, 15 May 2026 21:18:05 -0400 Subject: [PATCH] add join rules event --- lib/models/content/canonical_alias.dart | 17 +++++++++++++ lib/models/content/content.dart | 4 +++ lib/models/content/join_rules.dart | 34 +++++++++++++++++++++++++ lib/models/join_rule.dart | 4 +++ 4 files changed, 59 insertions(+) create mode 100644 lib/models/content/canonical_alias.dart create mode 100644 lib/models/content/join_rules.dart create mode 100644 lib/models/join_rule.dart diff --git a/lib/models/content/canonical_alias.dart b/lib/models/content/canonical_alias.dart new file mode 100644 index 0000000..f675401 --- /dev/null +++ b/lib/models/content/canonical_alias.dart @@ -0,0 +1,17 @@ +import "package:freezed_annotation/freezed_annotation.dart"; +import "package:nexus/models/content/content.dart"; +part "canonical_alias.freezed.dart"; +part "canonical_alias.g.dart"; + +@freezed +abstract class CanonicalAliasContent extends Content + with _$CanonicalAliasContent { + CanonicalAliasContent._(); + const factory CanonicalAliasContent({ + String? alias, + @Default([]) altAliases, + }) = _CanonicalAliasContent; + + factory CanonicalAliasContent.fromJson(Map json) => + _$CanonicalAliasContentFromJson(json); +} diff --git a/lib/models/content/content.dart b/lib/models/content/content.dart index be021ed..beff225 100644 --- a/lib/models/content/content.dart +++ b/lib/models/content/content.dart @@ -1,6 +1,8 @@ import "package:collection/collection.dart"; import "package:freezed_annotation/freezed_annotation.dart"; +import "package:nexus/models/content/canonical_alias.dart"; import "package:nexus/models/content/create.dart"; +import "package:nexus/models/content/join_rules.dart"; import "package:nexus/models/content/membership.dart"; import "package:nexus/models/content/message.dart"; @@ -22,6 +24,8 @@ enum EventType { encrypted("m.room.encrypted", Content.fromJson), membership("m.room.member", MembershipContent.fromJson), create("m.room.create", CreateContent.fromJson), + canonicalAlias("m.room.canonical_alias", CanonicalAliasContent.fromJson), + joinRules("m.room.join_rules", JoinRulesContent.fromJson), message("m.room.message", MessageContent.fromJson); final String type; diff --git a/lib/models/content/join_rules.dart b/lib/models/content/join_rules.dart new file mode 100644 index 0000000..a890d5c --- /dev/null +++ b/lib/models/content/join_rules.dart @@ -0,0 +1,34 @@ +import "package:fast_immutable_collections/fast_immutable_collections.dart"; +import "package:freezed_annotation/freezed_annotation.dart"; +import "package:nexus/models/content/content.dart"; +import "package:nexus/models/join_rule.dart"; +part "join_rules.freezed.dart"; +part "join_rules.g.dart"; + +@freezed +abstract class JoinRulesContent extends Content with _$JoinRulesContent { + JoinRulesContent._(); + const factory JoinRulesContent({ + required JoinRule joinRule, + @Default(IList.empty()) IList allow, + }) = _JoinRulesContent; + + factory JoinRulesContent.fromJson(Map json) => + _$JoinRulesContentFromJson(json); +} + +@freezed +abstract class AllowCondition with _$AllowCondition { + const factory AllowCondition({ + String? roomId, + required AllowConditionType type, + }) = _AllowCondition; + + factory AllowCondition.fromJson(Map json) => + _$AllowConditionFromJson(json); +} + +enum AllowConditionType { + @JsonValue("m.room_membership") + membership, +} diff --git a/lib/models/join_rule.dart b/lib/models/join_rule.dart new file mode 100644 index 0000000..3fade23 --- /dev/null +++ b/lib/models/join_rule.dart @@ -0,0 +1,4 @@ +import "package:freezed_annotation/freezed_annotation.dart"; + +@JsonEnum(fieldRename: FieldRename.snake) +enum JoinRule { public, knock, invite, private, restricted, knockRestricted }