mirror of
https://github.com/girlbossceo/ruwuma.git
synced 2025-04-29 06:49:48 -04:00
add allowed_rooms() utility to JoinRule
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
db8fe2f361
commit
920148dca1
1 changed files with 21 additions and 2 deletions
|
@ -2,9 +2,12 @@
|
|||
//!
|
||||
//! [`m.room.join_rules`]: https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
|
||||
|
||||
use std::{borrow::Cow, collections::BTreeMap};
|
||||
use std::{
|
||||
borrow::{Borrow, Cow},
|
||||
collections::BTreeMap,
|
||||
};
|
||||
|
||||
use ruma_common::{serde::from_raw_json_value, space::SpaceRoomJoinRule, OwnedRoomId};
|
||||
use ruma_common::{serde::from_raw_json_value, space::SpaceRoomJoinRule, OwnedRoomId, RoomId};
|
||||
use ruma_macros::EventContent;
|
||||
use serde::{
|
||||
de::{Deserializer, Error},
|
||||
|
@ -113,6 +116,22 @@ pub enum JoinRule {
|
|||
}
|
||||
|
||||
impl JoinRule {
|
||||
/// Returns allowed room_id's for restricted rooms; empty for other variants
|
||||
pub fn allowed_rooms(&self) -> impl Iterator<Item = &RoomId> + Send {
|
||||
let rules = match self {
|
||||
JoinRule::Restricted(rules) | JoinRule::KnockRestricted(rules) => Some(rules),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
rules.into_iter().flat_map(|rules| rules.allow.iter()).filter_map(|rule| {
|
||||
if let AllowRule::RoomMembership(RoomMembership { room_id: membership }) = rule {
|
||||
Some(membership.borrow())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the string name of this `JoinRule`
|
||||
pub fn as_str(&self) -> &str {
|
||||
match self {
|
||||
|
|
Loading…
Add table
Reference in a new issue