forked from jmug/stoatchat
feat: Add webhook endpoints for editing and deleting messages (#682)
* feat: ErrorType.CannotDeleteMessage, needed later Signed-off-by: Taureon <taureon@noreply.codeberg.org> * feat: webhook edit/delete message endpoints Signed-off-by: Taureon <taureon@noreply.codeberg.org> * lol, lmao even Signed-off-by: Taureon <taureon@noreply.codeberg.org> * fix contradictory comment Signed-off-by: Taureon <taureon@noreply.codeberg.org> --------- Signed-off-by: Taureon <taureon@noreply.codeberg.org> Co-authored-by: Taureon <taureon@noreply.codeberg.org>
This commit is contained in:
27
crates/delta/src/routes/webhooks/webhook_delete_message.rs
Normal file
27
crates/delta/src/routes/webhooks/webhook_delete_message.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use revolt_database::{util::reference::Reference, Database};
|
||||
use revolt_result::{create_error, Result};
|
||||
use rocket::State;
|
||||
use rocket_empty::EmptyResponse;
|
||||
|
||||
/// # Deletes a webhook message
|
||||
///
|
||||
/// Deletes a message sent by a webhook
|
||||
#[openapi(tag = "Webhooks")]
|
||||
#[delete("/<webhook_id>/<token>/<message_id>")]
|
||||
pub async fn webhook_delete_message(
|
||||
db: &State<Database>,
|
||||
webhook_id: Reference<'_>,
|
||||
token: String,
|
||||
message_id: Reference<'_>,
|
||||
) -> Result<EmptyResponse> {
|
||||
let webhook = webhook_id.as_webhook(db).await?;
|
||||
webhook.assert_token(&token)?;
|
||||
|
||||
let message = message_id.as_message(db).await?;
|
||||
|
||||
if message.author != webhook.id {
|
||||
return Err(create_error!(CannotDeleteMessage));
|
||||
}
|
||||
|
||||
message.delete(db).await.map(|_| EmptyResponse)
|
||||
}
|
||||
Reference in New Issue
Block a user