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(()) }