mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 10:26:29 +03:00
Start autodelete timer when message is displayed
This commit is contained in:
@@ -133,6 +133,36 @@ impl MsgId {
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns autodelete timer value for the message.
|
||||
pub(crate) fn autodelete_timer(self, context: &Context) -> sql::Result<Option<i64>> {
|
||||
let res = match context.sql.query_get_value_result(
|
||||
"SELECT autodelete_timer FROM msgs WHERE id=?",
|
||||
params![self],
|
||||
)? {
|
||||
None | Some(0) => None,
|
||||
Some(timer) => Some(timer),
|
||||
};
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// Starts autodelete timer for the message if it is not started yet.
|
||||
pub(crate) fn start_autodelete_timer(self, context: &Context) -> sql::Result<()> {
|
||||
if let Some(autodelete_timer) = self.autodelete_timer(context)? {
|
||||
let autodelete_timestamp = time() + autodelete_timer;
|
||||
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE msgs SET autodelete_timestamp = ? \
|
||||
WHERE (autodelete_timestamp == 0 OR autodelete_timestamp > ?) \
|
||||
AND id = ?",
|
||||
params![autodelete_timestamp, autodelete_timestamp, self],
|
||||
)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Bad evil escape hatch.
|
||||
///
|
||||
/// Avoid using this, eventually types should be cleaned up enough
|
||||
@@ -1077,6 +1107,14 @@ pub fn markseen_msgs(context: &Context, msg_ids: &[MsgId]) -> bool {
|
||||
let msgs = msgs.unwrap_or_default();
|
||||
|
||||
for (id, curr_state, curr_blocked) in msgs.into_iter() {
|
||||
if let Err(err) = id.start_autodelete_timer(context) {
|
||||
warn!(
|
||||
context,
|
||||
"Failed to start autodelete timer for message {}: {}", id, err
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if curr_blocked == Blocked::Not {
|
||||
if curr_state == MessageState::InFresh || curr_state == MessageState::InNoticed {
|
||||
update_msg_state(context, *id, MessageState::InSeen);
|
||||
|
||||
Reference in New Issue
Block a user