mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
Merge pull request #1411 from deltachat/delete-no-hide
Delete expired messages instead of hiding them
This commit is contained in:
15
src/chat.rs
15
src/chat.rs
@@ -1441,7 +1441,7 @@ pub fn get_chat_msgs(
|
|||||||
flags: u32,
|
flags: u32,
|
||||||
marker1before: Option<MsgId>,
|
marker1before: Option<MsgId>,
|
||||||
) -> Vec<MsgId> {
|
) -> Vec<MsgId> {
|
||||||
match hide_device_expired_messages(context) {
|
match delete_device_expired_messages(context) {
|
||||||
Err(err) => warn!(context, "Failed to delete expired messages: {}", err),
|
Err(err) => warn!(context, "Failed to delete expired messages: {}", err),
|
||||||
Ok(messages_deleted) => {
|
Ok(messages_deleted) => {
|
||||||
if messages_deleted {
|
if messages_deleted {
|
||||||
@@ -1587,11 +1587,11 @@ pub fn marknoticed_all_chats(context: &Context) -> Result<(), Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hides messages which are expired according to "delete_device_after" setting.
|
/// Deletes messages which are expired according to "delete_device_after" setting.
|
||||||
///
|
///
|
||||||
/// Returns true if any message is hidden, so event can be emitted. If nothing
|
/// Returns true if any message is deleted, so event can be emitted. If nothing
|
||||||
/// has been hidden, returns false.
|
/// has been deleted, returns false.
|
||||||
pub fn hide_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() {
|
if let Some(delete_device_after) = context.get_config_delete_device_after() {
|
||||||
let threshold_timestamp = time() - delete_device_after;
|
let threshold_timestamp = time() - delete_device_after;
|
||||||
|
|
||||||
@@ -1602,19 +1602,20 @@ pub fn hide_device_expired_messages(context: &Context) -> Result<bool, Error> {
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.0;
|
.0;
|
||||||
|
|
||||||
// Hide expired messages
|
// Delete expired messages
|
||||||
//
|
//
|
||||||
// Only update the rows that have to be updated, to avoid emitting
|
// Only update the rows that have to be updated, to avoid emitting
|
||||||
// unnecessary "chat modified" events.
|
// unnecessary "chat modified" events.
|
||||||
let rows_modified = context.sql.execute(
|
let rows_modified = context.sql.execute(
|
||||||
"UPDATE msgs \
|
"UPDATE msgs \
|
||||||
SET txt = 'DELETED', hidden = 1 \
|
SET txt = 'DELETED', chat_id = ? \
|
||||||
WHERE timestamp < ? \
|
WHERE timestamp < ? \
|
||||||
AND chat_id > ? \
|
AND chat_id > ? \
|
||||||
AND chat_id != ? \
|
AND chat_id != ? \
|
||||||
AND chat_id != ? \
|
AND chat_id != ? \
|
||||||
AND NOT hidden",
|
AND NOT hidden",
|
||||||
params![
|
params![
|
||||||
|
DC_CHAT_ID_TRASH,
|
||||||
threshold_timestamp,
|
threshold_timestamp,
|
||||||
DC_CHAT_ID_LAST_SPECIAL,
|
DC_CHAT_ID_LAST_SPECIAL,
|
||||||
self_chat_id,
|
self_chat_id,
|
||||||
|
|||||||
@@ -93,8 +93,8 @@ impl Chatlist {
|
|||||||
query_contact_id: Option<u32>,
|
query_contact_id: Option<u32>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
// Note that we do not emit DC_EVENT_MSGS_MODIFIED here even if some
|
// Note that we do not emit DC_EVENT_MSGS_MODIFIED here even if some
|
||||||
// messages get hidden to avoid reloading the same chatlist.
|
// messages get deleted to avoid reloading the same chatlist.
|
||||||
if let Err(err) = hide_device_expired_messages(context) {
|
if let Err(err) = delete_device_expired_messages(context) {
|
||||||
warn!(context, "Failed to hide expired messages: {}", err);
|
warn!(context, "Failed to hide expired messages: {}", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user