1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use crate::prelude::*;
use rive_models::{
    payload::SendFriendRequestPayload,
    user::{Mutuals, User},
};

impl Client {
    /// This fetches your direct messages, including any DM and group DM conversations.
    pub async fn fetch_mutual_friends_and_servers(&self, id: impl Into<String>) -> Result<Mutuals> {
        Ok(self
            .client
            .get(ep!(self, "/users/{}/mutual", id.into()))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }

    /// Accept another user's friend request
    pub async fn accept_friend_request(&self, id: impl Into<String>) -> Result<User> {
        Ok(self
            .client
            .put(ep!(self, "/users/{}/friend", id.into()))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }

    /// Denies another user's friend request or removes an existing friend.
    pub async fn remove_or_deny_friend(&self, id: impl Into<String>) -> Result<User> {
        Ok(self
            .client
            .delete(ep!(self, "/users/{}/friend", id.into()))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }

    /// Block another user by their id.
    pub async fn block_user(&self, id: impl Into<String>) -> Result<User> {
        Ok(self
            .client
            .put(ep!(self, "/users/{}/block", id.into()))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }

    /// Unblock another user by their id.
    pub async fn unblock_user(&self, id: impl Into<String>) -> Result<User> {
        Ok(self
            .client
            .delete(ep!(self, "/users/{}/block", id.into()))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }

    /// Send a friend request to another user.
    pub async fn send_friend_request(&self, payload: SendFriendRequestPayload) -> Result<User> {
        Ok(self
            .client
            .post(ep!(self, "/users/friend"))
            .auth(&self.authentication)
            .json(&payload)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }
}