forked from jmug/stoatchat
chore(refactor): validate further up the code
This commit is contained in:
@@ -71,10 +71,6 @@ pub async fn req(
|
||||
new_embeds.clear();
|
||||
|
||||
for embed in embeds {
|
||||
embed
|
||||
.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
new_embeds.push(embed.clone().into_embed(db, message.id.clone()).await?);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,10 +138,6 @@ pub async fn message_send(
|
||||
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?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::collections::HashSet;
|
||||
|
||||
use serde_json::json;
|
||||
use ulid::Ulid;
|
||||
use validator::Validate;
|
||||
|
||||
use crate::{
|
||||
events::client::EventV1,
|
||||
@@ -17,7 +18,7 @@ use crate::{
|
||||
january::{Embed, Text},
|
||||
push::PushNotification,
|
||||
},
|
||||
Database, Result,
|
||||
Database, Error, Result,
|
||||
};
|
||||
|
||||
impl Message {
|
||||
@@ -232,6 +233,9 @@ impl From<SystemMessage> for String {
|
||||
|
||||
impl SendableEmbed {
|
||||
pub async fn into_embed(self, db: &Database, message_id: String) -> Result<Embed> {
|
||||
self.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
let media = if let Some(id) = self.media {
|
||||
Some(
|
||||
db.find_and_use_attachment(&id, "attachments", "message", &message_id)
|
||||
|
||||
Reference in New Issue
Block a user