use crate::prelude::*;
use rive_models::{channel::Channel, payload::CreateGroupPayload, user::User};
impl Client {
pub async fn fetch_group_members(&self, id: impl Into<String>) -> Result<Vec<User>> {
Ok(self
.client
.get(ep!(self, "/channels/{}/members", id.into()))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
pub async fn create_group(&self, payload: CreateGroupPayload) -> Result<Channel> {
Ok(self
.client
.post(ep!(self, "/channels/create"))
.json(&payload)
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
pub async fn add_member_to_group(
&self,
group_id: impl Into<String>,
member_id: impl Into<String>,
) -> Result<()> {
self.client
.put(ep!(
self,
"/channels/{}/recipients/{}",
group_id.into(),
member_id.into()
))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?;
Ok(())
}
pub async fn remove_member_from_group(
&self,
group_id: impl Into<String>,
member_id: impl Into<String>,
) -> Result<()> {
self.client
.delete(ep!(
self,
"/channels/{}/recipients/{}",
group_id.into(),
member_id.into()
))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?;
Ok(())
}
}