Do ephemeral deletion in async task background loop (#3194)

* Do ephemeral deletion in background loop

1. in start_io start ephemeral async task, in stop_io cancel ephemeral async task

2. start ephemeral async task which loops like this:

- wait until next time a message deletion is needed or an interrupt occurs (see 3.)
- perform delete_expired_messages including sending MSGS_CHANGED events

3. on new messages (incoming or outgoing) with ephemeral timer:

- interrupt ephemeral async task

* Changelog

* Fix and improve test

* no return value needed

* address @link2xt review comments

* slight normalization: have only one place where we wait for interrupt_receiver

* simplify sql statement -- and don't exit the ephemeral_task if there is an sql problem but rather wait

* Remove now-unused `ephemeral_task` JoinHandle

The JoinHandle is now inside the Scheduler.

* fix clippy

* Revert accidental move of the line

* Add log

Co-authored-by: holger krekel <holger@merlinux.eu>
Co-authored-by: link2xt <link2xt@testrun.org>
This commit is contained in:
Hocuri
2022-04-10 12:22:47 +02:00
committed by GitHub
parent 6e3ec71c10
commit 2562c726e6
7 changed files with 113 additions and 113 deletions

View File

@@ -26,7 +26,7 @@ use crate::dc_tools::{
dc_create_smeared_timestamps, dc_get_abs_path, dc_gm2local_offset, improve_single_line_input,
time, IsNoneOrEmpty,
};
use crate::ephemeral::{delete_expired_messages, schedule_ephemeral_task, Timer as EphemeralTimer};
use crate::ephemeral::Timer as EphemeralTimer;
use crate::events::EventType;
use crate::html::new_html_mimepart;
use crate::job::{self, Action};
@@ -1428,7 +1428,6 @@ impl Chat {
],
)
.await?;
schedule_ephemeral_task(context).await;
msg.id = update_msg_id;
} else {
let raw_id = context
@@ -1478,7 +1477,7 @@ impl Chat {
.await?;
msg.id = MsgId::new(u32::try_from(raw_id)?);
}
schedule_ephemeral_task(context).await;
context.interrupt_ephemeral_task().await;
Ok(msg.id)
}
}
@@ -2206,23 +2205,6 @@ pub async fn get_chat_msgs(
flags: u32,
marker1before: Option<MsgId>,
) -> Result<Vec<ChatItem>> {
match delete_expired_messages(context).await {
Err(err) => warn!(context, "Failed to delete expired messages: {}", err),
Ok(messages_deleted) => {
if messages_deleted {
// Trigger reload of chatlist.
//
// On desktop chatlist is always shown on the side,
// and it is important to update the last message shown
// there.
context.emit_event(EventType::MsgsChanged {
msg_id: MsgId::new(0),
chat_id: ChatId::new(0),
})
}
}
}
let process_row = if (flags & DC_GCM_INFO_ONLY) != 0 {
|row: &rusqlite::Row| {
// is_info logic taken from Message.is_info()