Merge pull request 'Implement /rooms/<room_id>/joined_members' (#143) from joined_members into master

Reviewed-on: https://git.koesters.xyz/timo/conduit/pulls/143
This commit is contained in:
Timo Kösters 2020-07-27 18:22:04 +02:00
commit b82fd02ee3
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