fix: Don't resort re-sent message to the bottom (#8145)

We shouldn't just revert ad7f873c68 because then we won't be able to
normally transfer a backup from a device having clock a bit in the future.

INDEXED BY msgs_index7 is to prevent SQLite from downgrading to using msgs_index2 which has less
ordering.
This commit is contained in:
iequidoo
2026-04-21 10:38:10 -03:00
committed by iequidoo
parent 6dfc6f8780
commit 38affa2c62
3 changed files with 61 additions and 9 deletions

View File

@@ -834,17 +834,24 @@ ORDER BY id"
assert_eq!(received.chat_id, DC_CHAT_ID_TRASH);
}
/// Gets the most recent message ID of a chat.
///
/// Panics on errors or if the most recent message is a marker.
pub async fn get_last_msg_id_in(&self, chat_id: ChatId) -> MsgId {
let msgs = chat::get_chat_msgs(&self.ctx, chat_id).await.unwrap();
if let ChatItem::Message { msg_id } = msgs.last().unwrap() {
*msg_id
} else {
panic!("Wrong item type");
}
}
/// Gets the most recent message of a chat.
///
/// Panics on errors or if the most recent message is a marker.
pub async fn get_last_msg_in(&self, chat_id: ChatId) -> Message {
let msgs = chat::get_chat_msgs(&self.ctx, chat_id).await.unwrap();
let msg_id = if let ChatItem::Message { msg_id } = msgs.last().unwrap() {
msg_id
} else {
panic!("Wrong item type");
};
Message::load_from_db(&self.ctx, *msg_id).await.unwrap()
let msg_id = self.get_last_msg_id_in(chat_id).await;
Message::load_from_db(&self.ctx, msg_id).await.unwrap()
}
/// Gets the most recent message over all chats.