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
63#[derive(
65 Debug, Default, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql,
66)]
67#[repr(i8)]
68pub enum VideochatType {
69 #[default]
71 Unknown = 0,
72
73 BasicWebrtc = 1,
75
76 Jitsi = 2,
78}
79
80pub const DC_HANDSHAKE_CONTINUE_NORMAL_PROCESSING: i32 = 0x01;
81pub const DC_HANDSHAKE_STOP_NORMAL_PROCESSING: i32 = 0x02;
82pub const DC_HANDSHAKE_ADD_DELETE_JOB: i32 = 0x04;
83
84pub(crate) const DC_FROM_HANDSHAKE: i32 = 0x01;
85
86pub const DC_GCL_ARCHIVED_ONLY: usize = 0x01;
87pub const DC_GCL_NO_SPECIALS: usize = 0x02;
88pub const DC_GCL_ADD_ALLDONE_HINT: usize = 0x04;
89pub const DC_GCL_FOR_FORWARDING: usize = 0x08;
90
91pub const DC_GCL_ADD_SELF: u32 = 0x02;
92
93pub(crate) const DC_RESEND_USER_AVATAR_DAYS: i64 = 14;
95
96pub(crate) const DC_OUTDATED_WARNING_DAYS: i64 = 365;
101
102pub const DC_CHAT_ID_TRASH: ChatId = ChatId::new(3);
104pub const DC_CHAT_ID_ARCHIVED_LINK: ChatId = ChatId::new(6);
106pub const DC_CHAT_ID_ALLDONE_HINT: ChatId = ChatId::new(7);
108pub const DC_CHAT_ID_LAST_SPECIAL: ChatId = ChatId::new(9);
110
111#[derive(
113 Debug,
114 Display,
115 Clone,
116 Copy,
117 PartialEq,
118 Eq,
119 FromPrimitive,
120 ToPrimitive,
121 FromSql,
122 ToSql,
123 IntoStaticStr,
124 Serialize,
125 Deserialize,
126)]
127#[repr(u32)]
128pub enum Chattype {
129 Single = 100,
131
132 Group = 120,
134
135 Mailinglist = 140,
137
138 Broadcast = 160,
140}
141
142pub const DC_MSG_ID_DAYMARKER: u32 = 9;
143pub const DC_MSG_ID_LAST_SPECIAL: u32 = 9;
144
145pub(crate) const DC_ELLIPSIS: &str = "[...]";
147pub const DC_DESIRED_TEXT_LINES: usize = 38;
150pub const DC_DESIRED_TEXT_LINE_LEN: usize = 100;
152
153pub const DC_DESIRED_TEXT_LEN: usize = DC_DESIRED_TEXT_LINE_LEN * DC_DESIRED_TEXT_LINES;
162
163pub const DC_LP_AUTH_OAUTH2: i32 = 0x2;
174
175pub const DC_LP_AUTH_NORMAL: i32 = 0x4;
178
179pub const DC_LP_AUTH_FLAGS: i32 = DC_LP_AUTH_OAUTH2 | DC_LP_AUTH_NORMAL;
181
182pub const BALANCED_IMAGE_BYTES: usize = 500_000;
184pub const WORSE_IMAGE_BYTES: usize = 130_000;
185
186pub(crate) const BALANCED_AVATAR_SIZE: u32 = 512;
188pub(crate) const BALANCED_AVATAR_BYTES: usize = 60_000;
189pub(crate) const WORSE_AVATAR_SIZE: u32 = 128;
190pub(crate) const WORSE_AVATAR_BYTES: usize = 20_000; pub const BALANCED_IMAGE_SIZE: u32 = 1280;
194pub const WORSE_IMAGE_SIZE: u32 = 640;
195
196pub(crate) const DC_FOLDERS_CONFIGURED_KEY: &str = "folders_configured";
198pub(crate) const DC_FOLDERS_CONFIGURED_VERSION: i32 = 5;
200
201pub(crate) const DEFAULT_MAX_SMTP_RCPT_TO: usize = 50;
205
206pub(crate) const DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT: u64 = 12 * 60 * 60; pub(crate) const TIMESTAMP_SENT_TOLERANCE: i64 = 60;
212
213pub(crate) const SECUREJOIN_WAIT_TIMEOUT: u64 = 15;
217
218pub(crate) const EDITED_PREFIX: &str = "✏️";
221
222pub(crate) const ASM_SUBJECT: &str = "Autocrypt Setup Message";
225pub(crate) const ASM_BODY: &str = "This is the Autocrypt Setup Message \
226 used to transfer your end-to-end setup between clients.
227
228 To decrypt and use your setup, \
229 open the message in an Autocrypt-compliant client \
230 and enter the setup code presented on the generating device.
231
232 If you see this message in a chatmail client (Delta Chat, Arcane Chat, Delta Touch ...), \
233 use \"Settings / Add Second Device\" instead.";
234
235#[cfg(test)]
236mod tests {
237 use num_traits::FromPrimitive;
238
239 use super::*;
240
241 #[test]
242 fn test_chattype_values() {
243 assert_eq!(Chattype::Single, Chattype::from_i32(100).unwrap());
245 assert_eq!(Chattype::Group, Chattype::from_i32(120).unwrap());
246 assert_eq!(Chattype::Mailinglist, Chattype::from_i32(140).unwrap());
247 assert_eq!(Chattype::Broadcast, Chattype::from_i32(160).unwrap());
248 }
249
250 #[test]
251 fn test_showemails_values() {
252 assert_eq!(ShowEmails::All, ShowEmails::default());
254 assert_eq!(ShowEmails::Off, ShowEmails::from_i32(0).unwrap());
255 assert_eq!(
256 ShowEmails::AcceptedContacts,
257 ShowEmails::from_i32(1).unwrap()
258 );
259 assert_eq!(ShowEmails::All, ShowEmails::from_i32(2).unwrap());
260 }
261
262 #[test]
263 fn test_blocked_values() {
264 assert_eq!(Blocked::Not, Blocked::default());
266 assert_eq!(Blocked::Not, Blocked::from_i32(0).unwrap());
267 assert_eq!(Blocked::Yes, Blocked::from_i32(1).unwrap());
268 assert_eq!(Blocked::Request, Blocked::from_i32(2).unwrap());
269 }
270
271 #[test]
272 fn test_mediaquality_values() {
273 assert_eq!(MediaQuality::Balanced, MediaQuality::default());
275 assert_eq!(MediaQuality::Balanced, MediaQuality::from_i32(0).unwrap());
276 assert_eq!(MediaQuality::Worse, MediaQuality::from_i32(1).unwrap());
277 }
278
279 #[test]
280 fn test_videochattype_values() {
281 assert_eq!(VideochatType::Unknown, VideochatType::default());
283 assert_eq!(VideochatType::Unknown, VideochatType::from_i32(0).unwrap());
284 assert_eq!(
285 VideochatType::BasicWebrtc,
286 VideochatType::from_i32(1).unwrap()
287 );
288 assert_eq!(VideochatType::Jitsi, VideochatType::from_i32(2).unwrap());
289 }
290}