Delete autodelete-expired messages locally

This commit is contained in:
Alexander Krotov
2020-05-12 22:52:34 +03:00
parent b54c2a3196
commit 5523e7ba19

View File

@@ -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 /// Returns true if any message is deleted, so event can be emitted. If nothing
/// has been deleted, returns false. /// has been deleted, returns false.
pub fn delete_device_expired_messages(context: &Context) -> Result<bool, Error> { pub fn delete_device_expired_messages(context: &Context) -> Result<bool, Error> {
if let Some(delete_device_after) = context.get_config_delete_device_after() { let now = time();
let threshold_timestamp = time() - delete_device_after;
let self_chat_id = lookup_by_contact_id(context, DC_CONTACT_ID_SELF) let threshold_timestamp = match context.get_config_delete_device_after() {
.unwrap_or_default() None => 0,
.0; Some(delete_device_after) => now - delete_device_after,
let device_chat_id = lookup_by_contact_id(context, DC_CONTACT_ID_DEVICE) };
.unwrap_or_default()
.0;
// Delete expired messages let self_chat_id = lookup_by_contact_id(context, DC_CONTACT_ID_SELF)
// .unwrap_or_default()
// Only update the rows that have to be updated, to avoid emitting .0;
// unnecessary "chat modified" events. let device_chat_id = lookup_by_contact_id(context, DC_CONTACT_ID_DEVICE)
let rows_modified = context.sql.execute( .unwrap_or_default()
"UPDATE msgs \ .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 = ? \ 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 != ? \
AND chat_id != ?", AND chat_id != ?",
params![ params![
DC_CHAT_ID_TRASH, DC_CHAT_ID_TRASH,
threshold_timestamp, threshold_timestamp,
DC_CHAT_ID_LAST_SPECIAL, self_chat_id,
self_chat_id, now,
device_chat_id DC_CHAT_ID_LAST_SPECIAL,
], device_chat_id
)?; ],
)?;
Ok(rows_modified > 0) Ok(rows_modified > 0)
} else {
Ok(false)
}
} }
pub fn get_chat_media( pub fn get_chat_media(