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,8 +1601,12 @@ 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 threshold_timestamp = match context.get_config_delete_device_after() {
None => 0,
Some(delete_device_after) => now - delete_device_after,
};
let self_chat_id = lookup_by_contact_id(context, DC_CONTACT_ID_SELF) let self_chat_id = lookup_by_contact_id(context, DC_CONTACT_ID_SELF)
.unwrap_or_default() .unwrap_or_default()
@@ -1618,23 +1622,31 @@ pub fn delete_device_expired_messages(context: &Context) -> Result<bool, Error>
let rows_modified = context.sql.execute( let rows_modified = context.sql.execute(
"UPDATE msgs \ "UPDATE msgs \
SET txt = 'DELETED', chat_id = ? \ SET txt = 'DELETED', chat_id = ? \
WHERE timestamp < ? \ WHERE \
AND chat_id > ? \ ( \
( \
timestamp < ? \
AND chat_id != ? \ AND chat_id != ? \
) \
OR \
( \
autodelete_timestamp != 0 \
AND autodelete_timestamp < ? \
) \
) \
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,
DC_CHAT_ID_LAST_SPECIAL,
device_chat_id device_chat_id
], ],
)?; )?;
Ok(rows_modified > 0) Ok(rows_modified > 0)
} else {
Ok(false)
}
} }
pub fn get_chat_media( pub fn get_chat_media(