Files
stoatchat/crates/delta/src/routes/channels/message_delete.rs
T
Zomatree 502203d37c feat: Audit Logs (#466)
* fix: squash audit log branch changes

Signed-off-by: Zomatree <me@zomatree.live>

* feat: emoji edit + pronoun

Signed-off-by: Zomatree <me@zomatree.live>

* fix: use tokio instead of async-std

Signed-off-by: Zomatree <me@zomatree.live>

* feat: add slowmode to audit log

Signed-off-by: Zomatree <me@zomatree.live>

* chore: update comments on permissions

Signed-off-by: Zomatree <me@zomatree.live>

---------

Signed-off-by: Zomatree <me@zomatree.live>
2026-07-13 13:39:28 -07:00

57 lines
1.6 KiB
Rust

use revolt_database::{
util::{permissions::DatabasePermissionQuery, reference::Reference},
AuditLogEntryAction, Database, User,
};
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
use revolt_result::Result;
use rocket::State;
use rocket_empty::EmptyResponse;
use crate::util::audit_log_reason::AuditLogReason;
/// # Delete Message
///
/// Delete a message you've sent or one you have permission to delete.
#[openapi(tag = "Messaging")]
#[delete("/<target>/messages/<msg>", rank = 2)]
pub async fn delete(
db: &State<Database>,
user: User,
reason: AuditLogReason,
target: Reference<'_>,
msg: Reference<'_>,
) -> Result<EmptyResponse> {
let message = msg.as_message_in_channel(db, target.id).await?;
let channel = if message.author != user.id {
let channel = target.as_channel(db).await?;
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
calculate_channel_permissions(&mut query)
.await
.throw_if_lacking_channel_permission(ChannelPermission::ManageMessages)?;
Some(channel)
} else {
None
};
message.delete(db).await?;
if let Some(server) = channel.and_then(|c| c.server().map(|s| s.to_string())) {
AuditLogEntryAction::MessageDelete {
author: message.author.clone(),
channel: message.channel.clone(),
}
.insert(
db,
server.to_string(),
reason,
user.id.clone(),
Some(message.author),
)
.await;
};
Ok(EmptyResponse)
}