Skip to main content

revolt_database/models/messages/
ops.rs

1use std::collections::HashMap;
2use std::time::SystemTime;
3use revolt_result::Result;
4
5use crate::{AppendMessage, FieldsMessage, Message, MessageQuery, PartialMessage};
6
7#[cfg(feature = "mongodb")]
8mod mongodb;
9mod reference;
10
11#[async_trait]
12pub trait AbstractMessages: Sync + Send {
13    /// Insert a new message into the database
14    async fn insert_message(&self, message: &Message) -> Result<()>;
15
16    /// Fetch a message by its id
17    async fn fetch_message(&self, id: &str) -> Result<Message>;
18
19    /// Fetch multiple messages by given query
20    async fn fetch_messages(&self, query: MessageQuery) -> Result<Vec<Message>>;
21
22    /// Fetch multiple messages by given IDs
23    async fn fetch_messages_by_id(&self, ids: &[String]) -> Result<Vec<Message>>;
24
25    /// Update a given message with new information
26    async fn update_message(&self, id: &str, message: &PartialMessage, remove: Vec<FieldsMessage>) -> Result<()>;
27
28    /// Append information to a given message
29    async fn append_message(&self, id: &str, append: &AppendMessage) -> Result<()>;
30
31    /// Add a new reaction to a message
32    async fn add_reaction(&self, id: &str, emoji: &str, user: &str) -> Result<()>;
33
34    /// Remove a reaction from a message
35    async fn remove_reaction(&self, id: &str, emoji: &str, user: &str) -> Result<()>;
36
37    /// Remove reaction from a message
38    async fn clear_reaction(&self, id: &str, emoji: &str) -> Result<()>;
39
40    /// Delete a message from the database by its id
41    async fn delete_message(&self, id: &str) -> Result<()>;
42
43    /// Delete messages from a channel by their ids and corresponding channel id
44    async fn delete_messages(&self, channel: &str, ids: &[String]) -> Result<()>;
45
46    /// Delete all messages from a specific author in a server from a certain ULID onwards
47    async fn delete_messages_by_author_since(
48        &self,
49        channels: &[String],
50        author: &str,
51        since: SystemTime
52    ) -> Result<HashMap<String, Vec<String>>>;
53}