Skip to content

Commit ee68b9c

Browse files
authored
refactor: Use chat_id.get_timestamp() instead of duplicating its code (#6691)
1 parent a51b2fa commit ee68b9c

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/chat.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,8 @@ impl ChatId {
10801080
.unwrap_or(0))
10811081
}
10821082

1083-
/// Returns timestamp of the latest message in the chat.
1083+
/// Returns timestamp of the latest message in the chat,
1084+
/// including hidden messages or a draft if there is one.
10841085
pub(crate) async fn get_timestamp(self, context: &Context) -> Result<Option<i64>> {
10851086
let timestamp = context
10861087
.sql
@@ -4608,17 +4609,7 @@ pub async fn add_device_msg_with_importance(
46084609
// makes sure, the added message is the last one,
46094610
// even if the date is wrong (useful esp. when warning about bad dates)
46104611
let mut timestamp_sort = timestamp_sent;
4611-
if let Some(last_msg_time) = context
4612-
.sql
4613-
.query_get_value(
4614-
"SELECT MAX(timestamp)
4615-
FROM msgs
4616-
WHERE chat_id=?
4617-
HAVING COUNT(*) > 0",
4618-
(chat_id,),
4619-
)
4620-
.await?
4621-
{
4612+
if let Some(last_msg_time) = chat_id.get_timestamp(context).await? {
46224613
if timestamp_sort <= last_msg_time {
46234614
timestamp_sort = last_msg_time + 1;
46244615
}

0 commit comments

Comments
 (0)