diff --git a/src/receive_imf.rs b/src/receive_imf.rs index bfac21bb0..b3dd10ff9 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -636,14 +636,9 @@ async fn add_parts( if let Some(group_chat_id) = chat_id { if !chat::is_contact_in_chat(context, group_chat_id, from_id).await? { let chat = Chat::load_from_db(context, group_chat_id).await?; - if chat.is_protected() { - if chat.typ == Chattype::Single { - // Just assign the message to the 1:1 chat with the actual sender instead. - chat_id = None; - } else { - let s = stock_str::unknown_sender_for_chat(context).await; - mime_parser.replace_msg_by_error(&s); - } + if chat.is_protected() && chat.typ == Chattype::Single { + // Just assign the message to the 1:1 chat with the actual sender instead. + chat_id = None; } else { // In non-protected chats, just mark the sender as overridden. Therefore, the UI will prepend `~` // to the sender's name, indicating to the user that he/she is not part of the group. @@ -651,6 +646,12 @@ async fn add_parts( let name: &str = from.display_name.as_ref().unwrap_or(&from.addr); for part in &mut mime_parser.parts { part.param.set(Param::OverrideSenderDisplayname, name); + + if chat.is_protected() { + // In protected chat, also mark the message with an error. + let s = stock_str::unknown_sender_for_chat(context).await; + part.error = Some(s); + } } } } diff --git a/src/securejoin.rs b/src/securejoin.rs index 3beeaae2a..c91471f47 100644 --- a/src/securejoin.rs +++ b/src/securejoin.rs @@ -770,7 +770,7 @@ fn encrypted_and_signed( mod tests { use super::*; use crate::chat; - use crate::chat::ProtectionStatus; + use crate::chat::{remove_contact_from_chat, ProtectionStatus}; use crate::chatlist::Chatlist; use crate::constants::Chattype; use crate::contact::ContactAddress; @@ -1352,4 +1352,32 @@ First thread."#; assert!(get_securejoin_qr(&alice, Some(chat_id)).await.is_err()); Ok(()) } + + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_unknown_sender() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = tcm.alice().await; + let bob = tcm.bob().await; + + tcm.execute_securejoin(&alice, &bob).await; + + let alice_chat_id = alice + .create_group_with_members(ProtectionStatus::Protected, "Group with Bob", &[&bob]) + .await; + + let sent = alice.send_text(alice_chat_id, "Hi!").await; + let bob_chat_id = bob.recv_msg(&sent).await.chat_id; + + let sent = bob.send_text(bob_chat_id, "Hi hi!").await; + + let alice_bob_contact_id = Contact::create(&alice, "Bob", "bob@example.net").await?; + remove_contact_from_chat(&alice, alice_chat_id, alice_bob_contact_id).await?; + + // The message from Bob is delivered late, Bob is already removed. + let msg = alice.recv_msg(&sent).await; + assert_eq!(msg.text, "Hi hi!"); + assert_eq!(msg.error.unwrap(), "Unknown sender for this chat."); + + Ok(()) + } } diff --git a/src/stock_str.rs b/src/stock_str.rs index 6ea0bb3fb..0f0382633 100644 --- a/src/stock_str.rs +++ b/src/stock_str.rs @@ -149,7 +149,7 @@ pub enum StockMessage { however, of course, if they like, you may point them to 👉 https://get.delta.chat"))] WelcomeMessage = 71, - #[strum(props(fallback = "Unknown sender for this chat. See 'info' for more details."))] + #[strum(props(fallback = "Unknown sender for this chat."))] UnknownSenderForChat = 72, #[strum(props(fallback = "Message from %1$s"))] @@ -930,7 +930,7 @@ pub(crate) async fn welcome_message(context: &Context) -> String { translated(context, StockMessage::WelcomeMessage).await } -/// Stock string: `Unknown sender for this chat. See 'info' for more details.`. +/// Stock string: `Unknown sender for this chat.`. pub(crate) async fn unknown_sender_for_chat(context: &Context) -> String { translated(context, StockMessage::UnknownSenderForChat).await }