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 b549e7633d which made it impossible to
find contacts from groups even if we've written there.
This commit is contained in:
iequidoo
2026-04-07 22:01:24 -03:00
parent 60bc4011f7
commit f433f173cc
3 changed files with 26 additions and 18 deletions

View File

@@ -1202,7 +1202,7 @@ WHERE c.id>?
AND c.origin>=? AND c.origin>=?
AND c.blocked=0 AND c.blocked=0
AND (IFNULL(c.name_normalized,IIF(c.name='',c.authname,c.name)) LIKE ? OR c.addr LIKE ?) 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, ContactId::LAST_SPECIAL,
@@ -1211,6 +1211,7 @@ ORDER BY c.origin>=? DESC, c.last_seen DESC, c.id DESC
&s3str_like_cmd, &s3str_like_cmd,
&query_lowercased, &query_lowercased,
Origin::CreateChat, Origin::CreateChat,
Origin::OutgoingTo,
), ),
|row| { |row| {
let id: ContactId = row.get(0)?; 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 (fingerprint='')=?
AND origin>=? AND origin>=?
AND blocked=0 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, ContactId::LAST_SPECIAL,
flag_address, flag_address,
minimal_origin, minimal_origin,
Origin::CreateChat, Origin::CreateChat,
Origin::OutgoingTo,
), ),
|row| { |row| {
let id: ContactId = row.get(0)?; let id: ContactId = row.get(0)?;

View File

@@ -463,18 +463,20 @@ impl MimeFactory {
.into_iter() .into_iter()
.filter(|id| *id != ContactId::SELF) .filter(|id| *id != ContactId::SELF)
.collect(); .collect();
if recipient_ids.len() == 1 if !matches!(
&& !matches!( msg.param.get_cmd(),
msg.param.get_cmd(), SystemMessage::MemberRemovedFromGroup | SystemMessage::SecurejoinMessage
SystemMessage::MemberRemovedFromGroup | SystemMessage::SecurejoinMessage ) && !matches!(chat.typ, Chattype::OutBroadcast | Chattype::InBroadcast)
)
&& !matches!(chat.typ, Chattype::OutBroadcast | Chattype::InBroadcast)
{ {
let origin = match recipient_ids.len() {
1 => Origin::OutgoingTo,
_ => Origin::OutgoingCc,
};
info!( info!(
context, 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() if !msg.is_system_message()

View File

@@ -3875,21 +3875,23 @@ async fn test_group_contacts_goto_bottom() -> Result<()> {
assert_eq!(Contact::get_all(bob, 0, None).await?.len(), 0); assert_eq!(Contact::get_all(bob, 0, None).await?.len(), 0);
bob_chat_id.accept(bob).await?; bob_chat_id.accept(bob).await?;
let contacts = Contact::get_all(bob, 0, None).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; 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); 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?; let contacts = Contact::get_all(bob, 0, None).await?;
assert_eq!(contacts.len(), 2); assert_eq!(contacts.len(), 2);
assert_eq!(contacts[0], bob_fiona_id); assert_eq!(contacts[0], bob_fiona_id);
send_text_msg( send_text_msg(bob, bob_chat_id, "Hi all".to_string()).await?;
bob, bob.pop_sent_msg().await;
bob_chat_id, let contacts = Contact::get_all(bob, 0, None).await?;
"Hi Alice, stay down in my contact list".to_string(), // The group message made both contacts equally "important", but Fiona hasn't been online.
) assert_eq!(contacts[1], bob_fiona_id);
.await?;
send_text_msg(bob, bob_fiona_chat_id, "Hi Fiona".to_string()).await?;
bob.pop_sent_msg().await; bob.pop_sent_msg().await;
let contacts = Contact::get_all(bob, 0, None).await?; let contacts = Contact::get_all(bob, 0, None).await?;
assert_eq!(contacts[0], bob_fiona_id); assert_eq!(contacts[0], bob_fiona_id);
@@ -3905,6 +3907,8 @@ async fn test_group_contacts_goto_bottom() -> Result<()> {
bob.pop_sent_msg().await; bob.pop_sent_msg().await;
let contacts = Contact::get_all(bob, 0, None).await?; let contacts = Contact::get_all(bob, 0, None).await?;
let bob_alice_id = bob.add_or_lookup_contact_id(alice).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); assert_eq!(contacts[0], bob_alice_id);
Ok(()) Ok(())
} }