mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 21:47:02 +00:00
28 lines
743 B
Rust
28 lines
743 B
Rust
use crate::database::*;
|
|
use crate::util::result::{Error, Result};
|
|
|
|
use mongodb::bson::doc;
|
|
|
|
#[delete("/<target>/messages/<msg>")]
|
|
pub async fn req(user: User, target: Ref, msg: Ref) -> Result<()> {
|
|
let channel = target.fetch_channel().await?;
|
|
|
|
let perm = permissions::PermissionCalculator::new(&user)
|
|
.with_channel(&channel)
|
|
.for_channel()
|
|
.await?;
|
|
if !perm.get_view() {
|
|
Err(Error::LabelMe)?
|
|
}
|
|
|
|
let message = msg.fetch_message(&channel).await?;
|
|
if message.author != user.id && !perm.get_manage_messages() {
|
|
match channel {
|
|
Channel::SavedMessages { .. } => unreachable!(),
|
|
_ => Err(Error::CannotEditMessage)?,
|
|
}
|
|
}
|
|
|
|
message.delete().await
|
|
}
|