rive_http/miscellaneous/
sync.rs

1use crate::prelude::*;
2use rive_models::{channel::ChannelUnread, data::FetchMessagesData, user::UserSettings};
3use std::collections::HashMap;
4
5impl Client {
6    /// Fetch settings from server filtered by keys.
7    pub async fn fetch_settings(&self, data: FetchMessagesData) -> Result<UserSettings> {
8        Ok(self
9            .client
10            .post(ep!(self, "/sync/settings/fetch"))
11            .json(&data)
12            .auth(&self.authentication)
13            .send()
14            .await?
15            .process_error()
16            .await?
17            .json()
18            .await?)
19    }
20
21    /// Upload data to save to settings.
22    pub async fn set_settings(&self, data: HashMap<String, String>) -> Result<()> {
23        self.client
24            .post(ep!(self, "/sync/settings/set"))
25            .json(&data)
26            .auth(&self.authentication)
27            .send()
28            .await?
29            .process_error()
30            .await?;
31        Ok(())
32    }
33
34    /// Fetch information about unread state on channels.
35    pub async fn fetch_unreads(&self) -> Result<Vec<ChannelUnread>> {
36        Ok(self
37            .client
38            .get(ep!(self, "/sync/unreads"))
39            .auth(&self.authentication)
40            .send()
41            .await?
42            .process_error()
43            .await?
44            .json()
45            .await?)
46    }
47}