From fdeee7fdb58414631464dbd211780167895022e1 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 7 Apr 2020 14:43:24 +0200 Subject: [PATCH] More dummy endpoints --- src/main.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index ef4f08a..b9bd352 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,9 +16,9 @@ use ruma_client_api::{ r0::{ account::register, alias::get_alias, - filter::create_filter, + filter::{self, create_filter, get_filter}, keys::get_keys, - membership::join_room_by_id, + membership::{join_room_by_id, join_room_by_id_or_alias}, message::create_message_event, presence::set_presence, push::get_pushrules_all, @@ -30,7 +30,7 @@ use ruma_client_api::{ unversioned::get_supported_versions, }; use ruma_events::EventType; -use ruma_identifiers::{RoomId, UserId}; +use ruma_identifiers::{RoomId, RoomIdOrAliasId, UserId}; use ruma_wrapper::{MatrixResult, Ruma}; use serde_json::json; use std::{collections::HashMap, convert::TryInto, path::PathBuf}; @@ -214,6 +214,27 @@ fn get_pushrules_all_route() -> MatrixResult { })) } +#[get( + "/_matrix/client/r0/user/<_user_id>/filter/<_filter_id>", + data = "" +)] +fn get_filter_route( + body: Ruma, + _user_id: String, + _filter_id: String, +) -> MatrixResult { + // TODO + MatrixResult(Ok(get_filter::Response { + filter: filter::FilterDefinition { + event_fields: None, + event_format: None, + account_data: None, + room: None, + presence: None, + }, + })) +} + #[post("/_matrix/client/r0/user/<_user_id>/filter", data = "")] fn create_filter_route( body: Ruma, @@ -305,6 +326,37 @@ fn join_room_by_id_route( })) } +#[post("/_matrix/client/r0/join/<_room_id_or_alias>", data = "")] +fn join_room_by_id_or_alias_route( + data: State, + body: Ruma, + _room_id_or_alias: String, +) -> MatrixResult { + let room_id = match &body.room_id_or_alias { + RoomIdOrAliasId::RoomAliasId(alias) => match alias.alias() { + "#room:localhost" => "!xclkjvdlfj:localhost".try_into().unwrap(), + _ => { + debug!("Room not found."); + return MatrixResult(Err(Error { + kind: ErrorKind::NotFound, + message: "Room not found.".to_owned(), + status_code: http::StatusCode::NOT_FOUND, + })); + } + }, + + RoomIdOrAliasId::RoomId(id) => id.clone(), + }; + + data.room_join( + &room_id, + body.user_id.as_ref().expect("user is authenticated"), + ); + MatrixResult(Ok(join_room_by_id_or_alias::Response { + room_id: room_id.clone(), + })) +} + #[put( "/_matrix/client/r0/rooms/<_room_id>/send/<_event_type>/<_txn_id>", data = "" @@ -449,12 +501,14 @@ fn main() { get_login_route, login_route, get_pushrules_all_route, + get_filter_route, create_filter_route, set_presence_route, get_keys_route, create_room_route, get_alias_route, join_room_by_id_route, + join_room_by_id_or_alias_route, create_message_event_route, create_state_event_for_key_route, create_state_event_for_empty_key_route,