Skip to content

Commit 46922d4

Browse files
committed
fix: do not attempt to reference info messages
Info messages are added at the beginning of unpromoted group chats ("Others will only see this group after you sent a first message."), may be created by WebXDC etc. They are not sent outside and have local Message-ID that is not known to other recipients so they should be skipped when constructing In-Reply-To and References.
1 parent 75fe4e1 commit 46922d4

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/chat.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@ impl ChatId {
12281228
AND ((state BETWEEN {} AND {}) OR (state >= {})) \
12291229
AND NOT hidden \
12301230
AND download_state={} \
1231+
AND from_id != {} \
12311232
ORDER BY timestamp DESC, id DESC \
12321233
LIMIT 1;",
12331234
MessageState::InFresh as u32,
@@ -1236,6 +1237,9 @@ impl ChatId {
12361237
// Do not reply to not fully downloaded messages. Such a message could be a group chat
12371238
// message that we assigned to 1:1 chat.
12381239
DownloadState::Done as u32,
1240+
// Do not reference info messages, they are not actually sent out
1241+
// and have Message-IDs unknown to other chat members.
1242+
ContactId::INFO.to_u32(),
12391243
);
12401244
sql.query_row_optional(&query, (self,), f).await
12411245
}
@@ -4667,6 +4671,7 @@ mod tests {
46674671
use super::*;
46684672
use crate::chatlist::get_archived_cnt;
46694673
use crate::constants::{DC_GCL_ARCHIVED_ONLY, DC_GCL_NO_SPECIALS};
4674+
use crate::headerdef::HeaderDef;
46704675
use crate::message::delete_msgs;
46714676
use crate::receive_imf::receive_imf;
46724677
use crate::test_utils::{sync, TestContext, TestContextManager};
@@ -7622,4 +7627,29 @@ mod tests {
76227627

76237628
Ok(())
76247629
}
7630+
7631+
/// Tests that info message is ignored when constructing `In-Reply-To`.
7632+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
7633+
async fn test_info_not_referenced() -> Result<()> {
7634+
let mut tcm = TestContextManager::new();
7635+
let alice = &tcm.alice().await;
7636+
let bob = &tcm.bob().await;
7637+
7638+
let bob_received_message = tcm.send_recv_accept(alice, bob, "Hi!").await;
7639+
let bob_chat_id = bob_received_message.chat_id;
7640+
add_info_msg(bob, bob_chat_id, "Some info", create_smeared_timestamp(bob)).await?;
7641+
7642+
// Bob sends a message.
7643+
// This message should reference Alice's "Hi!" message and not the info message.
7644+
let sent = bob.send_text(bob_chat_id, "Hi hi!").await;
7645+
let mime_message = alice.parse_msg(&sent).await;
7646+
7647+
let in_reply_to = mime_message.get_header(HeaderDef::InReplyTo).unwrap();
7648+
assert_eq!(
7649+
in_reply_to,
7650+
format!("<{}>", bob_received_message.rfc724_mid)
7651+
);
7652+
7653+
Ok(())
7654+
}
76257655
}

0 commit comments

Comments
 (0)