Skip to main content

tongbal_api/chat/
builder.rs

1use serde::Serialize;
2
3use crate::{
4    BaseClient, Error, UserClient,
5    types::{
6        MessageId,
7        constants::{CHATS, NOTICE, SETTINGS},
8    },
9};
10
11use super::{ChatCondition, ChatGroup, ChatSlowModeSec, MinFollowerMinute, NoticeBody};
12
13#[derive(Debug)]
14pub struct SetChatNotice<'a> {
15    client: &'a UserClient,
16    message: Option<&'a str>,
17    message_id: Option<&'a MessageId>,
18}
19
20impl<'a> SetChatNotice<'a> {
21    pub(crate) fn new(client: &'a UserClient) -> Self {
22        Self {
23            client,
24            message: None,
25            message_id: None,
26        }
27    }
28
29    pub fn message(mut self, value: &'a str) -> Self {
30        self.message = Some(value);
31        self
32    }
33
34    pub fn message_id(mut self, value: &'a MessageId) -> Self {
35        self.message_id = Some(value);
36        self
37    }
38
39    pub async fn send(self) -> Result<(), Error> {
40        let mut url = self.client.base_url();
41        url.path_segments_mut().unwrap().extend([CHATS, NOTICE]);
42        crate::client::no_content(self.client.http_client().post(url).json(&NoticeBody {
43            message: self.message,
44            message_id: self.message_id,
45        }))
46        .await?;
47
48        Ok(())
49    }
50}
51
52#[derive(Debug, Serialize)]
53#[serde(rename_all = "camelCase")]
54pub struct SetChatSettings<'a> {
55    #[serde(skip)]
56    client: &'a UserClient,
57    chat_available_condition: Option<ChatCondition>,
58    chat_available_group: Option<ChatGroup>,
59    min_follower_minute: Option<MinFollowerMinute>,
60    allow_subscriber_in_follower_mode: Option<bool>,
61    chat_slow_mode_sec: Option<ChatSlowModeSec>,
62    chat_emoji_mode: Option<bool>,
63}
64
65impl<'a> SetChatSettings<'a> {
66    pub(crate) fn new(client: &'a UserClient) -> Self {
67        Self {
68            client,
69            chat_available_condition: None,
70            chat_available_group: None,
71            min_follower_minute: None,
72            allow_subscriber_in_follower_mode: None,
73            chat_slow_mode_sec: None,
74            chat_emoji_mode: None,
75        }
76    }
77
78    pub fn chat_available_condition(mut self, value: ChatCondition) -> Self {
79        self.chat_available_condition = Some(value);
80        self
81    }
82
83    pub fn chat_available_group(mut self, value: ChatGroup) -> Self {
84        self.chat_available_group = Some(value);
85        self
86    }
87
88    pub fn min_follower_minute(mut self, value: MinFollowerMinute) -> Self {
89        self.min_follower_minute = Some(value);
90        self
91    }
92
93    pub fn allow_subscriber_in_follower_mode(mut self, value: bool) -> Self {
94        self.allow_subscriber_in_follower_mode = Some(value);
95        self
96    }
97
98    pub fn chat_slow_mode_sec(mut self, value: ChatSlowModeSec) -> Self {
99        self.chat_slow_mode_sec = Some(value);
100        self
101    }
102
103    pub fn chat_emoji_mode(mut self, value: bool) -> Self {
104        self.chat_emoji_mode = Some(value);
105        self
106    }
107
108    pub async fn send(self) -> Result<(), Error> {
109        let mut url = self.client.base_url();
110        url.path_segments_mut().unwrap().extend([CHATS, SETTINGS]);
111        crate::client::no_content(self.client.http_client().put(url).json(&self)).await?;
112        Ok(())
113    }
114}