diff --git a/matrixgw_backend/src/controllers/matrix/matrix_event_controller.rs b/matrixgw_backend/src/controllers/matrix/matrix_event_controller.rs index 7befb98..f6ab6e7 100644 --- a/matrixgw_backend/src/controllers/matrix/matrix_event_controller.rs +++ b/matrixgw_backend/src/controllers/matrix/matrix_event_controller.rs @@ -7,6 +7,8 @@ use matrix_sdk::Room; use matrix_sdk::deserialized_responses::{TimelineEvent, TimelineEventKind}; use matrix_sdk::room::MessagesOptions; use matrix_sdk::room::edit::EditedContent; +use matrix_sdk::ruma::events::reaction::ReactionEventContent; +use matrix_sdk::ruma::events::relation::Annotation; use matrix_sdk::ruma::events::room::message::{ RoomMessageEventContent, RoomMessageEventContentWithoutRelation, }; @@ -160,6 +162,28 @@ pub async fn set_text_content( }) } +#[derive(Deserialize)] +struct EventReactionBody { + key: String, +} + +pub async fn react_to_event( + client: MatrixClientExtractor, + path: web::Path, + event_path: web::Path, +) -> HttpResult { + let body = client.auth.decode_json_body::()?; + + let Some(room) = client.client.client.get_room(&path.room_id) else { + return Ok(HttpResponse::NotFound().json("Room not found!")); + }; + + let annotation = Annotation::new(event_path.event_id.to_owned(), body.key.to_owned()); + room.send(ReactionEventContent::from(annotation)).await?; + + Ok(HttpResponse::Accepted().finish()) +} + pub async fn redact_event( client: MatrixClientExtractor, path: web::Path, diff --git a/matrixgw_backend/src/main.rs b/matrixgw_backend/src/main.rs index 6814d0f..f79d018 100644 --- a/matrixgw_backend/src/main.rs +++ b/matrixgw_backend/src/main.rs @@ -177,6 +177,10 @@ async fn main() -> std::io::Result<()> { "/api/matrix/room/{room_id}/event/{event_id}/set_text_content", web::post().to(matrix_event_controller::set_text_content), ) + .route( + "/api/matrix/room/{room_id}/event/{event_id}/react", + web::post().to(matrix_event_controller::react_to_event), + ) .route( "/api/matrix/room/{room_id}/event/{event_id}", web::delete().to(matrix_event_controller::redact_event),