rive_http/users/
relationships.rs

1use crate::prelude::*;
2use rive_models::{
3    data::SendFriendRequestData,
4    user::{Mutuals, User},
5};
6
7impl Client {
8    /// This fetches your direct messages, including any DM and group DM conversations.
9    pub async fn fetch_mutual_friends_and_servers(&self, id: impl Into<String>) -> Result<Mutuals> {
10        Ok(self
11            .client
12            .get(ep!(self, "/users/{}/mutual", id.into()))
13            .auth(&self.authentication)
14            .send()
15            .await?
16            .process_error()
17            .await?
18            .json()
19            .await?)
20    }
21
22    /// Accept another user's friend request
23    pub async fn accept_friend_request(&self, id: impl Into<String>) -> Result<User> {
24        Ok(self
25            .client
26            .put(ep!(self, "/users/{}/friend", id.into()))
27            .auth(&self.authentication)
28            .send()
29            .await?
30            .process_error()
31            .await?
32            .json()
33            .await?)
34    }
35
36    /// Denies another user's friend request or removes an existing friend.
37    pub async fn remove_or_deny_friend(&self, id: impl Into<String>) -> Result<User> {
38        Ok(self
39            .client
40            .delete(ep!(self, "/users/{}/friend", id.into()))
41            .auth(&self.authentication)
42            .send()
43            .await?
44            .process_error()
45            .await?
46            .json()
47            .await?)
48    }
49
50    /// Block another user by their id.
51    pub async fn block_user(&self, id: impl Into<String>) -> Result<User> {
52        Ok(self
53            .client
54            .put(ep!(self, "/users/{}/block", id.into()))
55            .auth(&self.authentication)
56            .send()
57            .await?
58            .process_error()
59            .await?
60            .json()
61            .await?)
62    }
63
64    /// Unblock another user by their id.
65    pub async fn unblock_user(&self, id: impl Into<String>) -> Result<User> {
66        Ok(self
67            .client
68            .delete(ep!(self, "/users/{}/block", id.into()))
69            .auth(&self.authentication)
70            .send()
71            .await?
72            .process_error()
73            .await?
74            .json()
75            .await?)
76    }
77
78    /// Send a friend request to another user.
79    pub async fn send_friend_request(&self, data: SendFriendRequestData) -> Result<User> {
80        Ok(self
81            .client
82            .post(ep!(self, "/users/friend"))
83            .auth(&self.authentication)
84            .json(&data)
85            .send()
86            .await?
87            .process_error()
88            .await?
89            .json()
90            .await?)
91    }
92}