diff --git a/crates/delta/src/routes/channels/message_send.rs b/crates/delta/src/routes/channels/message_send.rs index 76cfc40a..9645fffc 100644 --- a/crates/delta/src/routes/channels/message_send.rs +++ b/crates/delta/src/routes/channels/message_send.rs @@ -10,7 +10,6 @@ use revolt_quark::{ use rocket::serde::json::Json; use validator::Validate; -use once_cell::sync::Lazy; /// # Send Message /// diff --git a/crates/delta/src/routes/webhooks/webhook_execute_github.rs b/crates/delta/src/routes/webhooks/webhook_execute_github.rs index a16135c6..ecdf4eaf 100644 --- a/crates/delta/src/routes/webhooks/webhook_execute_github.rs +++ b/crates/delta/src/routes/webhooks/webhook_execute_github.rs @@ -981,7 +981,7 @@ pub async fn req(db: &Db, target: Ref, token: String, event: EventHeader<'_>, da author: webhook.id.clone(), channel: webhook.channel.clone(), embeds: Some(vec![embed]), - webhook: Some(webhook.clone()), + webhook: Some(webhook.clone().into_message_webhook()), ..Default::default() }; diff --git a/crates/quark/src/impl/generic/channels/channel.rs b/crates/quark/src/impl/generic/channels/channel.rs index 00e3ae2c..7cf07f90 100644 --- a/crates/quark/src/impl/generic/channels/channel.rs +++ b/crates/quark/src/impl/generic/channels/channel.rs @@ -441,7 +441,7 @@ impl Channel { masquerade: data.masquerade, interactions: data.interactions.unwrap_or_default(), author: author_id, - webhook, + webhook: webhook.map(|w| w.into_message_webhook()), ..Default::default() }; diff --git a/crates/quark/src/impl/generic/channels/webhook.rs b/crates/quark/src/impl/generic/channels/webhook.rs index acc170b9..71c81015 100644 --- a/crates/quark/src/impl/generic/channels/webhook.rs +++ b/crates/quark/src/impl/generic/channels/webhook.rs @@ -1,7 +1,8 @@ use crate::{ events::client::EventV1, models::{ - webhook::{Webhook, PartialWebhook, FieldsWebhook} + webhook::{Webhook, PartialWebhook, FieldsWebhook}, + message::MessageWebhook }, Database, Result }; @@ -56,9 +57,17 @@ impl Webhook { Ok(()) } - fn remove(&mut self, field: &FieldsWebhook) { + pub fn remove(&mut self, field: &FieldsWebhook) { match field { FieldsWebhook::Avatar => self.avatar = None } } + + pub fn into_message_webhook(self) -> MessageWebhook { + MessageWebhook { + id: self.id, + name: self.name, + avatar: self.avatar.map(|f| f.id) + } + } } diff --git a/crates/quark/src/models/channels/message.rs b/crates/quark/src/models/channels/message.rs index 375bfb91..264868f2 100644 --- a/crates/quark/src/models/channels/message.rs +++ b/crates/quark/src/models/channels/message.rs @@ -1,4 +1,4 @@ -use crate::{models::Webhook, util::regex::RE_COLOUR}; +use crate::util::regex::RE_COLOUR; use indexmap::{IndexMap, IndexSet}; use iso8601_timestamp::Timestamp; @@ -109,6 +109,17 @@ pub struct Interactions { pub restrict_reactions: bool, } +/// Information about the webhook which +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, Validate, Default)] +pub struct MessageWebhook { + // Id of Webhook + pub id: String, + // The name of the webhook - 1 to 32 chars + pub name: String, + // The id of the avatar of the webhook, if it has one + pub avatar: Option +} + /// Representation of a Message on Revolt #[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, OptionalStruct, Default)] #[optional_derive(Serialize, Deserialize, JsonSchema, Debug, Default, Clone)] @@ -126,9 +137,9 @@ pub struct Message { pub channel: String, /// Id of the user or webhook that sent this message pub author: String, - /// Id of the webhook that sent this message, mutually exclusive with `author` + /// The webhook that sent this message, mutually exclusive with `author` #[serde(skip_serializing_if = "Option::is_none")] - pub webhook: Option, + pub webhook: Option, /// Message content #[serde(skip_serializing_if = "Option::is_none")] pub content: Option,