revolt_database/models/messages/
ops.rs

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