mirror of
https://github.com/chatmail/core.git
synced 2026-04-24 17:06:28 +03:00
Delete autodelete-expired messages locally
This commit is contained in:
68
src/chat.rs
68
src/chat.rs
@@ -1601,40 +1601,52 @@ pub fn marknoticed_all_chats(context: &Context) -> Result<(), Error> {
|
||||
/// Returns true if any message is deleted, so event can be emitted. If nothing
|
||||
/// has been deleted, returns false.
|
||||
pub fn delete_device_expired_messages(context: &Context) -> Result<bool, Error> {
|
||||
if let Some(delete_device_after) = context.get_config_delete_device_after() {
|
||||
let threshold_timestamp = time() - delete_device_after;
|
||||
let now = time();
|
||||
|
||||
let self_chat_id = lookup_by_contact_id(context, DC_CONTACT_ID_SELF)
|
||||
.unwrap_or_default()
|
||||
.0;
|
||||
let device_chat_id = lookup_by_contact_id(context, DC_CONTACT_ID_DEVICE)
|
||||
.unwrap_or_default()
|
||||
.0;
|
||||
let threshold_timestamp = match context.get_config_delete_device_after() {
|
||||
None => 0,
|
||||
Some(delete_device_after) => now - delete_device_after,
|
||||
};
|
||||
|
||||
// Delete expired messages
|
||||
//
|
||||
// Only update the rows that have to be updated, to avoid emitting
|
||||
// unnecessary "chat modified" events.
|
||||
let rows_modified = context.sql.execute(
|
||||
"UPDATE msgs \
|
||||
let self_chat_id = lookup_by_contact_id(context, DC_CONTACT_ID_SELF)
|
||||
.unwrap_or_default()
|
||||
.0;
|
||||
let device_chat_id = lookup_by_contact_id(context, DC_CONTACT_ID_DEVICE)
|
||||
.unwrap_or_default()
|
||||
.0;
|
||||
|
||||
// Delete expired messages
|
||||
//
|
||||
// Only update the rows that have to be updated, to avoid emitting
|
||||
// unnecessary "chat modified" events.
|
||||
let rows_modified = context.sql.execute(
|
||||
"UPDATE msgs \
|
||||
SET txt = 'DELETED', chat_id = ? \
|
||||
WHERE timestamp < ? \
|
||||
WHERE \
|
||||
( \
|
||||
( \
|
||||
timestamp < ? \
|
||||
AND chat_id != ? \
|
||||
) \
|
||||
OR \
|
||||
( \
|
||||
autodelete_timestamp != 0 \
|
||||
AND autodelete_timestamp < ? \
|
||||
) \
|
||||
) \
|
||||
AND chat_id > ? \
|
||||
AND chat_id != ? \
|
||||
AND chat_id != ?",
|
||||
params![
|
||||
DC_CHAT_ID_TRASH,
|
||||
threshold_timestamp,
|
||||
DC_CHAT_ID_LAST_SPECIAL,
|
||||
self_chat_id,
|
||||
device_chat_id
|
||||
],
|
||||
)?;
|
||||
params![
|
||||
DC_CHAT_ID_TRASH,
|
||||
threshold_timestamp,
|
||||
self_chat_id,
|
||||
now,
|
||||
DC_CHAT_ID_LAST_SPECIAL,
|
||||
device_chat_id
|
||||
],
|
||||
)?;
|
||||
|
||||
Ok(rows_modified > 0)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
Ok(rows_modified > 0)
|
||||
}
|
||||
|
||||
pub fn get_chat_media(
|
||||
|
||||
Reference in New Issue
Block a user