1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-12-27 13:44:33 +01:00

improvement: implement GET publicRooms

This commit is contained in:
timokoesters 2020-05-19 16:28:03 +02:00
parent 821c608c6a
commit 61f4f2c716
No known key found for this signature in database
GPG key ID: 356E705610F626D5
2 changed files with 42 additions and 1 deletions

View file

@ -13,7 +13,7 @@ use ruma_client_api::{
alias::get_alias,
capabilities::get_capabilities,
config::{get_global_account_data, set_global_account_data},
directory::{self, get_public_rooms_filtered},
directory::{self, get_public_rooms, get_public_rooms_filtered},
filter::{self, create_filter, get_filter},
keys::{claim_keys, get_keys, upload_keys},
media::{create_content, get_content_thumbnail, get_content, get_media_config},
@ -1136,6 +1136,46 @@ pub fn invite_user_route(
}
}
#[get("/_matrix/client/r0/publicRooms")]
pub async fn get_public_rooms_route(
db: State<'_, Database>,
) -> MatrixResult<get_public_rooms::Response> {
let mut chunk = db
.rooms
.all_rooms()
.into_iter()
.map(|room_id| {
let state = db.rooms.room_state(&room_id).unwrap();
directory::PublicRoomsChunk {
aliases: Vec::new(),
canonical_alias: None,
name: state
.get(&(EventType::RoomName, "".to_owned()))
.and_then(|s| s.content.get("name"))
.and_then(|n| n.as_str())
.map(|n| n.to_owned()),
num_joined_members: (db.rooms.room_members(&room_id).count() as u32).into(),
room_id,
topic: None,
world_readable: false,
guest_can_join: true,
avatar_url: None,
}
})
.collect::<Vec<_>>();
chunk.sort_by(|l, r| r.num_joined_members.cmp(&l.num_joined_members));
let total_room_count_estimate = (chunk.len() as u32).into();
MatrixResult(Ok(get_public_rooms::Response {
chunk,
prev_batch: None,
next_batch: None,
total_room_count_estimate: Some(total_room_count_estimate),
}))
}
#[post("/_matrix/client/r0/publicRooms")]
pub async fn get_public_rooms_filtered_route(
db: State<'_, Database>,

View file

@ -55,6 +55,7 @@ fn setup_rocket() -> rocket::Rocket {
client_server::leave_room_route,
client_server::forget_room_route,
client_server::invite_user_route,
client_server::get_public_rooms_route,
client_server::get_public_rooms_filtered_route,
client_server::search_users_route,
client_server::get_member_events_route,