feat: implement /event (#144)
Merge branch 'master' into event-route Event: Implement /event Co-authored-by: the0 <theo@localhost> Reviewed-on: https://git.koesters.xyz/timo/conduit/pulls/144 Reviewed-by: Timo Kösters <timo@koesters.xyz>
This commit is contained in:
parent
b03d030b71
commit
469071e105
2 changed files with 31 additions and 1 deletions
|
@ -44,7 +44,7 @@ use ruma::{
|
|||
push::{get_pushers, get_pushrules_all, set_pushrule, set_pushrule_enabled},
|
||||
read_marker::set_read_marker,
|
||||
redact::redact_event,
|
||||
room::{self, create_room},
|
||||
room::{self, create_room, get_room_event},
|
||||
session::{get_login_types, login, logout, logout_all},
|
||||
state::{
|
||||
create_state_event_for_empty_key, create_state_event_for_key, get_state_events,
|
||||
|
@ -2059,6 +2059,35 @@ pub fn get_protocols_route() -> ConduitResult<get_protocols::Response> {
|
|||
.into())
|
||||
}
|
||||
|
||||
#[get(
|
||||
"/_matrix/client/r0/rooms/<_room_id>/event/<_event_id>",
|
||||
data = "<body>"
|
||||
)]
|
||||
pub fn get_room_event_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_room_event::Request>,
|
||||
_room_id: String,
|
||||
_event_id: String,
|
||||
) -> ConduitResult<get_room_event::Response> {
|
||||
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
||||
|
||||
if !db.rooms.is_joined(user_id, &body.room_id)? {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::Forbidden,
|
||||
"You don't have permission to view this room.",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(get_room_event::Response {
|
||||
event: db
|
||||
.rooms
|
||||
.get_pdu(&body.event_id)?
|
||||
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Event not found."))?
|
||||
.to_room_event(),
|
||||
}
|
||||
.into())
|
||||
}
|
||||
|
||||
#[put(
|
||||
"/_matrix/client/r0/rooms/<_room_id>/send/<_event_type>/<_txn_id>",
|
||||
data = "<body>"
|
||||
|
|
|
@ -36,6 +36,7 @@ fn setup_rocket() -> rocket::Rocket {
|
|||
client_server::get_pushrules_all_route,
|
||||
client_server::set_pushrule_route,
|
||||
client_server::set_pushrule_enabled_route,
|
||||
client_server::get_room_event_route,
|
||||
client_server::get_filter_route,
|
||||
client_server::create_filter_route,
|
||||
client_server::set_global_account_data_route,
|
||||
|
|
Loading…
Reference in a new issue