mirror of
https://github.com/chatmail/core.git
synced 2026-10-03 03:30:36 +03:00
refactor: turn DC_CHAT_ID_* into ChatId::* associated constants
We already have it done for ContactId.
This commit is contained in:
+24
-17
@@ -22,9 +22,7 @@ use crate::chatlist_events;
|
||||
use crate::color::str_to_color;
|
||||
use crate::config::Config;
|
||||
use crate::constants::{
|
||||
self, Blocked, Chattype, DC_CHAT_ID_ALLDONE_HINT, DC_CHAT_ID_ARCHIVED_LINK,
|
||||
DC_CHAT_ID_LAST_SPECIAL, DC_CHAT_ID_TRASH, DC_RESEND_USER_AVATAR_DAYS, EDITED_PREFIX,
|
||||
TIMESTAMP_SENT_TOLERANCE,
|
||||
self, Blocked, Chattype, DC_RESEND_USER_AVATAR_DAYS, EDITED_PREFIX, TIMESTAMP_SENT_TOLERANCE,
|
||||
};
|
||||
use crate::contact::{self, Contact, ContactId, Origin};
|
||||
use crate::context::Context;
|
||||
@@ -135,6 +133,15 @@ impl fmt::Display for CantSendReason {
|
||||
pub struct ChatId(u32);
|
||||
|
||||
impl ChatId {
|
||||
/// messages that should be deleted get this chat_id; the messages are deleted from the working thread later then. This is also needed as rfc724_mid should be preset as long as the message is not deleted on the server (otherwise it is downloaded again)
|
||||
pub const TRASH: ChatId = ChatId::new(3);
|
||||
/// only an indicator in a chatlist
|
||||
pub const ARCHIVED_LINK: ChatId = ChatId::new(6);
|
||||
/// only an indicator in a chatlist
|
||||
pub const ALLDONE_HINT: ChatId = ChatId::new(7);
|
||||
/// larger chat IDs are "real" chats, their messages are "real" messages.
|
||||
pub const LAST_SPECIAL: ChatId = ChatId::new(9);
|
||||
|
||||
/// Create a new [ChatId].
|
||||
pub const fn new(id: u32) -> ChatId {
|
||||
ChatId(id)
|
||||
@@ -151,7 +158,7 @@ impl ChatId {
|
||||
///
|
||||
/// This kind of chat ID can not be used for real chats.
|
||||
pub fn is_special(self) -> bool {
|
||||
(0..=DC_CHAT_ID_LAST_SPECIAL.0).contains(&self.0)
|
||||
(0..=Self::LAST_SPECIAL.0).contains(&self.0)
|
||||
}
|
||||
|
||||
/// Chat ID for messages which need to be deleted.
|
||||
@@ -161,7 +168,7 @@ impl ChatId {
|
||||
/// as they are not deleted on the server so that their rfc724_mid
|
||||
/// remains known and downloading them again can be avoided.
|
||||
pub fn is_trash(self) -> bool {
|
||||
self == DC_CHAT_ID_TRASH
|
||||
self == Self::TRASH
|
||||
}
|
||||
|
||||
/// Chat ID signifying there are **any** number of archived chats.
|
||||
@@ -171,7 +178,7 @@ impl ChatId {
|
||||
///
|
||||
/// [`Chatlist`]: crate::chatlist::Chatlist
|
||||
pub fn is_archived_link(self) -> bool {
|
||||
self == DC_CHAT_ID_ARCHIVED_LINK
|
||||
self == Self::ARCHIVED_LINK
|
||||
}
|
||||
|
||||
/// Virtual chat ID signalling there are **only** archived chats.
|
||||
@@ -183,12 +190,12 @@ impl ChatId {
|
||||
/// [`DC_GCL_ADD_ALLDONE_HINT`]: crate::constants::DC_GCL_ADD_ALLDONE_HINT
|
||||
/// [`Chatlist`]: crate::chatlist::Chatlist
|
||||
pub fn is_alldone_hint(self) -> bool {
|
||||
self == DC_CHAT_ID_ALLDONE_HINT
|
||||
self == Self::ALLDONE_HINT
|
||||
}
|
||||
|
||||
/// Returns [`ChatId`] of a chat that `msg` belongs to.
|
||||
pub(crate) fn lookup_by_message(msg: &Message) -> Option<Self> {
|
||||
if msg.chat_id == DC_CHAT_ID_TRASH {
|
||||
if msg.chat_id == Self::TRASH {
|
||||
return None;
|
||||
}
|
||||
if msg.download_state == DownloadState::Undecipherable {
|
||||
@@ -578,7 +585,7 @@ impl ChatId {
|
||||
/// `msg_state` is the state of the message. Matters only for incoming messages currently. For
|
||||
/// multiple outgoing messages the function may be called once with MessageState::Undefined.
|
||||
/// Sending an appropriate event is up to the caller.
|
||||
/// Also emits DC_EVENT_MSGS_CHANGED for DC_CHAT_ID_ARCHIVED_LINK when the number of archived
|
||||
/// Also emits DC_EVENT_MSGS_CHANGED for ChatId::ARCHIVED_LINK when the number of archived
|
||||
/// chats with unread messages increases (which is possible if the chat is muted).
|
||||
pub async fn unarchive_if_not_muted(
|
||||
self,
|
||||
@@ -614,7 +621,7 @@ impl ChatId {
|
||||
.await?;
|
||||
if unread_cnt == 1 {
|
||||
// Added the first unread message in the chat.
|
||||
context.emit_msgs_changed_without_msg_id(DC_CHAT_ID_ARCHIVED_LINK);
|
||||
context.emit_msgs_changed_without_msg_id(ChatId::ARCHIVED_LINK);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
@@ -680,7 +687,7 @@ impl ChatId {
|
||||
INSERT OR REPLACE INTO msgs (id, rfc724_mid, pre_rfc724_mid, timestamp, chat_id, deleted)
|
||||
SELECT id, rfc724_mid, pre_rfc724_mid, timestamp, ?, 1 FROM msgs WHERE chat_id=?
|
||||
",
|
||||
(DC_CHAT_ID_TRASH, self),
|
||||
(ChatId::TRASH, self),
|
||||
)?;
|
||||
transaction.execute("DELETE FROM chats_contacts WHERE chat_id=?", (self,))?;
|
||||
transaction.execute("DELETE FROM chats WHERE id=?", (self,))?;
|
||||
@@ -1011,7 +1018,7 @@ SELECT id, rfc724_mid, pre_rfc724_mid, timestamp, ?, 1 FROM msgs WHERE chat_id=?
|
||||
AND y.chat_id<>x.chat_id
|
||||
AND y.chat_id>?
|
||||
GROUP BY y.chat_id",
|
||||
(self, DC_CHAT_ID_LAST_SPECIAL),
|
||||
(self, ChatId::LAST_SPECIAL),
|
||||
|row| {
|
||||
let chat_id: ChatId = row.get(0)?;
|
||||
let intersection: f64 = row.get(1)?;
|
||||
@@ -1029,7 +1036,7 @@ SELECT id, rfc724_mid, pre_rfc724_mid, timestamp, ?, 1 FROM msgs WHERE chat_id=?
|
||||
WHERE contact_id > ? AND chat_id > ?
|
||||
AND add_timestamp >= remove_timestamp
|
||||
GROUP BY chat_id",
|
||||
(ContactId::LAST_SPECIAL, DC_CHAT_ID_LAST_SPECIAL),
|
||||
(ContactId::LAST_SPECIAL, ChatId::LAST_SPECIAL),
|
||||
|row| {
|
||||
let chat_id: ChatId = row.get(0)?;
|
||||
let size: f64 = row.get(1)?;
|
||||
@@ -2369,7 +2376,7 @@ impl ChatIdBlocked {
|
||||
INNER JOIN chats_contacts j
|
||||
ON c.id=j.chat_id
|
||||
WHERE c.type=100 -- 100 = Chattype::Single
|
||||
AND c.id>9 -- 9 = DC_CHAT_ID_LAST_SPECIAL
|
||||
AND c.id>9 -- 9 = ChatId::LAST_SPECIAL
|
||||
AND j.contact_id=?;",
|
||||
(contact_id,),
|
||||
|row| {
|
||||
@@ -3489,7 +3496,7 @@ pub async fn get_chat_media(
|
||||
(
|
||||
chat_id.is_none(),
|
||||
chat_id.unwrap_or_else(|| ChatId::new(0)),
|
||||
DC_CHAT_ID_TRASH,
|
||||
ChatId::TRASH,
|
||||
Viewtype::Webxdc,
|
||||
),
|
||||
|row| {
|
||||
@@ -3512,7 +3519,7 @@ pub async fn get_chat_media(
|
||||
(
|
||||
chat_id.is_none(),
|
||||
chat_id.unwrap_or_else(|| ChatId::new(0)),
|
||||
DC_CHAT_ID_TRASH,
|
||||
ChatId::TRASH,
|
||||
msg_type,
|
||||
if msg_type2 != Viewtype::Unknown {
|
||||
msg_type2
|
||||
@@ -5384,7 +5391,7 @@ impl Context {
|
||||
/// a noticed chat is archived. Emitting events should be cheap, a false-positive `MsgsChanged`
|
||||
/// is ok.
|
||||
pub(crate) fn on_archived_chats_maybe_noticed(&self) {
|
||||
self.emit_msgs_changed_without_msg_id(DC_CHAT_ID_ARCHIVED_LINK);
|
||||
self.emit_msgs_changed_without_msg_id(ChatId::ARCHIVED_LINK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user