mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 01:46:34 +03:00
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:
@@ -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)?;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user