Skip to content

Commit

Permalink
base: Remove RoomMemberships::UNKNOWN/KNOWN
Browse files Browse the repository at this point in the history
The unknown filter can be difficult to match with MembershipState,
depending on the store implementation.

Signed-off-by: Kévin Commaille <[email protected]>
  • Loading branch information
zecakeh authored and jplatte committed Apr 26, 2023
1 parent f7e8b22 commit 51a2d10
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions crates/matrix-sdk-base/src/rooms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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)
}
}

Expand Down

0 comments on commit 51a2d10

Please sign in to comment.