Skip to content

Commit f762e6b

Browse files
committed
fix: Don't attach profile data in group leave messages
1 parent 9d3450f commit f762e6b

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

src/chat/chat_tests.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,40 @@ async fn test_shall_attach_selfavatar() -> Result<()> {
15031503
Ok(())
15041504
}
15051505

1506+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
1507+
async fn test_no_profile_data_on_group_leave() -> Result<()> {
1508+
let mut tcm = TestContextManager::new();
1509+
let t = &tcm.alice().await;
1510+
let chat_id = create_group_chat(t, ProtectionStatus::Unprotected, "foo").await?;
1511+
1512+
let (contact_id, _) = Contact::add_or_lookup(
1513+
t,
1514+
"",
1515+
&ContactAddress::new("[email protected]")?,
1516+
Origin::IncomingUnknownTo,
1517+
)
1518+
.await?;
1519+
add_contact_to_chat(t, chat_id, contact_id).await?;
1520+
1521+
send_text_msg(t, chat_id, "populate".to_string()).await?;
1522+
t.pop_sent_msg().await;
1523+
1524+
t.set_config(Config::Displayname, Some("aae7b258ad3cabd9"))
1525+
.await?;
1526+
let file = t.dir.path().join("avatar.png");
1527+
let bytes = include_bytes!("../../test-data/image/avatar64x64.png");
1528+
tokio::fs::write(&file, bytes).await?;
1529+
t.set_config(Config::Selfavatar, Some(file.to_str().unwrap()))
1530+
.await?;
1531+
assert!(shall_attach_selfavatar(t, chat_id).await?);
1532+
1533+
remove_contact_from_chat(t, chat_id, ContactId::SELF).await?;
1534+
let sent_msg = t.pop_sent_msg().await;
1535+
assert!(!sent_msg.payload().contains("aae7b258ad3cabd9"));
1536+
assert!(!sent_msg.payload().contains("Chat-User-Avatar"));
1537+
Ok(())
1538+
}
1539+
15061540
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
15071541
async fn test_set_mute_duration() {
15081542
let t = TestContext::new().await;

src/mimefactory.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl MimeFactory {
161161
pub async fn from_msg(context: &Context, msg: Message) -> Result<MimeFactory> {
162162
let now = time();
163163
let chat = Chat::load_from_db(context, msg.chat_id).await?;
164-
let attach_profile_data = Self::should_attach_profile_data(&msg);
164+
let attach_profile_data = Self::should_attach_profile_data(context, &msg).await?;
165165
let undisclosed_recipients = chat.typ == Chattype::Broadcast;
166166

167167
let from_addr = context.get_primary_self_addr().await?;
@@ -312,7 +312,7 @@ impl MimeFactory {
312312
.unwrap_or_default(),
313313
false => "".to_string(),
314314
};
315-
let attach_selfavatar = Self::should_attach_selfavatar(context, &msg).await;
315+
let attach_selfavatar = Self::should_attach_selfavatar(context, &msg).await?;
316316

317317
debug_assert!(
318318
member_timestamps.is_empty()
@@ -434,8 +434,14 @@ impl MimeFactory {
434434
}
435435
}
436436

437-
fn should_attach_profile_data(msg: &Message) -> bool {
438-
msg.param.get_cmd() != SystemMessage::SecurejoinMessage || {
437+
async fn should_attach_profile_data(context: &Context, msg: &Message) -> Result<bool> {
438+
if msg.param.get_cmd() == SystemMessage::MemberRemovedFromGroup
439+
&& msg.param.get(Param::Arg)
440+
== context.get_config(Config::ConfiguredAddr).await?.as_deref()
441+
{
442+
return Ok(false);
443+
}
444+
Ok(msg.param.get_cmd() != SystemMessage::SecurejoinMessage || {
439445
let step = msg.param.get(Param::Arg).unwrap_or_default();
440446
// Don't attach profile data at the earlier SecureJoin steps:
441447
// - The corresponding messages, i.e. "v{c,g}-request" and "v{c,g}-auth-required" are
@@ -446,11 +452,11 @@ impl MimeFactory {
446452
|| step == "vc-request-with-auth"
447453
|| step == "vg-member-added"
448454
|| step == "vc-contact-confirm"
449-
}
455+
})
450456
}
451457

452-
async fn should_attach_selfavatar(context: &Context, msg: &Message) -> bool {
453-
Self::should_attach_profile_data(msg)
458+
async fn should_attach_selfavatar(context: &Context, msg: &Message) -> Result<bool> {
459+
Ok(Self::should_attach_profile_data(context, msg).await?
454460
&& match chat::shall_attach_selfavatar(context, msg.chat_id).await {
455461
Ok(should) => should,
456462
Err(err) => {
@@ -460,7 +466,7 @@ impl MimeFactory {
460466
);
461467
false
462468
}
463-
}
469+
})
464470
}
465471

466472
fn grpimage(&self) -> Option<String> {
@@ -521,7 +527,7 @@ impl MimeFactory {
521527
return Ok(format!("Re: {}", remove_subject_prefix(last_subject)));
522528
}
523529

524-
let self_name = match Self::should_attach_profile_data(msg) {
530+
let self_name = match Self::should_attach_profile_data(context, msg).await? {
525531
true => context.get_config(Config::Displayname).await?,
526532
false => None,
527533
};

0 commit comments

Comments
 (0)