From 51a2d101b600f2ec121b2c1148421b10da9470af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Tue, 25 Apr 2023 17:24:06 +0200 Subject: [PATCH] base: Remove RoomMemberships::UNKNOWN/KNOWN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The unknown filter can be difficult to match with MembershipState, depending on the store implementation. Signed-off-by: Kévin Commaille --- crates/matrix-sdk-base/src/rooms/mod.rs | 36 +++++++++---------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/crates/matrix-sdk-base/src/rooms/mod.rs b/crates/matrix-sdk-base/src/rooms/mod.rs index f1e1b636b46..b3081473fa1 100644 --- a/crates/matrix-sdk-base/src/rooms/mod.rs +++ b/crates/matrix-sdk-base/src/rooms/mod.rs @@ -309,30 +309,25 @@ fn calculate_room_name( } bitflags! { - /// Room memberships as a bitset. + /// Room membership filter as a bitset. /// - /// Note that, when used as a filter, [`RoomMemberships::empty()`] doesn't - /// filter the results and is equivalent to [`RoomMemberships::all()`]. + /// Note that [`RoomMemberships::empty()`] doesn't filter the results and + /// [`RoomMemberships::all()`] filters out unknown memberships. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct RoomMemberships: u16 { - /// An unknown (i.e. unspecced) membership. - const UNKNOWN = 0b00000001; /// The member joined the room. - const JOIN = 0b00000010; + const JOIN = 0b00000001; /// The member was invited to the room. - const INVITE = 0b00000100; + const INVITE = 0b00000010; /// The member requested to join the room. - const KNOCK = 0b00001000; + const KNOCK = 0b00000100; /// The member left the room. - const LEAVE = 0b00010000; + const LEAVE = 0b00001000; /// The member was banned. - const BAN = 0b00100000; + const BAN = 0b00010000; /// The member is active in the room (i.e. joined or invited). const ACTIVE = Self::JOIN.bits() | Self::INVITE.bits(); - - /// The member has a known (i.e. specced) membership. - const KNOWN = Self::JOIN.bits() | Self::INVITE.bits() | Self::KNOCK.bits() | Self::LEAVE.bits() | Self::BAN.bits(); } } @@ -343,21 +338,16 @@ impl RoomMemberships { return true; } - let membership = Self::from(membership); - self.contains(membership) - } -} - -impl From<&MembershipState> for RoomMemberships { - fn from(value: &MembershipState) -> Self { - match value { + let membership = match membership { MembershipState::Ban => Self::BAN, MembershipState::Invite => Self::INVITE, MembershipState::Join => Self::JOIN, MembershipState::Knock => Self::KNOCK, MembershipState::Leave => Self::LEAVE, - _ => Self::UNKNOWN, - } + _ => return false, + }; + + self.contains(membership) } }