Skip to main content

revolt_database/models/channels/
ops.rs

1use crate::{Channel, FieldsChannel, PartialChannel, revolt_result::Result, util::ChunkedDatabaseGenerator};
2use revolt_permissions::OverrideField;
3
4#[cfg(feature = "mongodb")]
5mod mongodb;
6mod reference;
7
8#[async_trait]
9pub trait AbstractChannels: Sync + Send {
10    /// Insert a new channel in the database
11    async fn insert_channel(&self, channel: &Channel) -> Result<()>;
12
13    /// Fetch a channel from the database
14    async fn fetch_channel(&self, channel_id: &str) -> Result<Channel>;
15
16    /// Fetch all channels from the database
17    async fn fetch_channels<'a>(&self, ids: &'a [String]) -> Result<Vec<Channel>>;
18
19    /// Fetch all direct messages for a user
20    async fn find_direct_messages(&self, user_id: &str) -> Result<Vec<Channel>>;
21
22    // Fetch all group dms for a user
23    async fn find_group_message_channels(&self, user_id: &str) -> Result<ChunkedDatabaseGenerator<Channel>>;
24
25    // Fetch saved messages channel
26    async fn find_saved_messages_channel(&self, user_id: &str) -> Result<Channel>;
27
28    // Fetch direct message channel (DM or Saved Messages)
29    async fn find_direct_message_channel(&self, user_a: &str, user_b: &str) -> Result<Channel>;
30
31    /// Insert a user to a group
32    async fn add_user_to_group(&self, channel_id: &str, user_id: &str) -> Result<()>;
33
34    /// Insert channel role permissions
35    async fn set_channel_role_permission(
36        &self,
37        channel_id: &str,
38        role_id: &str,
39        permissions: OverrideField,
40    ) -> Result<()>;
41
42    // Update channel
43    async fn update_channel(
44        &self,
45        id: &str,
46        channel_id: &PartialChannel,
47        remove: Vec<FieldsChannel>,
48    ) -> Result<()>;
49
50    // Remove a user from a group
51    async fn remove_user_from_group(&self, channel_id: &str, user_id: &str) -> Result<()>;
52
53    // Remove a user from all specified groups
54    async fn remove_user_from_groups(&self, channel_ids: Vec<String>, user_id: &str) -> Result<()>;
55
56    // Delete a channel
57    async fn delete_channel(&self, channel_id: &Channel) -> Result<()>;
58}