1#![allow(missing_docs)]
4
5use std::sync::LazyLock;
6
7use deltachat_derive::{FromSql, ToSql};
8use percent_encoding::{AsciiSet, NON_ALPHANUMERIC};
9use serde::{Deserialize, Serialize};
10
11use crate::chat::ChatId;
12
13pub static DC_VERSION_STR: LazyLock<String> =
14 LazyLock::new(|| env!("CARGO_PKG_VERSION").to_string());
15
16pub(crate) const NON_ALPHANUMERIC_WITHOUT_DOT: &AsciiSet = &NON_ALPHANUMERIC.remove(b'.');
18
19#[derive(
20 Debug,
21 Default,
22 Display,
23 Clone,
24 Copy,
25 PartialEq,
26 Eq,
27 FromPrimitive,
28 ToPrimitive,
29 FromSql,
30 ToSql,
31 Serialize,
32 Deserialize,
33)]
34#[repr(i8)]
35pub enum Blocked {
36 #[default]
37 Not = 0,
38 Yes = 1,
39 Request = 2,
40}
41
42#[derive(
43 Debug, Default, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql,
44)]
45#[repr(u8)]
46pub enum ShowEmails {
47 Off = 0,
48 AcceptedContacts = 1,
49 #[default] All = 2,
51}
52
53#[derive(
54 Debug, Default, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql,
55)]
56#[repr(u8)]
57pub enum MediaQuality {
58 #[default] Balanced = 0,
60 Worse = 1,
61}
62
63pub const DC_HANDSHAKE_CONTINUE_NORMAL_PROCESSING: i32 = 0x01;
64pub const DC_HANDSHAKE_STOP_NORMAL_PROCESSING: i32 = 0x02;
65pub const DC_HANDSHAKE_ADD_DELETE_JOB: i32 = 0x04;
66
67pub(crate) const DC_FROM_HANDSHAKE: i32 = 0x01;
68
69pub const DC_GCL_ARCHIVED_ONLY: usize = 0x01;
70pub const DC_GCL_NO_SPECIALS: usize = 0x02;
71pub const DC_GCL_ADD_ALLDONE_HINT: usize = 0x04;
72pub const DC_GCL_FOR_FORWARDING: usize = 0x08;
73
74pub const DC_GCL_ADD_SELF: u32 = 0x02;
75pub const DC_GCL_ADDRESS: u32 = 0x04;
76
77pub(crate) const DC_RESEND_USER_AVATAR_DAYS: i64 = 14;
79
80pub(crate) const DC_OUTDATED_WARNING_DAYS: i64 = 183;
86
87pub const DC_CHAT_ID_TRASH: ChatId = ChatId::new(3);
89pub const DC_CHAT_ID_ARCHIVED_LINK: ChatId = ChatId::new(6);
91pub const DC_CHAT_ID_ALLDONE_HINT: ChatId = ChatId::new(7);
93pub const DC_CHAT_ID_LAST_SPECIAL: ChatId = ChatId::new(9);
95
96#[derive(
98 Debug,
99 Display,
100 Clone,
101 Copy,
102 PartialEq,
103 Eq,
104 PartialOrd,
105 Ord,
106 FromPrimitive,
107 ToPrimitive,
108 FromSql,
109 ToSql,
110 IntoStaticStr,
111 Serialize,
112 Deserialize,
113)]
114#[repr(u32)]
115pub enum Chattype {
116 Single = 100,
120
121 Group = 120,
125
126 Mailinglist = 140,
129
130 OutBroadcast = 160,
142
143 InBroadcast = 165,
156}
157
158pub const DC_MSG_ID_DAYMARKER: u32 = 9;
159pub const DC_MSG_ID_LAST_SPECIAL: u32 = 9;
160
161pub(crate) const DC_ELLIPSIS: &str = "[...]";
163pub const DC_DESIRED_TEXT_LINES: usize = 38;
166pub const DC_DESIRED_TEXT_LINE_LEN: usize = 100;
168
169pub const DC_DESIRED_TEXT_LEN: usize = DC_DESIRED_TEXT_LINE_LEN * DC_DESIRED_TEXT_LINES;
178
179pub const DC_LP_AUTH_OAUTH2: i32 = 0x2;
190
191pub const DC_LP_AUTH_NORMAL: i32 = 0x4;
194
195pub const DC_LP_AUTH_FLAGS: i32 = DC_LP_AUTH_OAUTH2 | DC_LP_AUTH_NORMAL;
197
198pub const BALANCED_IMAGE_BYTES: usize = 500_000;
200pub const WORSE_IMAGE_BYTES: usize = 130_000;
201
202pub(crate) const BALANCED_AVATAR_SIZE: u32 = 512;
204pub(crate) const BALANCED_AVATAR_BYTES: usize = 60_000;
205pub(crate) const WORSE_AVATAR_SIZE: u32 = 128;
206pub(crate) const WORSE_AVATAR_BYTES: usize = 20_000; pub const BALANCED_IMAGE_SIZE: u32 = 1280;
210pub const WORSE_IMAGE_SIZE: u32 = 640;
211
212pub const MAX_RCVD_IMAGE_PIXELS: u32 = 50_000_000;
215
216pub(crate) const DC_FOLDERS_CONFIGURED_KEY: &str = "folders_configured";
218pub(crate) const DC_FOLDERS_CONFIGURED_VERSION: i32 = 5;
220
221pub(crate) const DEFAULT_MAX_SMTP_RCPT_TO: usize = 50;
225
226pub(crate) const DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT: u64 = 12 * 60 * 60; pub(crate) const TIMESTAMP_SENT_TOLERANCE: i64 = 60;
232
233pub(crate) const EDITED_PREFIX: &str = "✏️";
236
237pub(crate) const ASM_SUBJECT: &str = "Autocrypt Setup Message";
240pub(crate) const ASM_BODY: &str = "This is the Autocrypt Setup Message \
241 used to transfer your end-to-end setup between clients.
242
243 To decrypt and use your setup, \
244 open the message in an Autocrypt-compliant client \
245 and enter the setup code presented on the generating device.
246
247 If you see this message in a chatmail client (Delta Chat, Arcane Chat, Delta Touch ...), \
248 use \"Settings / Add Second Device\" instead.";
249
250pub(crate) const HOUSEKEEPING_PERIOD: i64 = 24 * 60 * 60;
252
253pub(crate) const BROADCAST_INCOMPATIBILITY_MSG: &str = r#"The up to now "experimental channels feature" is about to become an officially supported one. By that, privacy will be improved, it will become faster, and less traffic will be consumed.
254
255As we do not guarantee feature-stability for such experiments, this means, that you will need to create the channel again.
256
257Here is what to do:
258 • Create a new channel
259 • Tap on the channel name
260 • Tap on "QR Invite Code"
261 • Have all recipients scan the QR code, or send them the link
262
263If you have any questions, please send an email to delta@merlinux.eu or ask at https://support.delta.chat/."#;
264
265#[cfg(test)]
266mod tests {
267 use num_traits::FromPrimitive;
268
269 use super::*;
270
271 #[test]
272 fn test_chattype_values() {
273 assert_eq!(Chattype::Single, Chattype::from_i32(100).unwrap());
275 assert_eq!(Chattype::Group, Chattype::from_i32(120).unwrap());
276 assert_eq!(Chattype::Mailinglist, Chattype::from_i32(140).unwrap());
277 assert_eq!(Chattype::OutBroadcast, Chattype::from_i32(160).unwrap());
278 }
279
280 #[test]
281 fn test_showemails_values() {
282 assert_eq!(ShowEmails::All, ShowEmails::default());
284 assert_eq!(ShowEmails::Off, ShowEmails::from_i32(0).unwrap());
285 assert_eq!(
286 ShowEmails::AcceptedContacts,
287 ShowEmails::from_i32(1).unwrap()
288 );
289 assert_eq!(ShowEmails::All, ShowEmails::from_i32(2).unwrap());
290 }
291
292 #[test]
293 fn test_blocked_values() {
294 assert_eq!(Blocked::Not, Blocked::default());
296 assert_eq!(Blocked::Not, Blocked::from_i32(0).unwrap());
297 assert_eq!(Blocked::Yes, Blocked::from_i32(1).unwrap());
298 assert_eq!(Blocked::Request, Blocked::from_i32(2).unwrap());
299 }
300
301 #[test]
302 fn test_mediaquality_values() {
303 assert_eq!(MediaQuality::Balanced, MediaQuality::default());
305 assert_eq!(MediaQuality::Balanced, MediaQuality::from_i32(0).unwrap());
306 assert_eq!(MediaQuality::Worse, MediaQuality::from_i32(1).unwrap());
307 }
308}