mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 05:46:30 +03:00
Start ephemeral timers during housekeeping
This commit is contained in:
committed by
link2xt
parent
bb9603661a
commit
1b5d08e6ee
@@ -64,7 +64,7 @@ use crate::context::Context;
|
|||||||
use crate::dc_tools::time;
|
use crate::dc_tools::time;
|
||||||
use crate::error::{ensure, Error};
|
use crate::error::{ensure, Error};
|
||||||
use crate::events::Event;
|
use crate::events::Event;
|
||||||
use crate::message::{Message, MsgId};
|
use crate::message::{Message, MessageState, MsgId};
|
||||||
use crate::mimeparser::SystemMessage;
|
use crate::mimeparser::SystemMessage;
|
||||||
use crate::sql;
|
use crate::sql;
|
||||||
use crate::stock::StockMessage;
|
use crate::stock::StockMessage;
|
||||||
@@ -422,6 +422,36 @@ pub(crate) async fn load_imap_deletion_msgid(context: &Context) -> sql::Result<O
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Start ephemeral timers for seen messages if they are not started
|
||||||
|
/// yet.
|
||||||
|
///
|
||||||
|
/// It is possible that timers are not started due to a missing or
|
||||||
|
/// failed `MsgId.start_ephemeral_timer()` call, either in the current
|
||||||
|
/// or previous version of Delta Chat.
|
||||||
|
///
|
||||||
|
/// This function is supposed to be called in the background,
|
||||||
|
/// e.g. from housekeeping task.
|
||||||
|
pub(crate) async fn start_ephemeral_timers(context: &Context) -> sql::Result<()> {
|
||||||
|
context
|
||||||
|
.sql
|
||||||
|
.execute(
|
||||||
|
"UPDATE msgs \
|
||||||
|
SET ephemeral_timestamp = ? + ephemeral_timer \
|
||||||
|
WHERE ephemeral_timer > 0 \
|
||||||
|
AND ephemeral_timestamp = 0 \
|
||||||
|
AND state NOT IN (?, ?, ?)",
|
||||||
|
paramsv![
|
||||||
|
time(),
|
||||||
|
MessageState::InFresh,
|
||||||
|
MessageState::InNoticed,
|
||||||
|
MessageState::OutDraft
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use crate::chat::{update_device_icon, update_saved_messages_icon};
|
|||||||
use crate::constants::{ShowEmails, DC_CHAT_ID_TRASH};
|
use crate::constants::{ShowEmails, DC_CHAT_ID_TRASH};
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::dc_tools::*;
|
use crate::dc_tools::*;
|
||||||
|
use crate::ephemeral::start_ephemeral_timers;
|
||||||
use crate::param::*;
|
use crate::param::*;
|
||||||
use crate::peerstate::*;
|
use crate::peerstate::*;
|
||||||
|
|
||||||
@@ -568,6 +569,13 @@ pub async fn housekeeping(context: &Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Err(err) = start_ephemeral_timers(context).await {
|
||||||
|
warn!(
|
||||||
|
context,
|
||||||
|
"Housekeeping: cannot start ephemeral timers: {}", err
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if let Err(err) = prune_tombstones(context).await {
|
if let Err(err) = prune_tombstones(context).await {
|
||||||
warn!(
|
warn!(
|
||||||
context,
|
context,
|
||||||
|
|||||||
Reference in New Issue
Block a user