mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +03:00
fix: always prefer Chat-Group-ID over In-Reply-To and References
Chat-Group-ID always correctly identifies the chat message was sent to, while In-Reply-To and References may point to a message that has itself been incorrectly assigned to a chat.
This commit is contained in:
@@ -769,6 +769,18 @@ async fn add_parts(
|
|||||||
info!(context, "Message is an MDN (TRASH).",);
|
info!(context, "Message is an MDN (TRASH).",);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to assign to a chat based on Chat-Group-ID.
|
||||||
|
if chat_id.is_none() {
|
||||||
|
if let Some(grpid) = mime_parser.get_chat_group_id() {
|
||||||
|
if let Some((id, _protected, blocked)) =
|
||||||
|
chat::get_chat_id_by_grpid(context, grpid).await?
|
||||||
|
{
|
||||||
|
chat_id = Some(id);
|
||||||
|
chat_id_blocked = blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if chat_id.is_none() {
|
if chat_id.is_none() {
|
||||||
// try to assign to a chat based on In-Reply-To/References:
|
// try to assign to a chat based on In-Reply-To/References:
|
||||||
|
|
||||||
@@ -1035,6 +1047,18 @@ async fn add_parts(
|
|||||||
chat_id = Some(DC_CHAT_ID_TRASH);
|
chat_id = Some(DC_CHAT_ID_TRASH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to assign to a chat based on Chat-Group-ID.
|
||||||
|
if chat_id.is_none() {
|
||||||
|
if let Some(grpid) = mime_parser.get_chat_group_id() {
|
||||||
|
if let Some((id, _protected, blocked)) =
|
||||||
|
chat::get_chat_id_by_grpid(context, grpid).await?
|
||||||
|
{
|
||||||
|
chat_id = Some(id);
|
||||||
|
chat_id_blocked = blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if chat_id.is_none() {
|
if chat_id.is_none() {
|
||||||
// try to assign to a chat based on In-Reply-To/References:
|
// try to assign to a chat based on In-Reply-To/References:
|
||||||
|
|
||||||
|
|||||||
@@ -2693,6 +2693,103 @@ Second thread."#;
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Test that `Chat-Group-ID` is preferred over `In-Reply-To` and `References`.
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_chat_assignment_chat_group_id_preference() -> Result<()> {
|
||||||
|
let t = &TestContext::new_alice().await;
|
||||||
|
|
||||||
|
receive_imf(
|
||||||
|
t,
|
||||||
|
br#"Subject: Hello
|
||||||
|
Chat-Group-ID: eJ_llQIXf0K
|
||||||
|
Chat-Group-Name: Group name
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Message-ID: <first@localhost>
|
||||||
|
References: <first@localhost>
|
||||||
|
Date: Fri, 28 May 2021 10:15:05 +0000
|
||||||
|
From: Alice <alice@example.org>
|
||||||
|
To: Bob <bob@example.com>, <claire@example.org>
|
||||||
|
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
|
Hello, I've just created a group for us."#,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let group_msg = t.get_last_msg().await;
|
||||||
|
|
||||||
|
receive_imf(
|
||||||
|
t,
|
||||||
|
br#"Subject: Hello
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Message-ID: <second@localhost>
|
||||||
|
References: <second@localhost>
|
||||||
|
Date: Fri, 28 May 2021 10:15:05 +0000
|
||||||
|
From: Bob <bob@example.com>
|
||||||
|
To: Alice <alice@example.org>
|
||||||
|
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
|
Hello from Bob in 1:1 chat."#,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// References and In-Reply-To point to a message
|
||||||
|
// already assigned to 1:1 chat, but Chat-Group-ID is
|
||||||
|
// a stronger signal to assign message to a group.
|
||||||
|
receive_imf(
|
||||||
|
t,
|
||||||
|
br#"Subject: Hello
|
||||||
|
Chat-Group-ID: eJ_llQIXf0K
|
||||||
|
Chat-Group-Name: Group name
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Message-ID: <third@localhost>
|
||||||
|
In-Reply-To: <second@localhost>
|
||||||
|
References: <second@localhost>
|
||||||
|
Date: Fri, 28 May 2021 10:15:05 +0000
|
||||||
|
From: Bob <bob@example.com>
|
||||||
|
To: Alice <alice@example.org>, <claire@example.org>
|
||||||
|
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
|
Hello from Bob in a group."#,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let msg = t.get_last_msg().await;
|
||||||
|
assert_eq!(msg.text, "Hello from Bob in a group.");
|
||||||
|
assert_eq!(msg.chat_id, group_msg.chat_id);
|
||||||
|
|
||||||
|
// Test outgoing message as well.
|
||||||
|
receive_imf(
|
||||||
|
t,
|
||||||
|
br#"Subject: Hello
|
||||||
|
Chat-Group-ID: eJ_llQIXf0K
|
||||||
|
Chat-Group-Name: Group name
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Message-ID: <fourth@localhost>
|
||||||
|
In-Reply-To: <second@localhost>
|
||||||
|
References: <second@localhost>
|
||||||
|
Date: Fri, 28 May 2021 10:15:05 +0000
|
||||||
|
From: Alice <alice@example.org>
|
||||||
|
To: Bob <bob@example.com>, <claire@example.org>
|
||||||
|
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
|
Hello from Alice in a group."#,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let msg_outgoing = t.get_last_msg().await;
|
||||||
|
assert_eq!(msg_outgoing.text, "Hello from Alice in a group.");
|
||||||
|
assert_eq!(msg_outgoing.chat_id, group_msg.chat_id);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Test that read receipts don't create chats.
|
/// Test that read receipts don't create chats.
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_read_receipts_dont_create_chats() -> Result<()> {
|
async fn test_read_receipts_dont_create_chats() -> Result<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user