1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-10-15 19:42:07 +00:00

feat(spaces): hierarchy over federation

fix(spaces): deal with hierarchy recursion
fix(spaces): properly handle max_depth
refactor(spaces): token scheme to prevent clients from modifying max_depth and suggested_only
perf(spaces): use tokens to skip to room to start populating results at
feat(spaces): request hierarchy from servers in via field of child event
This commit is contained in:
Matthias Ahouansou 2024-03-02 11:12:22 +00:00
parent a9ff97e527
commit 56a51360e0
No known key found for this signature in database
9 changed files with 973 additions and 389 deletions

View file

@ -105,7 +105,7 @@ impl Services {
},
threads: rooms::threads::Service { db },
spaces: rooms::spaces::Service {
roomid_spacechunk_cache: Mutex::new(LruCache::new(200)),
roomid_spacehierarchy_cache: Mutex::new(LruCache::new(200)),
},
user: rooms::user::Service { db },
},
@ -154,7 +154,13 @@ impl Services {
.lock()
.await
.len();
let roomid_spacechunk_cache = self.rooms.spaces.roomid_spacechunk_cache.lock().await.len();
let roomid_spacehierarchy_cache = self
.rooms
.spaces
.roomid_spacehierarchy_cache
.lock()
.await
.len();
format!(
"\
@ -163,7 +169,7 @@ server_visibility_cache: {server_visibility_cache}
user_visibility_cache: {user_visibility_cache}
stateinfo_cache: {stateinfo_cache}
lasttimelinecount_cache: {lasttimelinecount_cache}
roomid_spacechunk_cache: {roomid_spacechunk_cache}\
roomid_spacechunk_cache: {roomid_spacehierarchy_cache}\
"
)
}
@ -211,7 +217,7 @@ roomid_spacechunk_cache: {roomid_spacechunk_cache}\
if amount > 5 {
self.rooms
.spaces
.roomid_spacechunk_cache
.roomid_spacehierarchy_cache
.lock()
.await
.clear();

File diff suppressed because it is too large Load diff

View file

@ -93,7 +93,7 @@ impl Service {
services()
.rooms
.spaces
.roomid_spacechunk_cache
.roomid_spacehierarchy_cache
.lock()
.await
.remove(&pdu.room_id);

View file

@ -10,15 +10,18 @@ use ruma::{
events::{
room::{
avatar::RoomAvatarEventContent,
guest_access::{GuestAccess, RoomGuestAccessEventContent},
history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent, RoomMembership},
member::{MembershipState, RoomMemberEventContent},
name::RoomNameEventContent,
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
},
StateEventType,
},
space::SpaceRoomJoinRule,
state_res::Event,
EventId, JsOption, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
EventId, JsOption, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
};
use serde_json::value::to_raw_value;
use tokio::sync::MutexGuard;
@ -396,4 +399,70 @@ impl Service {
}
})
}
/// Checks if guests are able to join a given room
pub fn guest_can_join(&self, room_id: &RoomId) -> Result<bool, Error> {
self.room_state_get(room_id, &StateEventType::RoomGuestAccess, "")?
.map_or(Ok(false), |s| {
serde_json::from_str(s.content.get())
.map(|c: RoomGuestAccessEventContent| c.guest_access == GuestAccess::CanJoin)
.map_err(|_| {
Error::bad_database("Invalid room guest access event in database.")
})
})
}
/// Checks if guests are able to view room content without joining
pub fn world_readable(&self, room_id: &RoomId) -> Result<bool, Error> {
self.room_state_get(room_id, &StateEventType::RoomHistoryVisibility, "")?
.map_or(Ok(false), |s| {
serde_json::from_str(s.content.get())
.map(|c: RoomHistoryVisibilityEventContent| {
c.history_visibility == HistoryVisibility::WorldReadable
})
.map_err(|_| {
Error::bad_database("Invalid room history visibility event in database.")
})
})
}
/// Returns the join rule for a given room
pub fn get_join_rule(
&self,
current_room: &RoomId,
) -> Result<(SpaceRoomJoinRule, Vec<OwnedRoomId>), Error> {
Ok(self
.room_state_get(current_room, &StateEventType::RoomJoinRules, "")?
.map(|s| {
serde_json::from_str(s.content.get())
.map(|c: RoomJoinRulesEventContent| {
(
c.join_rule.clone().into(),
self.allowed_room_ids(c.join_rule),
)
})
.map_err(|e| {
error!("Invalid room join rule event in database: {}", e);
Error::BadDatabase("Invalid room join rule event in database.")
})
})
.transpose()?
.unwrap_or((SpaceRoomJoinRule::Invite, vec![])))
}
/// 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![];
if let JoinRule::Restricted(r) | JoinRule::KnockRestricted(r) = join_rule {
for rule in r.allow {
if let AllowRule::RoomMembership(RoomMembership {
room_id: membership,
}) = rule
{
room_ids.push(membership.to_owned());
}
}
}
room_ids
}
}

View file

@ -248,11 +248,13 @@ impl Service {
self.db.room_members(room_id)
}
/// Returns the number of users which are currently in a room
#[tracing::instrument(skip(self))]
pub fn room_joined_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
self.db.room_joined_count(room_id)
}
/// Returns the number of users which are currently invited to a room
#[tracing::instrument(skip(self))]
pub fn room_invited_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
self.db.room_invited_count(room_id)

View file

@ -430,7 +430,7 @@ impl Service {
services()
.rooms
.spaces
.roomid_spacechunk_cache
.roomid_spacehierarchy_cache
.lock()
.await
.remove(&pdu.room_id);