fix over-tabulation
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
a88f913a17
commit
3dc91525ce
1 changed files with 140 additions and 137 deletions
|
@ -269,7 +269,7 @@ impl Service {
|
||||||
) -> Result<Option<SummaryAccessibility>> {
|
) -> Result<Option<SummaryAccessibility>> {
|
||||||
for server in via {
|
for server in via {
|
||||||
debug_info!("Asking {server} for /hierarchy");
|
debug_info!("Asking {server} for /hierarchy");
|
||||||
if let Ok(response) = services()
|
let Ok(response) = services()
|
||||||
.sending
|
.sending
|
||||||
.send_federation_request(
|
.send_federation_request(
|
||||||
server,
|
server,
|
||||||
|
@ -279,68 +279,70 @@ impl Service {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
else {
|
||||||
debug_info!("Got response from {server} for /hierarchy\n{response:?}");
|
continue;
|
||||||
let summary = response.room.clone();
|
};
|
||||||
|
|
||||||
self.roomid_spacehierarchy_cache.lock().await.insert(
|
debug_info!("Got response from {server} for /hierarchy\n{response:?}");
|
||||||
current_room.clone(),
|
let summary = response.room.clone();
|
||||||
Some(CachedSpaceHierarchySummary {
|
|
||||||
summary: summary.clone(),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
for child in response.children {
|
self.roomid_spacehierarchy_cache.lock().await.insert(
|
||||||
let mut guard = self.roomid_spacehierarchy_cache.lock().await;
|
current_room.clone(),
|
||||||
if !guard.contains_key(current_room) {
|
Some(CachedSpaceHierarchySummary {
|
||||||
guard.insert(
|
summary: summary.clone(),
|
||||||
current_room.clone(),
|
}),
|
||||||
Some(CachedSpaceHierarchySummary {
|
);
|
||||||
summary: {
|
|
||||||
let SpaceHierarchyChildSummary {
|
|
||||||
canonical_alias,
|
|
||||||
name,
|
|
||||||
num_joined_members,
|
|
||||||
room_id,
|
|
||||||
topic,
|
|
||||||
world_readable,
|
|
||||||
guest_can_join,
|
|
||||||
avatar_url,
|
|
||||||
join_rule,
|
|
||||||
room_type,
|
|
||||||
allowed_room_ids,
|
|
||||||
} = child;
|
|
||||||
|
|
||||||
SpaceHierarchyParentSummary {
|
for child in response.children {
|
||||||
canonical_alias,
|
let mut guard = self.roomid_spacehierarchy_cache.lock().await;
|
||||||
name,
|
if !guard.contains_key(current_room) {
|
||||||
num_joined_members,
|
guard.insert(
|
||||||
room_id: room_id.clone(),
|
current_room.clone(),
|
||||||
topic,
|
Some(CachedSpaceHierarchySummary {
|
||||||
world_readable,
|
summary: {
|
||||||
guest_can_join,
|
let SpaceHierarchyChildSummary {
|
||||||
avatar_url,
|
canonical_alias,
|
||||||
join_rule,
|
name,
|
||||||
room_type,
|
num_joined_members,
|
||||||
children_state: get_stripped_space_child_events(&room_id).await?.unwrap(),
|
room_id,
|
||||||
allowed_room_ids,
|
topic,
|
||||||
}
|
world_readable,
|
||||||
},
|
guest_can_join,
|
||||||
}),
|
avatar_url,
|
||||||
);
|
join_rule,
|
||||||
}
|
room_type,
|
||||||
|
allowed_room_ids,
|
||||||
|
} = child;
|
||||||
|
|
||||||
|
SpaceHierarchyParentSummary {
|
||||||
|
canonical_alias,
|
||||||
|
name,
|
||||||
|
num_joined_members,
|
||||||
|
room_id: room_id.clone(),
|
||||||
|
topic,
|
||||||
|
world_readable,
|
||||||
|
guest_can_join,
|
||||||
|
avatar_url,
|
||||||
|
join_rule,
|
||||||
|
room_type,
|
||||||
|
children_state: get_stripped_space_child_events(&room_id).await?.unwrap(),
|
||||||
|
allowed_room_ids,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if is_accessable_child(
|
|
||||||
current_room,
|
|
||||||
&response.room.join_rule,
|
|
||||||
&Identifier::UserId(user_id),
|
|
||||||
&response.room.allowed_room_ids,
|
|
||||||
) {
|
|
||||||
return Ok(Some(SummaryAccessibility::Accessible(Box::new(summary.clone()))));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(Some(SummaryAccessibility::Inaccessible));
|
|
||||||
}
|
}
|
||||||
|
if is_accessable_child(
|
||||||
|
current_room,
|
||||||
|
&response.room.join_rule,
|
||||||
|
&Identifier::UserId(user_id),
|
||||||
|
&response.room.allowed_room_ids,
|
||||||
|
) {
|
||||||
|
return Ok(Some(SummaryAccessibility::Accessible(Box::new(summary.clone()))));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(Some(SummaryAccessibility::Inaccessible));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.roomid_spacehierarchy_cache
|
self.roomid_spacehierarchy_cache
|
||||||
|
@ -461,24 +463,27 @@ impl Service {
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
|
|
||||||
while let Some((current_room, via)) = { next_room_to_traverse(&mut stack, &mut parents) } {
|
while let Some((current_room, via)) = { next_room_to_traverse(&mut stack, &mut parents) } {
|
||||||
if limit > results.len() {
|
if results.len() >= limit {
|
||||||
match (
|
break;
|
||||||
self.get_summary_and_children_client(¤t_room, suggested_only, sender_user, &via)
|
}
|
||||||
.await?,
|
|
||||||
current_room == room_id,
|
|
||||||
) {
|
|
||||||
(Some(SummaryAccessibility::Accessible(summary)), _) => {
|
|
||||||
let mut children: Vec<(OwnedRoomId, Vec<OwnedServerName>)> =
|
|
||||||
get_parent_children_via(&summary, suggested_only)
|
|
||||||
.into_iter()
|
|
||||||
.filter(|(room, _)| parents.iter().all(|parent| parent != room))
|
|
||||||
.rev()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if populate_results {
|
match (
|
||||||
results.push(summary_to_chunk(*summary.clone()));
|
self.get_summary_and_children_client(¤t_room, suggested_only, sender_user, &via)
|
||||||
} else {
|
.await?,
|
||||||
children = children
|
current_room == room_id,
|
||||||
|
) {
|
||||||
|
(Some(SummaryAccessibility::Accessible(summary)), _) => {
|
||||||
|
let mut children: Vec<(OwnedRoomId, Vec<OwnedServerName>)> =
|
||||||
|
get_parent_children_via(&summary, suggested_only)
|
||||||
|
.into_iter()
|
||||||
|
.filter(|(room, _)| parents.iter().all(|parent| parent != room))
|
||||||
|
.rev()
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if populate_results {
|
||||||
|
results.push(summary_to_chunk(*summary.clone()));
|
||||||
|
} else {
|
||||||
|
children = children
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.rev()
|
.rev()
|
||||||
.skip_while(|(room, _)| {
|
.skip_while(|(room, _)| {
|
||||||
|
@ -495,39 +500,36 @@ impl Service {
|
||||||
.rev()
|
.rev()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if children.is_empty() {
|
if children.is_empty() {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::InvalidParam,
|
ErrorKind::InvalidParam,
|
||||||
"Room IDs in token were not found.",
|
"Room IDs in token were not found.",
|
||||||
));
|
));
|
||||||
}
|
|
||||||
|
|
||||||
// We have reached the room after where we last left off
|
|
||||||
let parents_len = parents.len();
|
|
||||||
if checked!(parents_len + 1)? == short_room_ids.len() {
|
|
||||||
populate_results = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let parents_len: u64 = parents.len().try_into()?;
|
// We have reached the room after where we last left off
|
||||||
if !children.is_empty() && parents_len < max_depth {
|
let parents_len = parents.len();
|
||||||
parents.push_back(current_room.clone());
|
if checked!(parents_len + 1)? == short_room_ids.len() {
|
||||||
stack.push(children);
|
populate_results = true;
|
||||||
}
|
}
|
||||||
// Root room in the space hierarchy, we return an error
|
}
|
||||||
// if this one fails.
|
|
||||||
},
|
let parents_len: u64 = parents.len().try_into()?;
|
||||||
(Some(SummaryAccessibility::Inaccessible), true) => {
|
if !children.is_empty() && parents_len < max_depth {
|
||||||
return Err(Error::BadRequest(ErrorKind::forbidden(), "The requested room is inaccessible"));
|
parents.push_back(current_room.clone());
|
||||||
},
|
stack.push(children);
|
||||||
(None, true) => {
|
}
|
||||||
return Err(Error::BadRequest(ErrorKind::forbidden(), "The requested room was not found"));
|
// Root room in the space hierarchy, we return an error
|
||||||
},
|
// if this one fails.
|
||||||
// Just ignore other unavailable rooms
|
},
|
||||||
(None | Some(SummaryAccessibility::Inaccessible), false) => (),
|
(Some(SummaryAccessibility::Inaccessible), true) => {
|
||||||
}
|
return Err(Error::BadRequest(ErrorKind::forbidden(), "The requested room is inaccessible"));
|
||||||
} else {
|
},
|
||||||
break;
|
(None, true) => {
|
||||||
|
return Err(Error::BadRequest(ErrorKind::forbidden(), "The requested room was not found"));
|
||||||
|
},
|
||||||
|
// Just ignore other unavailable rooms
|
||||||
|
(None | Some(SummaryAccessibility::Inaccessible), false) => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,41 +576,42 @@ fn next_room_to_traverse(
|
||||||
async fn get_stripped_space_child_events(
|
async fn get_stripped_space_child_events(
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
) -> Result<Option<Vec<Raw<HierarchySpaceChildEvent>>>, Error> {
|
) -> Result<Option<Vec<Raw<HierarchySpaceChildEvent>>>, Error> {
|
||||||
if let Some(current_shortstatehash) = services().rooms.state.get_room_shortstatehash(room_id)? {
|
let Some(current_shortstatehash) = services().rooms.state.get_room_shortstatehash(room_id)? else {
|
||||||
let state = services()
|
return Ok(None);
|
||||||
.rooms
|
};
|
||||||
.state_accessor
|
|
||||||
.state_full_ids(current_shortstatehash)
|
|
||||||
.await?;
|
|
||||||
let mut children_pdus = Vec::new();
|
|
||||||
for (key, id) in state {
|
|
||||||
let (event_type, state_key) = services().rooms.short.get_statekey_from_short(key)?;
|
|
||||||
if event_type != StateEventType::SpaceChild {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let pdu = services()
|
let state = services()
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.state_accessor
|
||||||
.get_pdu(&id)?
|
.state_full_ids(current_shortstatehash)
|
||||||
.ok_or_else(|| Error::bad_database("Event in space state not found"))?;
|
.await?;
|
||||||
|
let mut children_pdus = Vec::new();
|
||||||
if serde_json::from_str::<SpaceChildEventContent>(pdu.content.get())
|
for (key, id) in state {
|
||||||
.ok()
|
let (event_type, state_key) = services().rooms.short.get_statekey_from_short(key)?;
|
||||||
.map(|c| c.via)
|
if event_type != StateEventType::SpaceChild {
|
||||||
.map_or(true, |v| v.is_empty())
|
continue;
|
||||||
{
|
}
|
||||||
continue;
|
|
||||||
}
|
let pdu = services()
|
||||||
|
.rooms
|
||||||
if OwnedRoomId::try_from(state_key).is_ok() {
|
.timeline
|
||||||
children_pdus.push(pdu.to_stripped_spacechild_state_event());
|
.get_pdu(&id)?
|
||||||
}
|
.ok_or_else(|| Error::bad_database("Event in space state not found"))?;
|
||||||
|
|
||||||
|
if serde_json::from_str::<SpaceChildEventContent>(pdu.content.get())
|
||||||
|
.ok()
|
||||||
|
.map(|c| c.via)
|
||||||
|
.map_or(true, |v| v.is_empty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if OwnedRoomId::try_from(state_key).is_ok() {
|
||||||
|
children_pdus.push(pdu.to_stripped_spacechild_state_event());
|
||||||
}
|
}
|
||||||
Ok(Some(children_pdus))
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(Some(children_pdus))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// With the given identifier, checks if a room is accessable
|
/// With the given identifier, checks if a room is accessable
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue