Can redact message
This commit is contained in:
@@ -83,7 +83,7 @@ pub async fn get_for_room(
|
||||
path: web::Path<RoomIdInPath>,
|
||||
query: web::Query<GetRoomEventsQuery>,
|
||||
) -> HttpResult {
|
||||
let Some(room) = client.client.client.get_room(&path.id) else {
|
||||
let Some(room) = client.client.client.get_room(&path.room_id) else {
|
||||
return Ok(HttpResponse::NotFound().json("Room not found!"));
|
||||
};
|
||||
|
||||
@@ -102,7 +102,7 @@ pub async fn send_text_message(
|
||||
) -> HttpResult {
|
||||
let req = client.auth.decode_json_body::<SendTextMessageRequest>()?;
|
||||
|
||||
let Some(room) = client.client.client.get_room(&path.id) else {
|
||||
let Some(room) = client.client.client.get_room(&path.room_id) else {
|
||||
return Ok(HttpResponse::NotFound().json("Room not found!"));
|
||||
};
|
||||
|
||||
@@ -111,3 +111,27 @@ pub async fn send_text_message(
|
||||
|
||||
Ok(HttpResponse::Accepted().finish())
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct EventIdInPath {
|
||||
pub(crate) event_id: OwnedEventId,
|
||||
}
|
||||
|
||||
pub async fn redact_event(
|
||||
client: MatrixClientExtractor,
|
||||
path: web::Path<RoomIdInPath>,
|
||||
event_path: web::Path<EventIdInPath>,
|
||||
) -> HttpResult {
|
||||
let Some(room) = client.client.client.get_room(&path.room_id) else {
|
||||
return Ok(HttpResponse::NotFound().json("Room not found!"));
|
||||
};
|
||||
|
||||
Ok(match room.redact(&event_path.event_id, None, None).await {
|
||||
Ok(_) => HttpResponse::Accepted().finish(),
|
||||
|
||||
Err(e) => {
|
||||
log::error!("Failed to redact event {}: {e}", event_path.event_id);
|
||||
HttpResponse::InternalServerError().json(format!("Failed to redact event! {e}"))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ pub async fn get_joined_spaces(client: MatrixClientExtractor) -> HttpResult {
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct RoomIdInPath {
|
||||
pub(crate) id: OwnedRoomId,
|
||||
pub(crate) room_id: OwnedRoomId,
|
||||
}
|
||||
|
||||
/// Get the list of joined rooms of the user
|
||||
@@ -91,7 +91,7 @@ pub async fn single_room_info(
|
||||
client: MatrixClientExtractor,
|
||||
path: web::Path<RoomIdInPath>,
|
||||
) -> HttpResult {
|
||||
Ok(match client.client.client.get_room(&path.id) {
|
||||
Ok(match client.client.client.get_room(&path.room_id) {
|
||||
None => HttpResponse::NotFound().json("Room not found"),
|
||||
Some(r) => HttpResponse::Ok().json(APIRoomInfo::from_room(&r).await?),
|
||||
})
|
||||
@@ -103,7 +103,7 @@ pub async fn room_avatar(
|
||||
client: MatrixClientExtractor,
|
||||
path: web::Path<RoomIdInPath>,
|
||||
) -> HttpResult {
|
||||
let Some(room) = client.client.client.get_room(&path.id) else {
|
||||
let Some(room) = client.client.client.get_room(&path.room_id) else {
|
||||
return Ok(HttpResponse::NotFound().json("Room not found"));
|
||||
};
|
||||
|
||||
|
||||
@@ -148,11 +148,11 @@ async fn main() -> std::io::Result<()> {
|
||||
web::get().to(matrix_room_controller::get_joined_spaces),
|
||||
)
|
||||
.route(
|
||||
"/api/matrix/room/{id}",
|
||||
"/api/matrix/room/{room_id}",
|
||||
web::get().to(matrix_room_controller::single_room_info),
|
||||
)
|
||||
.route(
|
||||
"/api/matrix/room/{id}/avatar",
|
||||
"/api/matrix/room/{room_id}/avatar",
|
||||
web::get().to(matrix_room_controller::room_avatar),
|
||||
)
|
||||
// Matrix profile controller
|
||||
@@ -166,13 +166,17 @@ async fn main() -> std::io::Result<()> {
|
||||
)
|
||||
// Matrix events controller
|
||||
.route(
|
||||
"/api/matrix/room/{id}/events",
|
||||
"/api/matrix/room/{room_id}/events",
|
||||
web::get().to(matrix_event_controller::get_for_room),
|
||||
)
|
||||
.route(
|
||||
"/api/matrix/room/{id}/send_text_message",
|
||||
"/api/matrix/room/{room_id}/send_text_message",
|
||||
web::post().to(matrix_event_controller::send_text_message),
|
||||
)
|
||||
.route(
|
||||
"/api/matrix/room/{room_id}/event/{event_id}",
|
||||
web::delete().to(matrix_event_controller::redact_event),
|
||||
)
|
||||
// Matrix media controller
|
||||
.route(
|
||||
"/api/matrix/media/{mxc}",
|
||||
|
||||
Reference in New Issue
Block a user