fixup+update msc3266, add fed support, parallelise IO

Signed-off-by: June Clementine Strawberry <june@3.dog>
This commit is contained in:
June Clementine Strawberry 2025-04-02 22:51:17 -04:00
parent 1036f8dfa8
commit 0e0b8cc403
No known key found for this signature in database
8 changed files with 389 additions and 174 deletions

View file

@ -27,7 +27,6 @@ use ruma::{
},
events::{
StateEventType,
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
space::child::{HierarchySpaceChildEvent, SpaceChildEventContent},
},
serde::Raw,
@ -306,25 +305,18 @@ async fn get_room_summary(
children_state: Vec<Raw<HierarchySpaceChildEvent>>,
identifier: &Identifier<'_>,
) -> Result<SpaceHierarchyParentSummary, Error> {
let join_rule = self
let (join_rule, allowed_room_ids) = self
.services
.state_accessor
.room_state_get_content(room_id, &StateEventType::RoomJoinRules, "")
.await
.map_or(JoinRule::Invite, |c: RoomJoinRulesEventContent| c.join_rule);
.get_space_join_rule(room_id)
.await;
let allowed_room_ids = self
.services
.state_accessor
.allowed_room_ids(join_rule.clone());
let join_rule = join_rule.clone().into();
let is_accessible_child = self
.is_accessible_child(room_id, &join_rule, identifier, &allowed_room_ids)
.await;
if !is_accessible_child {
return Err!(Request(Forbidden("User is not allowed to see the room",)));
return Err!(Request(Forbidden("User is not allowed to see the room")));
}
let name = self.services.state_accessor.get_name(room_id).ok();
@ -355,6 +347,14 @@ async fn get_room_summary(
.get_avatar(room_id)
.map(|res| res.into_option().unwrap_or_default().url);
let room_version = self.services.state.get_room_version(room_id).ok();
let encryption = self
.services
.state_accessor
.get_room_encryption(room_id)
.ok();
let (
canonical_alias,
name,
@ -364,6 +364,8 @@ async fn get_room_summary(
guest_can_join,
avatar_url,
room_type,
room_version,
encryption,
) = futures::join!(
canonical_alias,
name,
@ -372,7 +374,9 @@ async fn get_room_summary(
world_readable,
guest_can_join,
avatar_url,
room_type
room_type,
room_version,
encryption,
);
Ok(SpaceHierarchyParentSummary {
@ -387,9 +391,9 @@ async fn get_room_summary(
allowed_room_ids,
join_rule,
room_id: room_id.to_owned(),
num_joined_members: num_joined_members
.try_into()
.expect("user count should not be that big"),
num_joined_members: num_joined_members.try_into().unwrap_or_default(),
encryption,
room_version,
})
}
@ -487,6 +491,8 @@ async fn cache_insert(
join_rule,
room_type,
allowed_room_ids,
encryption,
room_version,
} = child;
let summary = SpaceHierarchyParentSummary {
@ -506,6 +512,8 @@ async fn cache_insert(
.map(PduEvent::into_stripped_spacechild_state_event)
.collect()
.await,
encryption,
room_version,
};
cache.insert(current_room.to_owned(), Some(CachedSpaceHierarchySummary { summary }));
@ -527,7 +535,9 @@ impl From<CachedSpaceHierarchySummary> for SpaceHierarchyRoomsChunk {
join_rule,
room_type,
children_state,
..
allowed_room_ids,
encryption,
room_version,
} = value.summary;
Self {
@ -542,6 +552,9 @@ impl From<CachedSpaceHierarchySummary> for SpaceHierarchyRoomsChunk {
join_rule,
room_type,
children_state,
encryption,
room_version,
allowed_room_ids,
}
}
}
@ -562,7 +575,9 @@ pub fn summary_to_chunk(summary: SpaceHierarchyParentSummary) -> SpaceHierarchyR
join_rule,
room_type,
children_state,
..
allowed_room_ids,
encryption,
room_version,
} = summary;
SpaceHierarchyRoomsChunk {
@ -577,5 +592,8 @@ pub fn summary_to_chunk(summary: SpaceHierarchyParentSummary) -> SpaceHierarchyR
join_rule,
room_type,
children_state,
encryption,
room_version,
allowed_room_ids,
}
}

View file

@ -129,22 +129,34 @@ impl Service {
.map(|c: RoomTopicEventContent| c.topic)
}
/// Returns the join rule (`SpaceRoomJoinRule`) for a given room
pub async fn get_join_rule(
/// Returns the space join rule (`SpaceRoomJoinRule`) for a given room and
/// any allowed room IDs if available. Will default to Invite and empty vec
/// if doesnt exist or invalid,
pub async fn get_space_join_rule(
&self,
room_id: &RoomId,
) -> Result<(SpaceRoomJoinRule, Vec<OwnedRoomId>)> {
) -> (SpaceRoomJoinRule, Vec<OwnedRoomId>) {
self.room_state_get_content(room_id, &StateEventType::RoomJoinRules, "")
.await
.map(|c: RoomJoinRulesEventContent| {
(c.join_rule.clone().into(), self.allowed_room_ids(c.join_rule))
})
.or_else(|_| Ok((SpaceRoomJoinRule::Invite, vec![])))
.map_or_else(
|_| (SpaceRoomJoinRule::Invite, vec![]),
|c: RoomJoinRulesEventContent| {
(c.join_rule.clone().into(), self.allowed_room_ids(c.join_rule))
},
)
}
/// Returns the join rules for a given room (`JoinRule` type). Will default
/// to Invite if doesnt exist or invalid
pub async fn get_join_rules(&self, room_id: &RoomId) -> JoinRule {
self.room_state_get_content(room_id, &StateEventType::RoomJoinRules, "")
.await
.map_or_else(|_| JoinRule::Invite, |c: RoomJoinRulesEventContent| (c.join_rule))
}
/// Returns an empty vec if not a restricted room
pub fn allowed_room_ids(&self, join_rule: JoinRule) -> Vec<OwnedRoomId> {
let mut room_ids = Vec::with_capacity(1);
let mut room_ids = Vec::with_capacity(1); // restricted rooms generally only have 1 allowed room ID
if let JoinRule::Restricted(r) | JoinRule::KnockRestricted(r) = join_rule {
for rule in r.allow {
if let AllowRule::RoomMembership(RoomMembership { room_id: membership }) = rule {