Start ephemeral timer for non-fresh messages

This commit is contained in:
Alexander Krotov
2020-07-13 01:16:34 +03:00
parent 0da21aa9f6
commit d54ade5891

View File

@@ -689,14 +689,9 @@ async fn add_parts(
// correct message_timestamp, it should not be used before,
// however, we cannot do this earlier as we need from_id to be set
let in_fresh = state == MessageState::InFresh;
let rcvd_timestamp = time();
let sort_timestamp = calc_sort_timestamp(
context,
*sent_timestamp,
*chat_id,
state == MessageState::InFresh,
)
.await;
let sort_timestamp = calc_sort_timestamp(context, *sent_timestamp, *chat_id, in_fresh).await;
*sent_timestamp = std::cmp::min(*sent_timestamp, rcvd_timestamp);
// unarchive chat
@@ -748,8 +743,8 @@ async fn add_parts(
"INSERT INTO msgs \
(rfc724_mid, server_folder, server_uid, chat_id, from_id, to_id, timestamp, \
timestamp_sent, timestamp_rcvd, type, state, msgrmsg, txt, txt_raw, param, \
bytes, hidden, mime_headers, mime_in_reply_to, mime_references, error, ephemeral_timer) \
VALUES (?,?,?,?,?,?, ?,?,?,?,?,?, ?,?,?,?,?,?, ?,?, ?,?);",
bytes, hidden, mime_headers, mime_in_reply_to, mime_references, error, ephemeral_timer, ephemeral_timestamp) \
VALUES (?,?,?,?,?,?, ?,?,?,?,?,?, ?,?,?,?,?,?, ?,?, ?,?,?);",
)?;
let is_location_kml = location_kml_is
@@ -771,6 +766,15 @@ async fn add_parts(
part.param.set_int(Param::Cmd, is_system_message as i32);
}
let ephemeral_timestamp = if in_fresh {
0
} else {
match ephemeral_timer {
EphemeralTimer::Disabled => 0,
EphemeralTimer::Enabled { duration } => rcvd_timestamp + i64::from(duration)
}
};
stmt.execute(paramsv![
rfc724_mid,
server_folder,
@@ -794,7 +798,8 @@ async fn add_parts(
mime_in_reply_to,
mime_references,
part.error,
ephemeral_timer
ephemeral_timer,
ephemeral_timestamp
])?;
drop(stmt);