fix: rewrite attachment deletion logic

This commit is contained in:
Paul Makles
2022-06-20 10:49:09 +01:00
parent ef757aa2fb
commit 7fc4fb2df7
6 changed files with 96 additions and 5 deletions

View File

@@ -135,7 +135,17 @@ impl Message {
/// Delete a message
pub async fn delete(self, db: &Database) -> Result<()> {
let file_ids: Vec<String> = self
.attachments
.map(|files| files.iter().map(|file| file.id.to_string()).collect())
.unwrap_or_default();
if !file_ids.is_empty() {
db.mark_attachments_as_deleted(&file_ids).await?;
}
db.delete_message(&self.id).await?;
EventV1::MessageDelete {
id: self.id,
channel: self.channel.clone(),