mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Move delete_device_expired_messages() to ChatId
This allows to check if chat is a self-talk or device chat. Messages are deleted only in viewed chats now.
This commit is contained in:
42
src/chat.rs
42
src/chat.rs
@@ -378,6 +378,28 @@ impl ChatId {
|
|||||||
Ok(self.get_param(context)?.exists(Param::Devicetalk))
|
Ok(self.get_param(context)?.exists(Param::Devicetalk))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Hides or deletes messages which are expired according to
|
||||||
|
/// "delete_device_after" setting.
|
||||||
|
pub fn delete_device_expired_messages(self, context: &Context) -> Result<(), Error> {
|
||||||
|
if self.is_special() || self.is_self_talk(context)? || self.is_device_talk(context)? {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(delete_device_after) = context.get_config_delete_device_after() {
|
||||||
|
let threshold_timestamp = time() - delete_device_after;
|
||||||
|
|
||||||
|
// Hide expired messages
|
||||||
|
context.sql.execute(
|
||||||
|
"UPDATE msgs \
|
||||||
|
SET txt = 'DELETED', hidden = 1 \
|
||||||
|
WHERE timestamp < ? \
|
||||||
|
AND chat_id == ?",
|
||||||
|
params![threshold_timestamp, self],
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Bad evil escape hatch.
|
/// Bad evil escape hatch.
|
||||||
///
|
///
|
||||||
/// Avoid using this, eventually types should be cleaned up enough
|
/// Avoid using this, eventually types should be cleaned up enough
|
||||||
@@ -1466,7 +1488,7 @@ pub fn get_chat_msgs(
|
|||||||
flags: u32,
|
flags: u32,
|
||||||
marker1before: Option<MsgId>,
|
marker1before: Option<MsgId>,
|
||||||
) -> Vec<MsgId> {
|
) -> Vec<MsgId> {
|
||||||
if let Err(err) = delete_device_expired_messages(context) {
|
if let Err(err) = chat_id.delete_device_expired_messages(context) {
|
||||||
warn!(context, "Failed to delete expired messages: {}", err);
|
warn!(context, "Failed to delete expired messages: {}", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2531,24 +2553,6 @@ pub(crate) fn add_info_msg(context: &Context, chat_id: ChatId, text: impl AsRef<
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hides or deletes messages which are expired according to
|
|
||||||
/// "delete_device_after" setting.
|
|
||||||
pub fn delete_device_expired_messages(context: &Context) -> sql::Result<()> {
|
|
||||||
if let Some(delete_device_after) = context.get_config_delete_device_after() {
|
|
||||||
let threshold_timestamp = time() - delete_device_after;
|
|
||||||
|
|
||||||
// Hide expired messages
|
|
||||||
context.sql.execute(
|
|
||||||
"UPDATE msgs \
|
|
||||||
SET txt = 'DELETED', hidden = 1 \
|
|
||||||
WHERE timestamp < ? \
|
|
||||||
AND chat_id > ?",
|
|
||||||
params![threshold_timestamp, DC_CHAT_ID_LAST_SPECIAL],
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user