forked from jmug/stoatchat
refactor(quark): strip webhook code
This commit is contained in:
@@ -28,7 +28,7 @@ default = [ "test" ]
|
|||||||
# Serialisation
|
# Serialisation
|
||||||
revolt_optional_struct = "0.2.0"
|
revolt_optional_struct = "0.2.0"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
validator = { version = "0.14", features = ["derive"] }
|
validator = { version = "0.16", features = ["derive"] }
|
||||||
iso8601-timestamp = { version = "0.1.8", features = ["schema", "bson"] }
|
iso8601-timestamp = { version = "0.1.8", features = ["schema", "bson"] }
|
||||||
|
|
||||||
# Formats
|
# Formats
|
||||||
@@ -93,3 +93,4 @@ sentry = "0.25.0"
|
|||||||
# Core
|
# Core
|
||||||
revolt-result = { path = "../core/result", features = [ "serde", "schemas" ] }
|
revolt-result = { path = "../core/result", features = [ "serde", "schemas" ] }
|
||||||
revolt-presence = { path = "../core/presence", features = [ "redis-is-patched" ] }
|
revolt-presence = { path = "../core/presence", features = [ "redis-is-patched" ] }
|
||||||
|
revolt-models = { path = "../core/models" }
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
use authifier::AuthifierEvent;
|
use authifier::AuthifierEvent;
|
||||||
|
use revolt_models::v0::{FieldsWebhook, PartialWebhook, Webhook};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::models::channel::{FieldsChannel, PartialChannel};
|
use crate::models::channel::{FieldsChannel, PartialChannel};
|
||||||
use crate::models::webhook::{PartialWebhook, FieldsWebhook};
|
|
||||||
use crate::models::message::{AppendMessage, PartialMessage};
|
use crate::models::message::{AppendMessage, PartialMessage};
|
||||||
use crate::models::server::{FieldsRole, FieldsServer, PartialRole, PartialServer};
|
use crate::models::server::{FieldsRole, FieldsServer, PartialRole, PartialServer};
|
||||||
use crate::models::server_member::{FieldsMember, MemberCompositeKey, PartialMember};
|
use crate::models::server_member::{FieldsMember, MemberCompositeKey, PartialMember};
|
||||||
use crate::models::user::{FieldsUser, PartialUser, RelationshipStatus};
|
use crate::models::user::{FieldsUser, PartialUser, RelationshipStatus};
|
||||||
use crate::models::{Channel, Emoji, Member, Message, Server, User, UserSettings, Webhook, Report};
|
use crate::models::{Channel, Emoji, Member, Message, Report, Server, User, UserSettings};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
/// WebSocket Client Errors
|
/// WebSocket Client Errors
|
||||||
@@ -222,13 +222,11 @@ pub enum EventV1 {
|
|||||||
WebhookUpdate {
|
WebhookUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
data: PartialWebhook,
|
data: PartialWebhook,
|
||||||
remove: Vec<FieldsWebhook>
|
remove: Vec<FieldsWebhook>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Delete webhook
|
/// Delete webhook
|
||||||
WebhookDelete {
|
WebhookDelete { id: String },
|
||||||
id: String
|
|
||||||
},
|
|
||||||
|
|
||||||
/// New report
|
/// New report
|
||||||
ReportCreate(Report),
|
ReportCreate(Report),
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
use crate::models::webhook::{Webhook, FieldsWebhook, PartialWebhook};
|
|
||||||
use crate::{AbstractWebhook, Result};
|
|
||||||
|
|
||||||
use super::super::DummyDb;
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl AbstractWebhook for DummyDb {
|
|
||||||
async fn insert_webhook(&self, webhook: &Webhook) -> Result<()> {
|
|
||||||
info!("Created webhook {} in {}", webhook.name, webhook.channel);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_webhook(&self, webhook_id: &str) -> Result<()> {
|
|
||||||
info!("deleting webhook {webhook_id}");
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fetch_webhook(&self, webhook_id: &str) -> Result<Webhook> {
|
|
||||||
Ok(Webhook {
|
|
||||||
id: webhook_id.to_string(),
|
|
||||||
name: "".to_string(),
|
|
||||||
avatar: None,
|
|
||||||
channel: "0".to_string(),
|
|
||||||
token: Some("".to_owned()),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn update_webhook(&self, webhook_id: &str, partial_webhook: &PartialWebhook, remove: &[FieldsWebhook]) -> Result<()> {
|
|
||||||
info!("updating webhook {webhook_id}, {partial_webhook:?}, removing {remove:?}");
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fetch_webhooks_for_channel(&self, channel: &str) -> Result<Vec<Webhook>> {
|
|
||||||
info!("fetching webhooks for channel {channel}");
|
|
||||||
|
|
||||||
Ok(vec![self.fetch_webhook("0").await?])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,7 +14,6 @@ pub mod channels {
|
|||||||
pub mod channel_invite;
|
pub mod channel_invite;
|
||||||
pub mod channel_unread;
|
pub mod channel_unread;
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub mod webhook;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod servers {
|
pub mod servers {
|
||||||
|
|||||||
@@ -6,11 +6,14 @@ use crate::{
|
|||||||
events::client::EventV1,
|
events::client::EventV1,
|
||||||
models::{
|
models::{
|
||||||
channel::{FieldsChannel, PartialChannel},
|
channel::{FieldsChannel, PartialChannel},
|
||||||
message::{SystemMessage, Message, DataMessageSend, Reply, RE_MENTION},
|
message::{DataMessageSend, Message, Reply, SystemMessage, RE_MENTION},
|
||||||
Channel,
|
Channel,
|
||||||
},
|
},
|
||||||
tasks::{ack::AckEvent, process_embeds},
|
tasks::{ack::AckEvent, process_embeds},
|
||||||
Database, Error, OverrideField, Result, types::push::MessageAuthor, web::idempotency::IdempotencyKey, Ref, variables::delta::{MAX_ATTACHMENT_COUNT, MAX_REPLY_COUNT},
|
types::push::MessageAuthor,
|
||||||
|
variables::delta::{MAX_ATTACHMENT_COUNT, MAX_REPLY_COUNT},
|
||||||
|
web::idempotency::IdempotencyKey,
|
||||||
|
Database, Error, OverrideField, Ref, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Channel {
|
impl Channel {
|
||||||
@@ -400,7 +403,13 @@ impl Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a message in a channel
|
/// Creates a message in a channel
|
||||||
pub async fn send_message(&self, db: &Database, data: DataMessageSend, author: MessageAuthor<'_>, mut idempotency: IdempotencyKey) -> Result<Message> {
|
pub async fn send_message(
|
||||||
|
&self,
|
||||||
|
db: &Database,
|
||||||
|
data: DataMessageSend,
|
||||||
|
author: MessageAuthor<'_>,
|
||||||
|
mut idempotency: IdempotencyKey,
|
||||||
|
) -> Result<Message> {
|
||||||
Message::validate_sum(&data.content, &data.embeds)?;
|
Message::validate_sum(&data.content, &data.embeds)?;
|
||||||
|
|
||||||
idempotency.consume_nonce(data.nonce).await?;
|
idempotency.consume_nonce(data.nonce).await?;
|
||||||
@@ -430,7 +439,7 @@ impl Channel {
|
|||||||
|
|
||||||
let (author_id, webhook) = match &author {
|
let (author_id, webhook) = match &author {
|
||||||
MessageAuthor::User(user) => (user.id.clone(), None),
|
MessageAuthor::User(user) => (user.id.clone(), None),
|
||||||
MessageAuthor::Webhook(webhook) => (webhook.id.clone(), Some((*webhook).clone()))
|
MessageAuthor::Webhook(webhook) => (webhook.id.clone(), Some((*webhook).clone())),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start constructing the message
|
// Start constructing the message
|
||||||
@@ -441,7 +450,7 @@ impl Channel {
|
|||||||
masquerade: data.masquerade,
|
masquerade: data.masquerade,
|
||||||
interactions: data.interactions.unwrap_or_default(),
|
interactions: data.interactions.unwrap_or_default(),
|
||||||
author: author_id,
|
author: author_id,
|
||||||
webhook: webhook.map(|w| w.into_message_webhook()),
|
webhook: webhook.map(|w| w.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -459,7 +468,9 @@ impl Channel {
|
|||||||
let mut replies = HashSet::new();
|
let mut replies = HashSet::new();
|
||||||
if let Some(entries) = data.replies {
|
if let Some(entries) = data.replies {
|
||||||
if entries.len() > *MAX_REPLY_COUNT {
|
if entries.len() > *MAX_REPLY_COUNT {
|
||||||
return Err(Error::TooManyReplies { max: *MAX_REPLY_COUNT });
|
return Err(Error::TooManyReplies {
|
||||||
|
max: *MAX_REPLY_COUNT,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for Reply { id, mention } in entries {
|
for Reply { id, mention } in entries {
|
||||||
@@ -499,13 +510,20 @@ impl Channel {
|
|||||||
let mut attachments = vec![];
|
let mut attachments = vec![];
|
||||||
if let Some(ids) = &data.attachments {
|
if let Some(ids) = &data.attachments {
|
||||||
if ids.len() > *MAX_ATTACHMENT_COUNT {
|
if ids.len() > *MAX_ATTACHMENT_COUNT {
|
||||||
return Err(Error::TooManyAttachments { max: *MAX_ATTACHMENT_COUNT} );
|
return Err(Error::TooManyAttachments {
|
||||||
|
max: *MAX_ATTACHMENT_COUNT,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for attachment_id in ids {
|
for attachment_id in ids {
|
||||||
attachments.push(
|
attachments.push(
|
||||||
db.find_and_use_attachment(attachment_id, "attachments", "message", &message_id)
|
db.find_and_use_attachment(
|
||||||
.await?,
|
attachment_id,
|
||||||
|
"attachments",
|
||||||
|
"message",
|
||||||
|
&message_id,
|
||||||
|
)
|
||||||
|
.await?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
use crate::{
|
|
||||||
events::client::EventV1,
|
|
||||||
models::{
|
|
||||||
webhook::{Webhook, PartialWebhook, FieldsWebhook},
|
|
||||||
message::MessageWebhook
|
|
||||||
},
|
|
||||||
Database, Result
|
|
||||||
};
|
|
||||||
|
|
||||||
impl Webhook {
|
|
||||||
pub async fn create(&self, db: &Database) -> Result<()> {
|
|
||||||
db.insert_webhook(self).await?;
|
|
||||||
|
|
||||||
// Avoid leaking the token to people who receive the event
|
|
||||||
let mut webhook = self.clone();
|
|
||||||
webhook.token = None;
|
|
||||||
|
|
||||||
EventV1::WebhookCreate(webhook)
|
|
||||||
.p(self.channel.clone()).await;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(&self, db: &Database) -> Result<()> {
|
|
||||||
db.delete_webhook(&self.id).await?;
|
|
||||||
|
|
||||||
EventV1::WebhookDelete { id: self.id.clone() }
|
|
||||||
.p(self.channel.clone()).await;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(
|
|
||||||
&mut self,
|
|
||||||
db: &Database,
|
|
||||||
mut partial: PartialWebhook,
|
|
||||||
remove: Vec<FieldsWebhook>
|
|
||||||
) -> Result<()> {
|
|
||||||
for field in &remove {
|
|
||||||
self.remove(field)
|
|
||||||
};
|
|
||||||
|
|
||||||
self.apply_options(partial.clone());
|
|
||||||
|
|
||||||
db.update_webhook(&self.id, &partial, &remove).await?;
|
|
||||||
|
|
||||||
partial.token = None; // Avoid leaking the token to people who receive the event
|
|
||||||
|
|
||||||
EventV1::WebhookUpdate {
|
|
||||||
id: self.id.clone(),
|
|
||||||
data: partial,
|
|
||||||
remove
|
|
||||||
}
|
|
||||||
.p(self.channel.clone())
|
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn remove(&mut self, field: &FieldsWebhook) {
|
|
||||||
match field {
|
|
||||||
FieldsWebhook::Avatar => self.avatar = None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn into_message_webhook(self) -> MessageWebhook {
|
|
||||||
MessageWebhook {
|
|
||||||
name: self.name,
|
|
||||||
avatar: self.avatar.map(|f| f.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,6 @@ pub mod channels {
|
|||||||
pub mod channel_invite;
|
pub mod channel_invite;
|
||||||
pub mod channel_unread;
|
pub mod channel_unread;
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub mod webhook;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod servers {
|
pub mod servers {
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
use crate::models::{webhook::{Webhook, PartialWebhook, FieldsWebhook}};
|
|
||||||
use crate::r#impl::mongo::IntoDocumentPath;
|
|
||||||
use crate::{Result, AbstractWebhook};
|
|
||||||
|
|
||||||
use super::super::MongoDb;
|
|
||||||
|
|
||||||
static COL: &str = "webhooks";
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl AbstractWebhook for MongoDb {
|
|
||||||
async fn insert_webhook(&self, webhook: &Webhook) -> Result<()> {
|
|
||||||
self.insert_one(COL, webhook).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fetch_webhook(&self, webhook_id: &str) -> Result<Webhook> {
|
|
||||||
info!("{COL} {webhook_id}");
|
|
||||||
|
|
||||||
self.find_one_by_id(COL, webhook_id).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_webhook(&self, webhook_id: &str) -> Result<()> {
|
|
||||||
self.delete_one_by_id(COL, webhook_id).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn update_webhook(&self, webhook_id: &str, partial_webhook: &PartialWebhook, remove: &[FieldsWebhook]) -> Result<()> {
|
|
||||||
self.update_one_by_id(
|
|
||||||
COL,
|
|
||||||
webhook_id,
|
|
||||||
partial_webhook,
|
|
||||||
remove.iter().map(|x| x as &dyn IntoDocumentPath).collect(),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.map(|_| ())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fetch_webhooks_for_channel(&self, channel: &str) -> Result<Vec<Webhook>> {
|
|
||||||
self.find(
|
|
||||||
COL,
|
|
||||||
doc! {
|
|
||||||
"channel": channel
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDocumentPath for FieldsWebhook {
|
|
||||||
fn as_path(&self) -> Option<&'static str> {
|
|
||||||
match self {
|
|
||||||
FieldsWebhook::Avatar => Some("avatar"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,6 @@ pub mod channels {
|
|||||||
pub mod channel_invite;
|
pub mod channel_invite;
|
||||||
pub mod channel_unread;
|
pub mod channel_unread;
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub mod webhook;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod servers {
|
pub mod servers {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use indexmap::{IndexMap, IndexSet};
|
|||||||
use iso8601_timestamp::Timestamp;
|
use iso8601_timestamp::Timestamp;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use revolt_models::v0::MessageWebhook;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
@@ -109,15 +110,6 @@ pub struct Interactions {
|
|||||||
pub restrict_reactions: bool,
|
pub restrict_reactions: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information about the webhook which
|
|
||||||
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, Validate, Default)]
|
|
||||||
pub struct MessageWebhook {
|
|
||||||
// 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<String>
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Representation of a Message on Revolt
|
/// Representation of a Message on Revolt
|
||||||
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, OptionalStruct, Default)]
|
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, OptionalStruct, Default)]
|
||||||
#[optional_derive(Serialize, Deserialize, JsonSchema, Debug, Default, Clone)]
|
#[optional_derive(Serialize, Deserialize, JsonSchema, Debug, Default, Clone)]
|
||||||
@@ -135,7 +127,7 @@ pub struct Message {
|
|||||||
pub channel: String,
|
pub channel: String,
|
||||||
/// Id of the user or webhook that sent this message
|
/// Id of the user or webhook that sent this message
|
||||||
pub author: String,
|
pub author: String,
|
||||||
/// The webhook that sent this message, mutually exclusive with `author`
|
/// The webhook that sent this message
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub webhook: Option<MessageWebhook>,
|
pub webhook: Option<MessageWebhook>,
|
||||||
/// Message content
|
/// Message content
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
use crate::models::File;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
/// Respresents a webhook
|
|
||||||
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, OptionalStruct)]
|
|
||||||
#[optional_derive(Serialize, Deserialize, JsonSchema, Debug, Default, Clone)]
|
|
||||||
#[optional_name = "PartialWebhook"]
|
|
||||||
#[opt_skip_serializing_none]
|
|
||||||
#[opt_some_priority]
|
|
||||||
|
|
||||||
pub struct Webhook {
|
|
||||||
/// Unique Id
|
|
||||||
#[serde(rename = "_id")]
|
|
||||||
pub id: String,
|
|
||||||
|
|
||||||
/// The name of the webhook
|
|
||||||
pub name: String,
|
|
||||||
|
|
||||||
/// The avatar of the webhook
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub avatar: Option<File>,
|
|
||||||
|
|
||||||
/// The channel this webhook belongs to
|
|
||||||
pub channel: String,
|
|
||||||
|
|
||||||
/// The private token for the webhook
|
|
||||||
pub token: Option<String>
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)]
|
|
||||||
pub enum FieldsWebhook {
|
|
||||||
Avatar
|
|
||||||
}
|
|
||||||
@@ -13,7 +13,6 @@ mod channels {
|
|||||||
pub mod channel_invite;
|
pub mod channel_invite;
|
||||||
pub mod channel_unread;
|
pub mod channel_unread;
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub mod webhook;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod servers {
|
mod servers {
|
||||||
@@ -55,4 +54,3 @@ pub use simple::SimpleModel;
|
|||||||
pub use snapshot::Snapshot;
|
pub use snapshot::Snapshot;
|
||||||
pub use user::User;
|
pub use user::User;
|
||||||
pub use user_settings::UserSettings;
|
pub use user_settings::UserSettings;
|
||||||
pub use webhook::Webhook;
|
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
use crate::models::webhook::{Webhook, PartialWebhook, FieldsWebhook};
|
|
||||||
use crate::Result;
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
pub trait AbstractWebhook: Sync + Send {
|
|
||||||
async fn insert_webhook(&self, webhook: &Webhook) -> Result<()>;
|
|
||||||
async fn fetch_webhook(&self, webhook_id: &str) -> Result<Webhook>;
|
|
||||||
async fn delete_webhook(&self, webhook_id: &str) -> Result<()>;
|
|
||||||
async fn update_webhook(&self, webhook_id: &str, partial_webhook: &PartialWebhook, remove: &[FieldsWebhook]) -> Result<()>;
|
|
||||||
async fn fetch_webhooks_for_channel(&self, channel: &str) -> Result<Vec<Webhook>>;
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,6 @@ mod channels {
|
|||||||
pub mod channel_invite;
|
pub mod channel_invite;
|
||||||
pub mod channel_unread;
|
pub mod channel_unread;
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub mod webhook;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod servers {
|
mod servers {
|
||||||
@@ -41,7 +40,6 @@ pub use channels::channel::AbstractChannel;
|
|||||||
pub use channels::channel_invite::AbstractChannelInvite;
|
pub use channels::channel_invite::AbstractChannelInvite;
|
||||||
pub use channels::channel_unread::AbstractChannelUnread;
|
pub use channels::channel_unread::AbstractChannelUnread;
|
||||||
pub use channels::message::AbstractMessage;
|
pub use channels::message::AbstractMessage;
|
||||||
pub use channels::webhook::AbstractWebhook;
|
|
||||||
|
|
||||||
pub use servers::server::AbstractServer;
|
pub use servers::server::AbstractServer;
|
||||||
pub use servers::server_ban::AbstractServerBan;
|
pub use servers::server_ban::AbstractServerBan;
|
||||||
@@ -70,7 +68,6 @@ pub trait AbstractDatabase:
|
|||||||
+ AbstractBot
|
+ AbstractBot
|
||||||
+ AbstractUser
|
+ AbstractUser
|
||||||
+ AbstractUserSettings
|
+ AbstractUserSettings
|
||||||
+ AbstractWebhook
|
|
||||||
+ AbstractReport
|
+ AbstractReport
|
||||||
+ AbstractSnapshot
|
+ AbstractSnapshot
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
use revolt_models::v0::Webhook;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::models::{Message, User, Webhook, File};
|
use crate::models::{Message, User};
|
||||||
use crate::variables::delta::{APP_URL, AUTUMN_URL, PUBLIC_URL};
|
use crate::variables::delta::{APP_URL, AUTUMN_URL, PUBLIC_URL};
|
||||||
|
|
||||||
/// Push Notification
|
/// Push Notification
|
||||||
@@ -27,7 +28,7 @@ pub struct PushNotification {
|
|||||||
|
|
||||||
pub enum MessageAuthor<'a> {
|
pub enum MessageAuthor<'a> {
|
||||||
User(&'a User),
|
User(&'a User),
|
||||||
Webhook(&'a Webhook)
|
Webhook(&'a Webhook),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MessageAuthor<'a> {
|
impl<'a> MessageAuthor<'a> {
|
||||||
@@ -38,10 +39,10 @@ impl<'a> MessageAuthor<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn avatar(&self) -> Option<&File> {
|
pub fn avatar(&self) -> Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
MessageAuthor::User(user) => user.avatar.as_ref(),
|
MessageAuthor::User(user) => user.avatar.as_ref().map(|file| file.id.as_str()),
|
||||||
MessageAuthor::Webhook(webhook) => webhook.avatar.as_ref(),
|
MessageAuthor::Webhook(webhook) => webhook.avatar.as_ref().map(|file| file.id.as_str()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ impl PushNotification {
|
|||||||
pub fn new(msg: Message, author: Option<MessageAuthor<'_>>, channel_id: &str) -> Self {
|
pub fn new(msg: Message, author: Option<MessageAuthor<'_>>, channel_id: &str) -> Self {
|
||||||
let icon = if let Some(author) = &author {
|
let icon = if let Some(author) = &author {
|
||||||
if let Some(avatar) = author.avatar() {
|
if let Some(avatar) = author.avatar() {
|
||||||
format!("{}/avatars/{}", &*AUTUMN_URL, avatar.id)
|
format!("{}/avatars/{}", &*AUTUMN_URL, avatar)
|
||||||
} else {
|
} else {
|
||||||
format!("{}/users/{}/default_avatar", &*PUBLIC_URL, author.id())
|
format!("{}/users/{}/default_avatar", &*PUBLIC_URL, author.id())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use schemars::JsonSchema;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
Bot, Channel, Emoji, Invite, Member, Message, Report, Server, ServerBan, User, Webhook
|
Bot, Channel, Emoji, Invite, Member, Message, Report, Server, ServerBan, User,
|
||||||
};
|
};
|
||||||
use crate::{Database, Error, Result};
|
use crate::{Database, Error, Result};
|
||||||
|
|
||||||
@@ -81,11 +81,6 @@ impl Ref {
|
|||||||
db.fetch_emoji(&self.id).await
|
db.fetch_emoji(&self.id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetches webhook from Ref
|
|
||||||
pub async fn as_webhook(&self, db: &Database) -> Result<Webhook> {
|
|
||||||
db.fetch_webhook(&self.id).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch report from Ref
|
/// Fetch report from Ref
|
||||||
pub async fn as_report(&self, db: &Database) -> Result<Report> {
|
pub async fn as_report(&self, db: &Database) -> Result<Report> {
|
||||||
db.fetch_report(&self.id).await
|
db.fetch_report(&self.id).await
|
||||||
|
|||||||
Reference in New Issue
Block a user