From 85ebde29dcd3639673d865a2b3ddbb089b7dcbe3 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 7 Nov 2019 01:56:52 +0100 Subject: [PATCH] do not resort chatlist on draft changes resorting the chatlist on changing drafts has some ux issues. eg. when the chatlist is visible together with the input field, if may come to flickering resorting during input or to a resorting just when the user leave the chat as this might trigger set_draft(). but also on mobiles, the resorting is visible and a bit unexpected. also it is unclear what happens when a chat with a draft is entered and left without modifications. the solution proposed here is to ignore draft on sorting while still showing them in the chatlist if they're newer as the last message. a possible disadvantage is that the date for the chat with a draft does not follow the ordering (the ordering is by the last message), however, the date is not shown as a "primary sort" criterion or so, so it might be that this is completely okay. also, of course, it affects only draft :) --- src/chatlist.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/chatlist.rs b/src/chatlist.rs index ffd6d6f9a..fa45561b5 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -126,7 +126,7 @@ impl Chatlist { " SELECT MAX(timestamp)", " FROM msgs", " WHERE chat_id=c.id", - " AND (hidden=0 OR (hidden=1 AND state=19)))", + " AND hidden=0)", " WHERE c.id>9", " AND c.blocked=0", " AND c.id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?)", @@ -149,7 +149,7 @@ impl Chatlist { " SELECT MAX(timestamp)", " FROM msgs", " WHERE chat_id=c.id", - " AND (hidden=0 OR (hidden=1 AND state=19)))", + " AND hidden=0)", " WHERE c.id>9", " AND c.blocked=0", " AND c.archived=1", @@ -175,7 +175,7 @@ impl Chatlist { " SELECT MAX(timestamp)", " FROM msgs", " WHERE chat_id=c.id", - " AND (hidden=0 OR (hidden=1 AND state=19)))", + " AND hidden=0)", " WHERE c.id>9", " AND c.blocked=0", " AND c.name LIKE ?", @@ -198,7 +198,7 @@ impl Chatlist { " SELECT MAX(timestamp)", " FROM msgs", " WHERE chat_id=c.id", - " AND (hidden=0 OR (hidden=1 AND state=19)))", + " AND hidden=0)", " WHERE c.id>9", " AND c.blocked=0", " AND c.archived=0", @@ -294,7 +294,7 @@ impl Chatlist { let lastmsg_id = self.ids[index].1; let mut lastcontact = None; - let lastmsg = if let Ok(lastmsg) = Message::load_from_db(context, lastmsg_id) { + let mut lastmsg = if let Ok(lastmsg) = Message::load_from_db(context, lastmsg_id) { if lastmsg.from_id != DC_CONTACT_ID_SELF && (chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup) { @@ -306,6 +306,16 @@ impl Chatlist { None }; + if let Ok(draft) = get_draft(context, chat.id) { + if draft.is_some() + && (lastmsg.is_none() + || draft.as_ref().unwrap().timestamp_sort + > lastmsg.as_ref().unwrap().timestamp_sort) + { + lastmsg = draft; + } + } + if chat.id == DC_CHAT_ID_ARCHIVED_LINK { ret.text2 = None; } else if lastmsg.is_none() || lastmsg.as_ref().unwrap().from_id == DC_CONTACT_ID_UNDEFINED