Can get spaces hierarchy
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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 space_service = SpaceService::new(client.client.client);
|
||||
let spaces = space_service.joined_spaces().await;
|
||||
let mut hierarchy = HashMap::new();
|
||||
for space in spaces {
|
||||
let rooms = space_service.space_room_list(space.room_id.to_owned());
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user