Can react to event
This commit is contained in:
@@ -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<RoomIdInPath>,
|
||||
event_path: web::Path<EventIdInPath>,
|
||||
) -> HttpResult {
|
||||
let body = client.auth.decode_json_body::<EventReactionBody>()?;
|
||||
|
||||
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<RoomIdInPath>,
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user