From 0abc12e5fa2a15ec5d9cd9d5526493e552698580 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Wed, 8 Jun 2022 14:12:11 +0100 Subject: [PATCH] chore(refactor): process attachments last --- Cargo.lock | 2 +- crates/delta/Cargo.toml | 2 +- .../delta/src/routes/channels/message_send.rs | 34 +++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a844a755..8996ad3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2730,7 +2730,7 @@ dependencies = [ [[package]] name = "revolt-delta" -version = "0.5.3-6" +version = "0.5.3-7" dependencies = [ "async-channel", "async-std", diff --git a/crates/delta/Cargo.toml b/crates/delta/Cargo.toml index 32f8d586..478674ec 100644 --- a/crates/delta/Cargo.toml +++ b/crates/delta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "revolt-delta" -version = "0.5.3-6" +version = "0.5.3-7" license = "AGPL-3.0-or-later" authors = ["Paul Makles "] edition = "2018" diff --git a/crates/delta/src/routes/channels/message_send.rs b/crates/delta/src/routes/channels/message_send.rs index 73cc4f56..a5be09e6 100644 --- a/crates/delta/src/routes/channels/message_send.rs +++ b/crates/delta/src/routes/channels/message_send.rs @@ -134,7 +134,23 @@ pub async fn message_send( .replace(replies.into_iter().collect::>()); } - // 4. Add attachments to message. + // 4. Process included embeds. + let mut embeds = vec![]; + if let Some(sendable_embeds) = data.embeds { + for sendable_embed in sendable_embeds { + sendable_embed + .validate() + .map_err(|error| Error::FailedValidation { error })?; + + embeds.push(sendable_embed.into_embed(db, message_id.clone()).await?) + } + } + + if !embeds.is_empty() { + message.embeds.replace(embeds); + } + + // 5. Add attachments to message. let mut attachments = vec![]; if let Some(ids) = &data.attachments { if !ids.is_empty() { @@ -160,22 +176,6 @@ pub async fn message_send( message.attachments.replace(attachments); } - // 5. Process included embeds. - let mut embeds = vec![]; - if let Some(sendable_embeds) = data.embeds { - for sendable_embed in sendable_embeds { - sendable_embed - .validate() - .map_err(|error| Error::FailedValidation { error })?; - - embeds.push(sendable_embed.into_embed(db, message_id.clone()).await?) - } - } - - if !embeds.is_empty() { - message.embeds.replace(embeds); - } - // 6. Set content message.content = data.content;