From 8d41d023974e967825148bbe8c288b34f33ee31b Mon Sep 17 00:00:00 2001 From: iequidoo Date: Thu, 7 Dec 2023 21:45:31 -0300 Subject: [PATCH] fix: calc_sort_timestamp: Skip messages that mustn't affect sorting of a new message (#5088) Drafts mustn't affect sorting of any other messages, they aren't even displayed in the chat window. Also hidden messages mustn't affect sorting of usual messages. But let hidden messages sort together with protection messages because hidden messages also can be or not be verified, so let's preserve this information -- even it's not useful currently, it can be useful in the future versions. --- src/receive_imf.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 2c224d17b..de89ddf2b 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1501,8 +1501,8 @@ pub(crate) async fn calc_sort_timestamp( context .sql .query_get_value( - "SELECT MAX(timestamp) FROM msgs WHERE chat_id=?", - (chat_id,), + "SELECT MAX(timestamp) FROM msgs WHERE chat_id=? AND state!=?", + (chat_id, MessageState::OutDraft), ) .await? } else if incoming { @@ -1517,7 +1517,7 @@ pub(crate) async fn calc_sort_timestamp( context .sql .query_get_value( - "SELECT MAX(timestamp) FROM msgs WHERE chat_id=? AND state>?", + "SELECT MAX(timestamp) FROM msgs WHERE chat_id=? AND hidden=0 AND state>?", (chat_id, MessageState::InFresh), ) .await?