From 1d9702e9e77cfe559baf59c343e5021d405a18b8 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 7 Jan 2023 13:35:16 +0000 Subject: [PATCH] refactor: add ChatId::get_timestamp() --- src/chat.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 33fb6d88e..a1e3b9f86 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -871,6 +871,15 @@ impl ChatId { Ok(count) } + /// Returns timestamp of the latest message in the chat. + pub(crate) async fn get_timestamp(self, context: &Context) -> Result> { + let timestamp = context + .sql + .query_get_value("SELECT MAX(timestamp) FROM msgs WHERE chat_id=?", (self,)) + .await?; + Ok(timestamp) + } + pub(crate) async fn get_param(self, context: &Context) -> Result { let res: Option = context .sql @@ -2575,14 +2584,7 @@ pub(crate) async fn marknoticed_chat_if_older_than( chat_id: ChatId, timestamp: i64, ) -> Result<()> { - if let Some(chat_timestamp) = context - .sql - .query_get_value( - "SELECT MAX(timestamp) FROM msgs WHERE chat_id=?", - (chat_id,), - ) - .await? - { + if let Some(chat_timestamp) = chat_id.get_timestamp(context).await? { if timestamp > chat_timestamp { marknoticed_chat(context, chat_id).await?; }