Implement get_joined_rooms (#155)

whitelist /joined_rooms in sytest

Signed-off-by: Aurabindo Pillai <mail@aurabindo.in>

style: fmt

feat: implement /joined_rooms (#78)

Signed-off-by: Aurabindo Pillai <mail@aurabindo.in>

Co-authored-by: Aurabindo Pillai <mail@aurabindo.in>
Co-authored-by: timokoesters <timo@koesters.xyz>
Reviewed-on: https://git.koesters.xyz/timo/conduit/pulls/155
Reviewed-by: Timo Kösters <timo@koesters.xyz>
next
aura 2020-07-25 18:35:22 +02:00 committed by Timo Kösters
parent be43b9557e
commit 630196f0a3
4 changed files with 24 additions and 5 deletions

View File

@ -34,7 +34,7 @@ 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, kick_user, leave_room, unban_user, join_room_by_id_or_alias, 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,
@ -1439,6 +1439,23 @@ pub fn create_room_route(
Ok(create_room::Response { room_id }.into()) Ok(create_room::Response { room_id }.into())
} }
#[get("/_matrix/client/r0/joined_rooms", data = "<body>")]
pub fn joined_rooms_route(
db: State<'_, Database>,
body: Ruma<joined_rooms::Request>,
) -> ConduitResult<joined_rooms::Response> {
let user_id = body.user_id.as_ref().expect("user is authenticated");
Ok(joined_rooms::Response {
joined_rooms: db
.rooms
.rooms_joined(&user_id)
.filter_map(|r| r.ok())
.collect(),
}
.into())
}
#[put( #[put(
"/_matrix/client/r0/rooms/<_room_id>/redact/<_event_id>/<_txn_id>", "/_matrix/client/r0/rooms/<_room_id>/redact/<_event_id>/<_txn_id>",
data = "<body>" data = "<body>"

View File

@ -66,6 +66,7 @@ fn setup_rocket() -> rocket::Rocket {
client_server::join_room_by_id_or_alias_route, client_server::join_room_by_id_or_alias_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::kick_user_route, client_server::kick_user_route,
client_server::ban_user_route, client_server::ban_user_route,
client_server::unban_user_route, client_server::unban_user_route,

View File

@ -1,7 +1,7 @@
use crate::{utils, Error}; use crate::{utils, Error};
use log::warn; use log::warn;
use rocket::{ use rocket::{
data::{Data, FromDataFuture, Transform, TransformFuture, Transformed, FromTransformedData}, data::{Data, FromDataFuture, FromTransformedData, Transform, TransformFuture, Transformed},
http::Status, http::Status,
response::{self, Responder}, response::{self, Responder},
Outcome::*, Outcome::*,
@ -125,7 +125,7 @@ impl<'r, 'o, T> Responder<'r, 'o> for RumaResponse<T>
where where
T: Send + TryInto<http::Response<Vec<u8>>>, T: Send + TryInto<http::Response<Vec<u8>>>,
T::Error: Send, T::Error: Send,
'o: 'r 'o: 'r,
{ {
fn respond_to(self, _: &'r Request<'_>) -> response::Result<'o> { fn respond_to(self, _: &'r Request<'_>) -> response::Result<'o> {
let http_response: Result<http::Response<_>, _> = self.0.try_into(); let http_response: Result<http::Response<_>, _> = self.0.try_into();
@ -143,8 +143,7 @@ where
let http_body = http_response.into_body(); let http_body = http_response.into_body();
response response.sized_body(http_body.len(), Cursor::new(http_body));
.sized_body(http_body.len(), Cursor::new(http_body));
response.raw_header("Access-Control-Allow-Origin", "*"); response.raw_header("Access-Control-Allow-Origin", "*");
response.raw_header( response.raw_header(

View File

@ -29,6 +29,8 @@ GET /publicRooms lists newly-created room
GET /register yields a set of flows GET /register yields a set of flows
GET /rooms/:room_id/state fetches entire room state GET /rooms/:room_id/state fetches entire room state
GET /rooms/:room_id/state/m.room.member/:user_id fetches my membership GET /rooms/:room_id/state/m.room.member/:user_id fetches my membership
GET /joined_rooms lists newly-created room
/joined_rooms returns only joined rooms
Getting push rules doesn't corrupt the cache SYN-390 Getting push rules doesn't corrupt the cache SYN-390
POST /createRoom makes a private room POST /createRoom makes a private room
POST /createRoom makes a private room with invites POST /createRoom makes a private room with invites