From ee68b9c7ba2e32c7e864957a0d3083f7570e1104 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Fri, 21 Mar 2025 15:06:30 +0100 Subject: [PATCH] refactor: Use chat_id.get_timestamp() instead of duplicating its code (#6691) --- src/chat.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 121875984..b87348e12 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1080,7 +1080,8 @@ impl ChatId { .unwrap_or(0)) } - /// Returns timestamp of the latest message in the chat. + /// Returns timestamp of the latest message in the chat, + /// including hidden messages or a draft if there is one. pub(crate) async fn get_timestamp(self, context: &Context) -> Result> { let timestamp = context .sql @@ -4608,17 +4609,7 @@ pub async fn add_device_msg_with_importance( // makes sure, the added message is the last one, // even if the date is wrong (useful esp. when warning about bad dates) let mut timestamp_sort = timestamp_sent; - if let Some(last_msg_time) = context - .sql - .query_get_value( - "SELECT MAX(timestamp) - FROM msgs - WHERE chat_id=? - HAVING COUNT(*) > 0", - (chat_id,), - ) - .await? - { + if let Some(last_msg_time) = chat_id.get_timestamp(context).await? { if timestamp_sort <= last_msg_time { timestamp_sort = last_msg_time + 1; }