Implement /rooms/<room_id>/joined_members

next
CapsizeGlimmer 2020-07-10 02:49:05 -04:00 committed by timokoesters
parent fdb7b8f0f1
commit 4d4969862a
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
4 changed files with 37 additions and 2 deletions

View File

@ -34,7 +34,8 @@ use ruma::{
media::{create_content, get_content, get_content_thumbnail, get_media_config}, media::{create_content, get_content, get_content_thumbnail, get_media_config},
membership::{ membership::{
ban_user, forget_room, get_member_events, invite_user, join_room_by_id, ban_user, forget_room, get_member_events, invite_user, join_room_by_id,
join_room_by_id_or_alias, joined_rooms, kick_user, leave_room, unban_user, join_room_by_id_or_alias, joined_members, joined_rooms, kick_user, leave_room,
unban_user,
}, },
message::{create_message_event, get_message_events}, message::{create_message_event, get_message_events},
presence::set_presence, presence::set_presence,
@ -1667,6 +1668,38 @@ pub fn kick_user_route(
Ok(kick_user::Response.into()) Ok(kick_user::Response.into())
} }
#[get("/_matrix/client/r0/rooms/<_room_id>/joined_members", data = "<body>")]
pub fn joined_members_route(
db: State<'_, Database>,
body: Ruma<joined_members::Request>,
_room_id: String,
) -> ConduitResult<joined_members::Response> {
let user_id = body.user_id.as_ref().expect("user is authenticated");
if !db.rooms.is_joined(&user_id, &body.room_id).unwrap_or(false) {
return Err(Error::BadRequest(
ErrorKind::Forbidden,
"You aren't a member of the room.",
));
}
let mut joined = BTreeMap::new();
for user_id in db.rooms.room_members(&body.room_id).filter_map(|r| r.ok()) {
let display_name = db.users.displayname(&user_id)?;
let avatar_url = db.users.avatar_url(&user_id)?;
joined.insert(
user_id,
joined_members::RoomMember {
display_name,
avatar_url,
},
);
}
Ok(joined_members::Response { joined }.into())
}
#[post("/_matrix/client/r0/rooms/<_room_id>/ban", data = "<body>")] #[post("/_matrix/client/r0/rooms/<_room_id>/ban", data = "<body>")]
pub fn ban_user_route( pub fn ban_user_route(
db: State<'_, Database>, db: State<'_, Database>,

View File

@ -81,7 +81,7 @@ impl Rooms {
Ok(hashmap) Ok(hashmap)
} }
/// Returns the full room state. /// Returns the all state entries for this type.
pub fn room_state_type( pub fn room_state_type(
&self, &self,
room_id: &RoomId, room_id: &RoomId,

View File

@ -64,6 +64,7 @@ fn setup_rocket() -> rocket::Rocket {
client_server::get_alias_route, client_server::get_alias_route,
client_server::join_room_by_id_route, client_server::join_room_by_id_route,
client_server::join_room_by_id_or_alias_route, client_server::join_room_by_id_or_alias_route,
client_server::joined_members_route,
client_server::leave_room_route, client_server::leave_room_route,
client_server::forget_room_route, client_server::forget_room_route,
client_server::joined_rooms_route, client_server::joined_rooms_route,

View File

@ -1,3 +1,4 @@
/joined_members return joined members
/joined_rooms returns only joined rooms /joined_rooms returns only joined rooms
3pid invite join valid signature but revoked keys are rejected 3pid invite join valid signature but revoked keys are rejected
3pid invite join valid signature but unreachable ID server are rejected 3pid invite join valid signature but unreachable ID server are rejected