mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 21:36:30 +03:00
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.
This commit is contained in:
12
src/chat.rs
12
src/chat.rs
@@ -432,14 +432,18 @@ impl ChatId {
|
|||||||
|
|
||||||
match chat.typ {
|
match chat.typ {
|
||||||
Chattype::Single | Chattype::Group | Chattype::OutBroadcast | Chattype::InBroadcast => {
|
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
|
// Previously accepting a chat literally created a chat because unaccepted chats
|
||||||
// went to "contact requests" list rather than normal chatlist.
|
// 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? {
|
for contact_id in get_chat_contacts(context, self).await? {
|
||||||
if contact_id != ContactId::SELF {
|
if contact_id != ContactId::SELF {
|
||||||
ContactId::scaleup_origin(context, &[contact_id], Origin::CreateChat)
|
ContactId::scaleup_origin(context, &[contact_id], origin).await?;
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1144,7 +1144,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.last_seen DESC, c.id DESC
|
ORDER BY c.origin>=? DESC, c.last_seen DESC, c.id DESC
|
||||||
",
|
",
|
||||||
(
|
(
|
||||||
ContactId::LAST_SPECIAL,
|
ContactId::LAST_SPECIAL,
|
||||||
@@ -1152,6 +1152,7 @@ ORDER BY c.last_seen DESC, c.id DESC
|
|||||||
minimal_origin,
|
minimal_origin,
|
||||||
&s3str_like_cmd,
|
&s3str_like_cmd,
|
||||||
&s3str_like_cmd,
|
&s3str_like_cmd,
|
||||||
|
Origin::CreateChat,
|
||||||
),
|
),
|
||||||
|row| {
|
|row| {
|
||||||
let id: ContactId = row.get(0)?;
|
let id: ContactId = row.get(0)?;
|
||||||
@@ -1201,8 +1202,13 @@ ORDER BY c.last_seen DESC, c.id DESC
|
|||||||
AND (fingerprint='')=?
|
AND (fingerprint='')=?
|
||||||
AND origin>=?
|
AND origin>=?
|
||||||
AND blocked=0
|
AND blocked=0
|
||||||
ORDER BY last_seen DESC, id DESC;",
|
ORDER BY origin>=? DESC, last_seen DESC, id DESC",
|
||||||
(ContactId::LAST_SPECIAL, flag_address, minimal_origin),
|
(
|
||||||
|
ContactId::LAST_SPECIAL,
|
||||||
|
flag_address,
|
||||||
|
minimal_origin,
|
||||||
|
Origin::CreateChat,
|
||||||
|
),
|
||||||
|row| {
|
|row| {
|
||||||
let id: ContactId = row.get(0)?;
|
let id: ContactId = row.get(0)?;
|
||||||
let addr: String = row.get(1)?;
|
let addr: String = row.get(1)?;
|
||||||
|
|||||||
@@ -3878,8 +3878,9 @@ async fn test_group_contacts_goto_bottom() -> Result<()> {
|
|||||||
assert_eq!(contacts[1], bob_fiona_id);
|
assert_eq!(contacts[1], bob_fiona_id);
|
||||||
|
|
||||||
ChatId::create_for_contact(bob, bob_fiona_id).await?;
|
ChatId::create_for_contact(bob, bob_fiona_id).await?;
|
||||||
// Unfortunately, nothing has changed.
|
let contacts = Contact::get_all(bob, 0, None).await?;
|
||||||
assert_eq!(Contact::get_all(bob, 0, None).await?, contacts);
|
assert_eq!(contacts.len(), 2);
|
||||||
|
assert_eq!(contacts[0], bob_fiona_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user