mirror of
https://github.com/chatmail/core.git
synced 2026-09-22 13:01:21 +03:00
refactor: turn DC_MSG_ID_* into MsgId::* associated constants
This commit is contained in:
@@ -130,9 +130,6 @@ pub enum Chattype {
|
||||
InBroadcast = 165,
|
||||
}
|
||||
|
||||
pub const DC_MSG_ID_DAYMARKER: u32 = 9;
|
||||
pub const DC_MSG_ID_LAST_SPECIAL: u32 = 9;
|
||||
|
||||
/// String that indicates that something is left out or truncated.
|
||||
pub(crate) const DC_ELLIPSIS: &str = "[...]";
|
||||
// how many lines desktop can display when fullscreen (fullscreen at zoomlevel 1x)
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::collections::BTreeSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str;
|
||||
|
||||
use anyhow::{Context as _, Result, ensure, format_err};
|
||||
use anyhow::{Context as _, Result, ensure};
|
||||
use deltachat_contact_tools::{VcardContact, parse_vcard};
|
||||
use deltachat_derive::{FromSql, ToSql};
|
||||
use humansize::BINARY;
|
||||
@@ -17,7 +17,7 @@ use crate::blob::BlobObject;
|
||||
use crate::chat::{Chat, ChatId, ChatIdBlocked, ChatVisibility, send_msg};
|
||||
use crate::chatlist_events;
|
||||
use crate::config::Config;
|
||||
use crate::constants::{Blocked, Chattype, DC_MSG_ID_LAST_SPECIAL};
|
||||
use crate::constants::{Blocked, Chattype};
|
||||
use crate::contact::{self, Contact, ContactId};
|
||||
use crate::context::Context;
|
||||
use crate::debug_logging::set_debug_logging_xdc;
|
||||
@@ -49,13 +49,18 @@ use crate::tools::{
|
||||
pub struct MsgId(u32);
|
||||
|
||||
impl MsgId {
|
||||
/// Markers added before each day in a local timezone.
|
||||
pub const DAYMARKER: MsgId = MsgId::new(9);
|
||||
/// Largest reserved message ID.
|
||||
pub const LAST_SPECIAL: MsgId = MsgId::new(9);
|
||||
|
||||
/// Create a new [MsgId].
|
||||
pub fn new(id: u32) -> MsgId {
|
||||
pub const fn new(id: u32) -> MsgId {
|
||||
MsgId(id)
|
||||
}
|
||||
|
||||
/// Create a new unset [MsgId].
|
||||
pub fn new_unset() -> MsgId {
|
||||
pub const fn new_unset() -> MsgId {
|
||||
MsgId(0)
|
||||
}
|
||||
|
||||
@@ -63,7 +68,7 @@ impl MsgId {
|
||||
///
|
||||
/// This kind of message ID can not be used for real messages.
|
||||
pub fn is_special(self) -> bool {
|
||||
self.0 <= DC_MSG_ID_LAST_SPECIAL
|
||||
(0..=Self::LAST_SPECIAL.0).contains(&self.0)
|
||||
}
|
||||
|
||||
/// Whether the message ID is unset.
|
||||
@@ -355,18 +360,8 @@ impl std::fmt::Display for MsgId {
|
||||
/// Allow converting [MsgId] to an SQLite type.
|
||||
///
|
||||
/// This allows you to directly store [MsgId] into the database.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This **does** ensure that no special message IDs are written into
|
||||
/// the database and the conversion will fail if this is not the case.
|
||||
impl rusqlite::types::ToSql for MsgId {
|
||||
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
|
||||
if self.0 <= DC_MSG_ID_LAST_SPECIAL {
|
||||
return Err(rusqlite::Error::ToSqlConversionFailure(
|
||||
format_err!("Invalid MsgId {}", self.0).into(),
|
||||
));
|
||||
}
|
||||
let val = rusqlite::types::Value::Integer(i64::from(self.0));
|
||||
let out = rusqlite::types::ToSqlOutput::Owned(val);
|
||||
Ok(out)
|
||||
@@ -2106,7 +2101,7 @@ pub async fn estimate_deletion_cnt(
|
||||
AND chat_id != ?3
|
||||
AND chat_id != ?4 AND hidden = 0;",
|
||||
(
|
||||
DC_MSG_ID_LAST_SPECIAL,
|
||||
MsgId::LAST_SPECIAL,
|
||||
threshold_timestamp,
|
||||
self_chat_id,
|
||||
ChatId::TRASH,
|
||||
|
||||
Reference in New Issue
Block a user