chore(refactor): process attachments last

This commit is contained in:
Paul Makles
2022-06-08 14:12:11 +01:00
parent aaceb5bdee
commit 0abc12e5fa
3 changed files with 19 additions and 19 deletions

2
Cargo.lock generated
View File

@@ -2730,7 +2730,7 @@ dependencies = [
[[package]]
name = "revolt-delta"
version = "0.5.3-6"
version = "0.5.3-7"
dependencies = [
"async-channel",
"async-std",

View File

@@ -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 <paulmakles@gmail.com>"]
edition = "2018"

View File

@@ -134,7 +134,23 @@ pub async fn message_send(
.replace(replies.into_iter().collect::<Vec<String>>());
}
// 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;