From f433f173cc8a4286b0ad8d6654d70876d37381f5 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Tue, 7 Apr 2026 22:01:24 -0300 Subject: [PATCH] fix: Scale up contacts messaged in groups to OutgoingCc This makes such contacts appear in the contact list. But let's sort them after contacts messaged directly (in 1:1 chats or 2-member groups) to avoid cluttering the contact list with contacts from big groups. UX-wise this partially reverts b549e7633d5735af72c7a7c9b35f984abdff938e which made it impossible to find contacts from groups even if we've written there. --- src/contact.rs | 6 ++++-- src/mimefactory.rs | 18 ++++++++++-------- src/receive_imf/receive_imf_tests.rs | 20 ++++++++++++-------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/contact.rs b/src/contact.rs index 4b750803f..3c527d8ac 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1202,7 +1202,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.origin>=? DESC, c.last_seen DESC, c.id DESC +ORDER BY c.origin>=? DESC, c.origin>=? DESC, c.last_seen DESC, c.id DESC ", ( ContactId::LAST_SPECIAL, @@ -1211,6 +1211,7 @@ ORDER BY c.origin>=? DESC, c.last_seen DESC, c.id DESC &s3str_like_cmd, &query_lowercased, Origin::CreateChat, + Origin::OutgoingTo, ), |row| { let id: ContactId = row.get(0)?; @@ -1260,12 +1261,13 @@ ORDER BY c.origin>=? DESC, c.last_seen DESC, c.id DESC AND (fingerprint='')=? AND origin>=? AND blocked=0 - ORDER BY origin>=? DESC, last_seen DESC, id DESC", + ORDER BY origin>=? DESC, origin>=? DESC, last_seen DESC, id DESC", ( ContactId::LAST_SPECIAL, flag_address, minimal_origin, Origin::CreateChat, + Origin::OutgoingTo, ), |row| { let id: ContactId = row.get(0)?; diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 0e0eefd6e..361551935 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -463,18 +463,20 @@ impl MimeFactory { .into_iter() .filter(|id| *id != ContactId::SELF) .collect(); - if recipient_ids.len() == 1 - && !matches!( - msg.param.get_cmd(), - SystemMessage::MemberRemovedFromGroup | SystemMessage::SecurejoinMessage - ) - && !matches!(chat.typ, Chattype::OutBroadcast | Chattype::InBroadcast) + if !matches!( + msg.param.get_cmd(), + SystemMessage::MemberRemovedFromGroup | SystemMessage::SecurejoinMessage + ) && !matches!(chat.typ, Chattype::OutBroadcast | Chattype::InBroadcast) { + let origin = match recipient_ids.len() { + 1 => Origin::OutgoingTo, + _ => Origin::OutgoingCc, + }; info!( context, - "Scale up origin of {} recipients to OutgoingTo.", chat.id + "Scale up origin of {} recipients to {origin:?}.", chat.id ); - ContactId::scaleup_origin(context, &recipient_ids, Origin::OutgoingTo).await?; + ContactId::scaleup_origin(context, &recipient_ids, origin).await?; } if !msg.is_system_message() diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index 809ead1d6..d6c1a91c6 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -3875,21 +3875,23 @@ async fn test_group_contacts_goto_bottom() -> Result<()> { assert_eq!(Contact::get_all(bob, 0, None).await?.len(), 0); bob_chat_id.accept(bob).await?; let contacts = Contact::get_all(bob, 0, None).await?; - assert_eq!(contacts.len(), 2); let bob_fiona_id = bob.add_or_lookup_contact_id(fiona).await; + // Fiona hasn't been online, so she goes after Alice. + assert_eq!(contacts.len(), 2); assert_eq!(contacts[1], bob_fiona_id); - ChatId::create_for_contact(bob, bob_fiona_id).await?; + let bob_fiona_chat_id = ChatId::create_for_contact(bob, bob_fiona_id).await?; let contacts = Contact::get_all(bob, 0, None).await?; assert_eq!(contacts.len(), 2); assert_eq!(contacts[0], bob_fiona_id); - send_text_msg( - bob, - bob_chat_id, - "Hi Alice, stay down in my contact list".to_string(), - ) - .await?; + send_text_msg(bob, bob_chat_id, "Hi all".to_string()).await?; + bob.pop_sent_msg().await; + let contacts = Contact::get_all(bob, 0, None).await?; + // The group message made both contacts equally "important", but Fiona hasn't been online. + assert_eq!(contacts[1], bob_fiona_id); + + send_text_msg(bob, bob_fiona_chat_id, "Hi Fiona".to_string()).await?; bob.pop_sent_msg().await; let contacts = Contact::get_all(bob, 0, None).await?; assert_eq!(contacts[0], bob_fiona_id); @@ -3905,6 +3907,8 @@ async fn test_group_contacts_goto_bottom() -> Result<()> { bob.pop_sent_msg().await; let contacts = Contact::get_all(bob, 0, None).await?; let bob_alice_id = bob.add_or_lookup_contact_id(alice).await; + // As the group only contains Alice, the sent message made her as "important" as Fiona + // previously messaged 1:1 by Bob, but Fiona hasn't been online. assert_eq!(contacts[0], bob_alice_id); Ok(()) }