rust_tdlib/types/
chat_position.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Describes a position of a chat in a chat list
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct ChatPosition {
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
14
15    #[serde(skip_serializing_if = "ChatList::_is_default")]
16    list: ChatList,
17    /// A parameter used to determine order of the chat in the chat list. Chats must be sorted by the pair (order, chat.id) in descending order
18
19    #[serde(
20        deserialize_with = "super::_common::number_from_string",
21        serialize_with = "super::_common::string_to_number"
22    )]
23    #[serde(default)]
24    order: i64,
25    /// True, if the chat is pinned in the chat list
26
27    #[serde(default)]
28    is_pinned: bool,
29    /// Source of the chat in the chat list; may be null
30    source: Option<ChatSource>,
31}
32
33impl RObject for ChatPosition {
34    #[doc(hidden)]
35    fn extra(&self) -> Option<&str> {
36        self.extra.as_deref()
37    }
38    #[doc(hidden)]
39    fn client_id(&self) -> Option<i32> {
40        self.client_id
41    }
42}
43
44impl ChatPosition {
45    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
46        Ok(serde_json::from_str(json.as_ref())?)
47    }
48    pub fn builder() -> ChatPositionBuilder {
49        let mut inner = ChatPosition::default();
50        inner.extra = Some(Uuid::new_v4().to_string());
51
52        ChatPositionBuilder { inner }
53    }
54
55    pub fn list(&self) -> &ChatList {
56        &self.list
57    }
58
59    pub fn order(&self) -> i64 {
60        self.order
61    }
62
63    pub fn is_pinned(&self) -> bool {
64        self.is_pinned
65    }
66
67    pub fn source(&self) -> &Option<ChatSource> {
68        &self.source
69    }
70}
71
72#[doc(hidden)]
73pub struct ChatPositionBuilder {
74    inner: ChatPosition,
75}
76
77#[deprecated]
78pub type RTDChatPositionBuilder = ChatPositionBuilder;
79
80impl ChatPositionBuilder {
81    pub fn build(&self) -> ChatPosition {
82        self.inner.clone()
83    }
84
85    pub fn list<T: AsRef<ChatList>>(&mut self, list: T) -> &mut Self {
86        self.inner.list = list.as_ref().clone();
87        self
88    }
89
90    pub fn order(&mut self, order: i64) -> &mut Self {
91        self.inner.order = order;
92        self
93    }
94
95    pub fn is_pinned(&mut self, is_pinned: bool) -> &mut Self {
96        self.inner.is_pinned = is_pinned;
97        self
98    }
99
100    pub fn source<T: AsRef<ChatSource>>(&mut self, source: T) -> &mut Self {
101        self.inner.source = Some(source.as_ref().clone());
102        self
103    }
104}
105
106impl AsRef<ChatPosition> for ChatPosition {
107    fn as_ref(&self) -> &ChatPosition {
108        self
109    }
110}
111
112impl AsRef<ChatPosition> for ChatPositionBuilder {
113    fn as_ref(&self) -> &ChatPosition {
114        &self.inner
115    }
116}