mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 12:56:30 +03:00
fix: do not use square brackets error for unknown sender
If the sender of the message in protected group chat is not a member of the chat, mark the sender name with `~` as we do it in non-protected chats and set the error instead of replacing the whole message with "Unknown sender for this chat. See 'info' for more details." To send a message to a protected group this way the sender needs to know the group ID and sign the message with the current verified key. Usually this is just a late message delivered shortly after the user has left the group or was removed from it. Replacing the message with a single error text part as done before this change makes it impossible to access anything other than text, such as attached images.
This commit is contained in:
@@ -636,14 +636,9 @@ async fn add_parts(
|
|||||||
if let Some(group_chat_id) = chat_id {
|
if let Some(group_chat_id) = chat_id {
|
||||||
if !chat::is_contact_in_chat(context, group_chat_id, from_id).await? {
|
if !chat::is_contact_in_chat(context, group_chat_id, from_id).await? {
|
||||||
let chat = Chat::load_from_db(context, group_chat_id).await?;
|
let chat = Chat::load_from_db(context, group_chat_id).await?;
|
||||||
if chat.is_protected() {
|
if chat.is_protected() && chat.typ == Chattype::Single {
|
||||||
if chat.typ == Chattype::Single {
|
// Just assign the message to the 1:1 chat with the actual sender instead.
|
||||||
// Just assign the message to the 1:1 chat with the actual sender instead.
|
chat_id = None;
|
||||||
chat_id = None;
|
|
||||||
} else {
|
|
||||||
let s = stock_str::unknown_sender_for_chat(context).await;
|
|
||||||
mime_parser.replace_msg_by_error(&s);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// In non-protected chats, just mark the sender as overridden. Therefore, the UI will prepend `~`
|
// 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.
|
// 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);
|
let name: &str = from.display_name.as_ref().unwrap_or(&from.addr);
|
||||||
for part in &mut mime_parser.parts {
|
for part in &mut mime_parser.parts {
|
||||||
part.param.set(Param::OverrideSenderDisplayname, name);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -770,7 +770,7 @@ fn encrypted_and_signed(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::chat;
|
use crate::chat;
|
||||||
use crate::chat::ProtectionStatus;
|
use crate::chat::{remove_contact_from_chat, ProtectionStatus};
|
||||||
use crate::chatlist::Chatlist;
|
use crate::chatlist::Chatlist;
|
||||||
use crate::constants::Chattype;
|
use crate::constants::Chattype;
|
||||||
use crate::contact::ContactAddress;
|
use crate::contact::ContactAddress;
|
||||||
@@ -1352,4 +1352,32 @@ First thread."#;
|
|||||||
assert!(get_securejoin_qr(&alice, Some(chat_id)).await.is_err());
|
assert!(get_securejoin_qr(&alice, Some(chat_id)).await.is_err());
|
||||||
Ok(())
|
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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ pub enum StockMessage {
|
|||||||
however, of course, if they like, you may point them to 👉 https://get.delta.chat"))]
|
however, of course, if they like, you may point them to 👉 https://get.delta.chat"))]
|
||||||
WelcomeMessage = 71,
|
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,
|
UnknownSenderForChat = 72,
|
||||||
|
|
||||||
#[strum(props(fallback = "Message from %1$s"))]
|
#[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
|
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 {
|
pub(crate) async fn unknown_sender_for_chat(context: &Context) -> String {
|
||||||
translated(context, StockMessage::UnknownSenderForChat).await
|
translated(context, StockMessage::UnknownSenderForChat).await
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user