revolt_database/models/users/
ops.rs

1use authifier::models::Session;
2use iso8601_timestamp::Timestamp;
3use revolt_result::Result;
4
5use crate::{FieldsUser, PartialUser, RelationshipStatus, User};
6
7#[cfg(feature = "mongodb")]
8mod mongodb;
9mod reference;
10
11#[async_trait]
12pub trait AbstractUsers: Sync + Send {
13    /// Insert a new user into the database
14    async fn insert_user(&self, user: &User) -> Result<()>;
15
16    /// Fetch a user from the database
17    async fn fetch_user(&self, id: &str) -> Result<User>;
18
19    /// Fetch a user from the database by their username
20    async fn fetch_user_by_username(&self, username: &str, discriminator: &str) -> Result<User>;
21
22    /// Fetch a session from the database by token
23    async fn fetch_session_by_token(&self, token: &str) -> Result<Session>;
24
25    /// Fetch multiple users by their ids
26    async fn fetch_users<'a>(&self, ids: &'a [String]) -> Result<Vec<User>>;
27
28    /// Fetch all discriminators in use for a username
29    async fn fetch_discriminators_in_use(&self, username: &str) -> Result<Vec<String>>;
30
31    /// Fetch ids of users that both users are friends with
32    async fn fetch_mutual_user_ids(&self, user_a: &str, user_b: &str) -> Result<Vec<String>>;
33
34    /// Fetch ids of channels that both users are in
35    async fn fetch_mutual_channel_ids(&self, user_a: &str, user_b: &str) -> Result<Vec<String>>;
36
37    /// Fetch ids of servers that both users share
38    async fn fetch_mutual_server_ids(&self, user_a: &str, user_b: &str) -> Result<Vec<String>>;
39
40    /// Update a user by their id given some data
41    async fn update_user(
42        &self,
43        id: &str,
44        user: &PartialUser,
45        remove: Vec<FieldsUser>,
46    ) -> Result<()>;
47
48    /// Set relationship with another user
49    ///
50    /// This should use pull_relationship if relationship is None.
51    async fn set_relationship(
52        &self,
53        user_id: &str,
54        target_id: &str,
55        relationship: &RelationshipStatus,
56    ) -> Result<()>;
57
58    /// Remove relationship with another user
59    async fn pull_relationship(&self, user_id: &str, target_id: &str) -> Result<()>;
60
61    /// Delete a user by their id
62    async fn delete_user(&self, id: &str) -> Result<()>;
63
64    /// Remove push subscription for a session by session id (TODO: remove)
65    async fn remove_push_subscription_by_session_id(&self, session_id: &str) -> Result<()>;
66
67    async fn update_session_last_seen(&self, session_id: &str, when: Timestamp) -> Result<()>;
68}