fix: never sort the message before chat creation timestamp

This commit is contained in:
link2xt
2026-03-27 22:51:27 +01:00
parent aebec1ec0d
commit ae7b12a32c

View File

@@ -930,6 +930,17 @@ SELECT id, rfc724_mid, pre_rfc724_mid, timestamp, ?, 1 FROM msgs WHERE chat_id=?
.unwrap_or(0)) .unwrap_or(0))
} }
/// Returns timestamp of us joining the chat if we are the member of the chat.
pub(crate) async fn join_timestamp(self, context: &Context) -> Result<Option<i64>> {
context
.sql
.query_get_value(
"SELECT add_timestamp FROM chats_contacts WHERE chat_id=? AND contact_id=?",
(self, ContactId::SELF),
)
.await
}
/// 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. /// including hidden messages or a draft if there is one.
pub(crate) async fn get_timestamp(self, context: &Context) -> Result<Option<i64>> { pub(crate) async fn get_timestamp(self, context: &Context) -> Result<Option<i64>> {
@@ -1287,9 +1298,13 @@ SELECT id, rfc724_mid, pre_rfc724_mid, timestamp, ?, 1 FROM msgs WHERE chat_id=?
sort_timestamp = last_msg_time; sort_timestamp = last_msg_time;
} }
if let Some(join_timestamp) = self.join_timestamp(context).await? {
Ok(std::cmp::max(sort_timestamp, join_timestamp))
} else {
Ok(sort_timestamp) Ok(sort_timestamp)
} }
} }
}
impl std::fmt::Display for ChatId { impl std::fmt::Display for ChatId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {