All checks were successful
continuous-integration/drone/push Build is passing
35 lines
1.1 KiB
Rust
35 lines
1.1 KiB
Rust
use crate::controllers::HttpResult;
|
|
use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
|
|
use actix_web::HttpResponse;
|
|
use matrix_sdk_ui::spaces::SpaceService;
|
|
use matrix_sdk_ui::spaces::room_list::SpaceRoomListPaginationState;
|
|
use std::collections::HashMap;
|
|
|
|
/// Get space hierarchy
|
|
pub async fn hierarchy(client: MatrixClientExtractor) -> HttpResult {
|
|
let spaces = client.client.client.joined_space_rooms();
|
|
let space_service = SpaceService::new(client.client.client);
|
|
let mut hierarchy = HashMap::new();
|
|
for space in spaces {
|
|
let rooms = space_service
|
|
.space_room_list(space.room_id().to_owned())
|
|
.await;
|
|
while !matches!(
|
|
rooms.pagination_state(),
|
|
SpaceRoomListPaginationState::Idle { end_reached: true }
|
|
) {
|
|
rooms.paginate().await?;
|
|
}
|
|
|
|
hierarchy.insert(
|
|
space.room_id().to_owned(),
|
|
rooms
|
|
.rooms()
|
|
.into_iter()
|
|
.map(|room| room.room_id)
|
|
.collect::<Vec<_>>(),
|
|
);
|
|
}
|
|
Ok(HttpResponse::Ok().json(hierarchy))
|
|
}
|