rive_http/channels/
groups.rs1use crate::prelude::*;
2use rive_models::{channel::Channel, data::CreateGroupData, user::User};
3
4impl Client {
5 pub async fn fetch_group_members(&self, id: impl Into<String>) -> Result<Vec<User>> {
7 Ok(self
8 .client
9 .get(ep!(self, "/channels/{}/members", id.into()))
10 .auth(&self.authentication)
11 .send()
12 .await?
13 .process_error()
14 .await?
15 .json()
16 .await?)
17 }
18
19 pub async fn create_group(&self, data: CreateGroupData) -> Result<Channel> {
21 Ok(self
22 .client
23 .post(ep!(self, "/channels/create"))
24 .json(&data)
25 .auth(&self.authentication)
26 .send()
27 .await?
28 .process_error()
29 .await?
30 .json()
31 .await?)
32 }
33
34 pub async fn add_member_to_group(
36 &self,
37 group_id: impl Into<String>,
38 member_id: impl Into<String>,
39 ) -> Result<()> {
40 self.client
41 .put(ep!(
42 self,
43 "/channels/{}/recipients/{}",
44 group_id.into(),
45 member_id.into()
46 ))
47 .auth(&self.authentication)
48 .send()
49 .await?
50 .process_error()
51 .await?
52 .json()
53 .await?;
54 Ok(())
55 }
56
57 pub async fn remove_member_from_group(
59 &self,
60 group_id: impl Into<String>,
61 member_id: impl Into<String>,
62 ) -> Result<()> {
63 self.client
64 .delete(ep!(
65 self,
66 "/channels/{}/recipients/{}",
67 group_id.into(),
68 member_id.into()
69 ))
70 .auth(&self.authentication)
71 .send()
72 .await?
73 .process_error()
74 .await?
75 .json()
76 .await?;
77 Ok(())
78 }
79}