rust_tdlib/types/
optimize_storage.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Optimizes storage usage, i.e. deletes some files and returns new storage usage statistics. Secret thumbnails can't be deleted
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct OptimizeStorage {
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    /// Limit on the total size of files after deletion, in bytes. Pass 1 to use the default limit
14
15    #[serde(default)]
16    size: i64,
17    /// Limit on the time that has passed since the last time a file was accessed (or creation time for some filesystems). Pass 1 to use the default limit
18
19    #[serde(default)]
20    ttl: i32,
21    /// Limit on the total count of files after deletion. Pass 1 to use the default limit
22
23    #[serde(default)]
24    count: i32,
25    /// The amount of time after the creation of a file during which it can't be deleted, in seconds. Pass 1 to use the default value
26
27    #[serde(default)]
28    immunity_delay: i32,
29    /// If non-empty, only files with the given types are considered. By default, all types except thumbnails, profile photos, stickers and wallpapers are deleted
30
31    #[serde(default)]
32    file_types: Vec<FileType>,
33    /// If non-empty, only files from the given chats are considered. Use 0 as chat identifier to delete files not belonging to any chat (e.g., profile photos)
34
35    #[serde(default)]
36    chat_ids: Vec<i64>,
37    /// If non-empty, files from the given chats are excluded. Use 0 as chat identifier to exclude all files not belonging to any chat (e.g., profile photos)
38
39    #[serde(default)]
40    exclude_chat_ids: Vec<i64>,
41    /// Pass true if statistics about the files that were deleted must be returned instead of the whole storage usage statistics. Affects only returned statistics
42
43    #[serde(default)]
44    return_deleted_file_statistics: bool,
45    /// Same as in getStorageStatistics. Affects only returned statistics
46
47    #[serde(default)]
48    chat_limit: i32,
49
50    #[serde(rename(serialize = "@type"))]
51    td_type: String,
52}
53
54impl RObject for OptimizeStorage {
55    #[doc(hidden)]
56    fn extra(&self) -> Option<&str> {
57        self.extra.as_deref()
58    }
59    #[doc(hidden)]
60    fn client_id(&self) -> Option<i32> {
61        self.client_id
62    }
63}
64
65impl RFunction for OptimizeStorage {}
66
67impl OptimizeStorage {
68    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
69        Ok(serde_json::from_str(json.as_ref())?)
70    }
71    pub fn builder() -> OptimizeStorageBuilder {
72        let mut inner = OptimizeStorage::default();
73        inner.extra = Some(Uuid::new_v4().to_string());
74
75        inner.td_type = "optimizeStorage".to_string();
76
77        OptimizeStorageBuilder { inner }
78    }
79
80    pub fn size(&self) -> i64 {
81        self.size
82    }
83
84    pub fn ttl(&self) -> i32 {
85        self.ttl
86    }
87
88    pub fn count(&self) -> i32 {
89        self.count
90    }
91
92    pub fn immunity_delay(&self) -> i32 {
93        self.immunity_delay
94    }
95
96    pub fn file_types(&self) -> &Vec<FileType> {
97        &self.file_types
98    }
99
100    pub fn chat_ids(&self) -> &Vec<i64> {
101        &self.chat_ids
102    }
103
104    pub fn exclude_chat_ids(&self) -> &Vec<i64> {
105        &self.exclude_chat_ids
106    }
107
108    pub fn return_deleted_file_statistics(&self) -> bool {
109        self.return_deleted_file_statistics
110    }
111
112    pub fn chat_limit(&self) -> i32 {
113        self.chat_limit
114    }
115}
116
117#[doc(hidden)]
118pub struct OptimizeStorageBuilder {
119    inner: OptimizeStorage,
120}
121
122#[deprecated]
123pub type RTDOptimizeStorageBuilder = OptimizeStorageBuilder;
124
125impl OptimizeStorageBuilder {
126    pub fn build(&self) -> OptimizeStorage {
127        self.inner.clone()
128    }
129
130    pub fn size(&mut self, size: i64) -> &mut Self {
131        self.inner.size = size;
132        self
133    }
134
135    pub fn ttl(&mut self, ttl: i32) -> &mut Self {
136        self.inner.ttl = ttl;
137        self
138    }
139
140    pub fn count(&mut self, count: i32) -> &mut Self {
141        self.inner.count = count;
142        self
143    }
144
145    pub fn immunity_delay(&mut self, immunity_delay: i32) -> &mut Self {
146        self.inner.immunity_delay = immunity_delay;
147        self
148    }
149
150    pub fn file_types(&mut self, file_types: Vec<FileType>) -> &mut Self {
151        self.inner.file_types = file_types;
152        self
153    }
154
155    pub fn chat_ids(&mut self, chat_ids: Vec<i64>) -> &mut Self {
156        self.inner.chat_ids = chat_ids;
157        self
158    }
159
160    pub fn exclude_chat_ids(&mut self, exclude_chat_ids: Vec<i64>) -> &mut Self {
161        self.inner.exclude_chat_ids = exclude_chat_ids;
162        self
163    }
164
165    pub fn return_deleted_file_statistics(
166        &mut self,
167        return_deleted_file_statistics: bool,
168    ) -> &mut Self {
169        self.inner.return_deleted_file_statistics = return_deleted_file_statistics;
170        self
171    }
172
173    pub fn chat_limit(&mut self, chat_limit: i32) -> &mut Self {
174        self.inner.chat_limit = chat_limit;
175        self
176    }
177}
178
179impl AsRef<OptimizeStorage> for OptimizeStorage {
180    fn as_ref(&self) -> &OptimizeStorage {
181        self
182    }
183}
184
185impl AsRef<OptimizeStorage> for OptimizeStorageBuilder {
186    fn as_ref(&self) -> &OptimizeStorage {
187        &self.inner
188    }
189}