Implement /rooms/<room_id>/joined_members
This commit is contained in:
parent
fdb7b8f0f1
commit
4d4969862a
|
@ -34,7 +34,8 @@ use ruma::{
|
|||
media::{create_content, get_content, get_content_thumbnail, get_media_config},
|
||||
membership::{
|
||||
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},
|
||||
presence::set_presence,
|
||||
|
@ -1667,6 +1668,38 @@ pub fn kick_user_route(
|
|||
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>")]
|
||||
pub fn ban_user_route(
|
||||
db: State<'_, Database>,
|
||||
|
|
|
@ -81,7 +81,7 @@ impl Rooms {
|
|||
Ok(hashmap)
|
||||
}
|
||||
|
||||
/// Returns the full room state.
|
||||
/// Returns the all state entries for this type.
|
||||
pub fn room_state_type(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
|
@ -64,6 +64,7 @@ fn setup_rocket() -> rocket::Rocket {
|
|||
client_server::get_alias_route,
|
||||
client_server::join_room_by_id_route,
|
||||
client_server::join_room_by_id_or_alias_route,
|
||||
client_server::joined_members_route,
|
||||
client_server::leave_room_route,
|
||||
client_server::forget_room_route,
|
||||
client_server::joined_rooms_route,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/joined_members return joined members
|
||||
/joined_rooms returns only joined rooms
|
||||
3pid invite join valid signature but revoked keys are rejected
|
||||
3pid invite join valid signature but unreachable ID server are rejected
|
||||
|
|
Loading…
Reference in New Issue