rust_tdlib/types/
load_chats.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Loads more chats from a chat list. The loaded chats and their positions in the chat list will be sent through updates. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. Returns a 404 error if all chats have been loaded
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct LoadChats {
8    #[doc(hidden)]
9    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10    extra: Option<String>,
11    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12    client_id: Option<i32>,
13    /// The chat list in which to load chats; pass null to load chats from the main chat list
14
15    #[serde(skip_serializing_if = "ChatList::_is_default")]
16    chat_list: ChatList,
17    /// The maximum number of chats to be loaded. For optimal performance, the number of loaded chats is chosen by TDLib and can be smaller than the specified limit, even if the end of the list is not reached
18
19    #[serde(default)]
20    limit: i32,
21
22    #[serde(rename(serialize = "@type"))]
23    td_type: String,
24}
25
26impl RObject for LoadChats {
27    #[doc(hidden)]
28    fn extra(&self) -> Option<&str> {
29        self.extra.as_deref()
30    }
31    #[doc(hidden)]
32    fn client_id(&self) -> Option<i32> {
33        self.client_id
34    }
35}
36
37impl RFunction for LoadChats {}
38
39impl LoadChats {
40    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
41        Ok(serde_json::from_str(json.as_ref())?)
42    }
43    pub fn builder() -> LoadChatsBuilder {
44        let mut inner = LoadChats::default();
45        inner.extra = Some(Uuid::new_v4().to_string());
46
47        inner.td_type = "loadChats".to_string();
48
49        LoadChatsBuilder { inner }
50    }
51
52    pub fn chat_list(&self) -> &ChatList {
53        &self.chat_list
54    }
55
56    pub fn limit(&self) -> i32 {
57        self.limit
58    }
59}
60
61#[doc(hidden)]
62pub struct LoadChatsBuilder {
63    inner: LoadChats,
64}
65
66#[deprecated]
67pub type RTDLoadChatsBuilder = LoadChatsBuilder;
68
69impl LoadChatsBuilder {
70    pub fn build(&self) -> LoadChats {
71        self.inner.clone()
72    }
73
74    pub fn chat_list<T: AsRef<ChatList>>(&mut self, chat_list: T) -> &mut Self {
75        self.inner.chat_list = chat_list.as_ref().clone();
76        self
77    }
78
79    pub fn limit(&mut self, limit: i32) -> &mut Self {
80        self.inner.limit = limit;
81        self
82    }
83}
84
85impl AsRef<LoadChats> for LoadChats {
86    fn as_ref(&self) -> &LoadChats {
87        self
88    }
89}
90
91impl AsRef<LoadChats> for LoadChatsBuilder {
92    fn as_ref(&self) -> &LoadChats {
93        &self.inner
94    }
95}