From 84161f4202177cb8ff1e2948d80cacd32ccc796b Mon Sep 17 00:00:00 2001 From: iequidoo Date: Tue, 16 Dec 2025 03:33:09 -0300 Subject: [PATCH] fix: When accepting group, add members with Origin::IncomingTo and sort them down in the contact list (7592) When accepting a chat, its members are promoted to `Origin::CreateChat`, but for groups it makes sense to use lower origin because users don't always check all members before accepting a chat and may not want to have the group members mixed with existing contacts. `IncomingTo` fits here by its definition: "additional To:'s of incoming message of known sender", i.e. we assume that the sender of some message is known to the user. This way we can show contacts coming from groups in the bottom of contact list, maybe even add some separator later. It makes sense not to hide such contacts completely, otherwise if the user remembers the contact name, but not the chat it's a member of, it would be difficult to find the contact. --- src/chat.rs | 12 ++++++++---- src/contact.rs | 12 +++++++++--- src/receive_imf/receive_imf_tests.rs | 5 +++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index d3f710c18..533cf8c76 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -432,14 +432,18 @@ impl ChatId { match chat.typ { Chattype::Single | Chattype::Group | Chattype::OutBroadcast | Chattype::InBroadcast => { - // User has "created a chat" with all these contacts. - // // Previously accepting a chat literally created a chat because unaccepted chats // went to "contact requests" list rather than normal chatlist. + // But for groups we use lower origin because users don't always check all members + // before accepting a chat and may not want to have the group members mixed with + // existing contacts. `IncomingTo` fits here by its definition. + let origin = match chat.typ { + Chattype::Group => Origin::IncomingTo, + _ => Origin::CreateChat, + }; for contact_id in get_chat_contacts(context, self).await? { if contact_id != ContactId::SELF { - ContactId::scaleup_origin(context, &[contact_id], Origin::CreateChat) - .await?; + ContactId::scaleup_origin(context, &[contact_id], origin).await?; } } } diff --git a/src/contact.rs b/src/contact.rs index 7d7e1ca14..0c3a52382 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1144,7 +1144,7 @@ WHERE c.id>? AND c.origin>=? AND c.blocked=0 AND (IFNULL(c.name_normalized,IIF(c.name='',c.authname,c.name)) LIKE ? OR c.addr LIKE ?) -ORDER BY c.last_seen DESC, c.id DESC +ORDER BY c.origin>=? DESC, c.last_seen DESC, c.id DESC ", ( ContactId::LAST_SPECIAL, @@ -1152,6 +1152,7 @@ ORDER BY c.last_seen DESC, c.id DESC minimal_origin, &s3str_like_cmd, &s3str_like_cmd, + Origin::CreateChat, ), |row| { let id: ContactId = row.get(0)?; @@ -1201,8 +1202,13 @@ ORDER BY c.last_seen DESC, c.id DESC AND (fingerprint='')=? AND origin>=? AND blocked=0 - ORDER BY last_seen DESC, id DESC;", - (ContactId::LAST_SPECIAL, flag_address, minimal_origin), + ORDER BY origin>=? DESC, last_seen DESC, id DESC", + ( + ContactId::LAST_SPECIAL, + flag_address, + minimal_origin, + Origin::CreateChat, + ), |row| { let id: ContactId = row.get(0)?; let addr: String = row.get(1)?; diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index c8e25ee2a..40a6eddd0 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -3878,8 +3878,9 @@ async fn test_group_contacts_goto_bottom() -> Result<()> { assert_eq!(contacts[1], bob_fiona_id); ChatId::create_for_contact(bob, bob_fiona_id).await?; - // Unfortunately, nothing has changed. - assert_eq!(Contact::get_all(bob, 0, None).await?, contacts); + let contacts = Contact::get_all(bob, 0, None).await?; + assert_eq!(contacts.len(), 2); + assert_eq!(contacts[0], bob_fiona_id); Ok(()) }