Skip to content

Commit 84161f4

Browse files
committed
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.
1 parent 4af9463 commit 84161f4

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/chat.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,18 @@ impl ChatId {
432432

433433
match chat.typ {
434434
Chattype::Single | Chattype::Group | Chattype::OutBroadcast | Chattype::InBroadcast => {
435-
// User has "created a chat" with all these contacts.
436-
//
437435
// Previously accepting a chat literally created a chat because unaccepted chats
438436
// went to "contact requests" list rather than normal chatlist.
437+
// But for groups we use lower origin because users don't always check all members
438+
// before accepting a chat and may not want to have the group members mixed with
439+
// existing contacts. `IncomingTo` fits here by its definition.
440+
let origin = match chat.typ {
441+
Chattype::Group => Origin::IncomingTo,
442+
_ => Origin::CreateChat,
443+
};
439444
for contact_id in get_chat_contacts(context, self).await? {
440445
if contact_id != ContactId::SELF {
441-
ContactId::scaleup_origin(context, &[contact_id], Origin::CreateChat)
442-
.await?;
446+
ContactId::scaleup_origin(context, &[contact_id], origin).await?;
443447
}
444448
}
445449
}

src/contact.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,14 +1144,15 @@ WHERE c.id>?
11441144
AND c.origin>=?
11451145
AND c.blocked=0
11461146
AND (IFNULL(c.name_normalized,IIF(c.name='',c.authname,c.name)) LIKE ? OR c.addr LIKE ?)
1147-
ORDER BY c.last_seen DESC, c.id DESC
1147+
ORDER BY c.origin>=? DESC, c.last_seen DESC, c.id DESC
11481148
",
11491149
(
11501150
ContactId::LAST_SPECIAL,
11511151
flag_address,
11521152
minimal_origin,
11531153
&s3str_like_cmd,
11541154
&s3str_like_cmd,
1155+
Origin::CreateChat,
11551156
),
11561157
|row| {
11571158
let id: ContactId = row.get(0)?;
@@ -1201,8 +1202,13 @@ ORDER BY c.last_seen DESC, c.id DESC
12011202
AND (fingerprint='')=?
12021203
AND origin>=?
12031204
AND blocked=0
1204-
ORDER BY last_seen DESC, id DESC;",
1205-
(ContactId::LAST_SPECIAL, flag_address, minimal_origin),
1205+
ORDER BY origin>=? DESC, last_seen DESC, id DESC",
1206+
(
1207+
ContactId::LAST_SPECIAL,
1208+
flag_address,
1209+
minimal_origin,
1210+
Origin::CreateChat,
1211+
),
12061212
|row| {
12071213
let id: ContactId = row.get(0)?;
12081214
let addr: String = row.get(1)?;

src/receive_imf/receive_imf_tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,8 +3878,9 @@ async fn test_group_contacts_goto_bottom() -> Result<()> {
38783878
assert_eq!(contacts[1], bob_fiona_id);
38793879

38803880
ChatId::create_for_contact(bob, bob_fiona_id).await?;
3881-
// Unfortunately, nothing has changed.
3882-
assert_eq!(Contact::get_all(bob, 0, None).await?, contacts);
3881+
let contacts = Contact::get_all(bob, 0, None).await?;
3882+
assert_eq!(contacts.len(), 2);
3883+
assert_eq!(contacts[0], bob_fiona_id);
38833884
Ok(())
38843885
}
38853886

0 commit comments

Comments
 (0)