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>
This commit is contained in:
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},
membership::{
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},
presence::set_presence,
@ -1439,6 +1439,23 @@ pub fn create_room_route(
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(
"/_matrix/client/r0/rooms/<_room_id>/redact/<_event_id>/<_txn_id>",
data = "<body>"

View File

@ -66,6 +66,7 @@ fn setup_rocket() -> rocket::Rocket {
client_server::join_room_by_id_or_alias_route,
client_server::leave_room_route,
client_server::forget_room_route,
client_server::joined_rooms_route,
client_server::kick_user_route,
client_server::ban_user_route,
client_server::unban_user_route,

View File

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

View File

@ -29,6 +29,8 @@ GET /publicRooms lists newly-created room
GET /register yields a set of flows
GET /rooms/:room_id/state fetches entire room state
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
POST /createRoom makes a private room
POST /createRoom makes a private room with invites