1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-11-16 10:11:04 +01:00

fix: spaces with restricted rooms

This commit is contained in:
Timo Kösters 2023-07-26 08:33:27 +02:00
parent 9f14ad7125
commit bf46829595
No known key found for this signature in database
GPG key ID: 0B25E636FBA7E4CB

View file

@ -16,7 +16,7 @@ use ruma::{
create::RoomCreateEventContent, create::RoomCreateEventContent,
guest_access::{GuestAccess, RoomGuestAccessEventContent}, guest_access::{GuestAccess, RoomGuestAccessEventContent},
history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent}, history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
join_rules::{JoinRule, RoomJoinRulesEventContent}, join_rules::{self, AllowRule, JoinRule, RoomJoinRulesEventContent},
topic::RoomTopicEventContent, topic::RoomTopicEventContent,
}, },
StateEventType, StateEventType,
@ -30,7 +30,7 @@ use tracing::{debug, error, warn};
use crate::{services, Error, PduEvent, Result}; use crate::{services, Error, PduEvent, Result};
pub enum CachedJoinRule { pub enum CachedJoinRule {
Simplified(SpaceRoomJoinRule), //Simplified(SpaceRoomJoinRule),
Full(JoinRule), Full(JoinRule),
} }
@ -84,9 +84,9 @@ impl Service {
{ {
if let Some(cached) = cached { if let Some(cached) = cached {
let allowed = match &cached.join_rule { let allowed = match &cached.join_rule {
CachedJoinRule::Simplified(s) => { //CachedJoinRule::Simplified(s) => {
self.handle_simplified_join_rule(s, sender_user, &current_room)? //self.handle_simplified_join_rule(s, sender_user, &current_room)?
} //}
CachedJoinRule::Full(f) => { CachedJoinRule::Full(f) => {
self.handle_join_rule(f, sender_user, &current_room)? self.handle_join_rule(f, sender_user, &current_room)?
} }
@ -211,11 +211,34 @@ impl Service {
.map(|c| c.room_id.clone()) .map(|c| c.room_id.clone())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if self.handle_simplified_join_rule( let join_rule = match response.room.join_rule {
&response.room.join_rule, SpaceRoomJoinRule::Invite => JoinRule::Invite,
sender_user, SpaceRoomJoinRule::Knock => JoinRule::Knock,
&current_room, SpaceRoomJoinRule::Private => JoinRule::Private,
)? { SpaceRoomJoinRule::Restricted => {
JoinRule::Restricted(join_rules::Restricted {
allow: response
.room
.allowed_room_ids
.into_iter()
.map(|room| AllowRule::room_membership(room))
.collect(),
})
}
SpaceRoomJoinRule::KnockRestricted => {
JoinRule::KnockRestricted(join_rules::Restricted {
allow: response
.room
.allowed_room_ids
.into_iter()
.map(|room| AllowRule::room_membership(room))
.collect(),
})
}
SpaceRoomJoinRule::Public => JoinRule::Public,
_ => return Err(Error::BadServerResponse("Unknown join rule")),
};
if self.handle_join_rule(&join_rule, sender_user, &current_room)? {
if left_to_skip > 0 { if left_to_skip > 0 {
left_to_skip -= 1; left_to_skip -= 1;
} else { } else {
@ -231,7 +254,7 @@ impl Service {
Some(CachedSpaceChunk { Some(CachedSpaceChunk {
chunk, chunk,
children, children,
join_rule: CachedJoinRule::Simplified(response.room.join_rule), join_rule: CachedJoinRule::Full(join_rule),
}), }),
); );
@ -437,8 +460,22 @@ impl Service {
} }
match join_rule { match join_rule {
JoinRule::Restricted(_) => { JoinRule::Restricted(r) => {
// TODO: Check rules for rule in &r.allow {
match rule {
join_rules::AllowRule::RoomMembership(rm) => {
if let Ok(true) = services()
.rooms
.state_cache
.is_joined(sender_user, &rm.room_id)
{
return Ok(true);
}
}
_ => {}
}
}
Ok(false) Ok(false)
} }
JoinRule::KnockRestricted(_) => { JoinRule::KnockRestricted(_) => {