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
use crate::prelude::*;
use rive_models::{channel::ChannelUnread, payload::FetchMessagesPayload, user::UserSettings};
use std::collections::HashMap;

impl Client {
    /// Fetch settings from server filtered by keys.
    pub async fn fetch_settings(&self, payload: FetchMessagesPayload) -> Result<UserSettings> {
        Ok(self
            .client
            .post(ep!(self, "/sync/settings/fetch"))
            .json(&payload)
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }

    /// Upload data to save to settings.
    pub async fn set_settings(&self, payload: HashMap<String, String>) -> Result<()> {
        self.client
            .post(ep!(self, "/sync/settings/set"))
            .json(&payload)
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?;
        Ok(())
    }

    /// Fetch information about unread state on channels.
    pub async fn fetch_unreads(&self) -> Result<Vec<ChannelUnread>> {
        Ok(self
            .client
            .get(ep!(self, "/sync/unreads"))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }
}