From 16f2021c59e81f1db79aef780c560488f321cefa Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 13 Apr 2022 15:31:40 +0200 Subject: [PATCH] events: Add {RoomJoinRulesEvent, SyncJoinRulesEvent}::join_rule --- .../ruma-common/src/events/room/join_rules.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/ruma-common/src/events/room/join_rules.rs b/crates/ruma-common/src/events/room/join_rules.rs index 210ddb0d..a02a574d 100644 --- a/crates/ruma-common/src/events/room/join_rules.rs +++ b/crates/ruma-common/src/events/room/join_rules.rs @@ -49,6 +49,26 @@ impl<'de> Deserialize<'de> for RoomJoinRulesEventContent { } } +impl RoomJoinRulesEvent { + /// Obtain the join rule, regardless of whether this event is redacted. + pub fn join_rule(&self) -> &JoinRule { + match self { + Self::Original(ev) => &ev.content.join_rule, + Self::Redacted(ev) => &ev.content.join_rule, + } + } +} + +impl SyncRoomJoinRulesEvent { + /// Obtain the join rule, regardless of whether this event is redacted. + pub fn join_rule(&self) -> &JoinRule { + match self { + Self::Original(ev) => &ev.content.join_rule, + Self::Redacted(ev) => &ev.content.join_rule, + } + } +} + /// The rule used for users wishing to join this room. /// /// This type can hold an arbitrary string. To check for formats that are not available as a