Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/chat/chat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,40 @@ async fn test_shall_attach_selfavatar() -> Result<()> {
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_no_profile_data_on_group_leave() -> Result<()> {
let mut tcm = TestContextManager::new();
let t = &tcm.alice().await;
let chat_id = create_group_chat(t, ProtectionStatus::Unprotected, "foo").await?;

let (contact_id, _) = Contact::add_or_lookup(
t,
"",
&ContactAddress::new("[email protected]")?,
Origin::IncomingUnknownTo,
)
.await?;
add_contact_to_chat(t, chat_id, contact_id).await?;

send_text_msg(t, chat_id, "populate".to_string()).await?;
t.pop_sent_msg().await;

t.set_config(Config::Displayname, Some("aae7b258ad3cabd9"))
.await?;
let file = t.dir.path().join("avatar.png");
let bytes = include_bytes!("../../test-data/image/avatar64x64.png");
tokio::fs::write(&file, bytes).await?;
t.set_config(Config::Selfavatar, Some(file.to_str().unwrap()))
.await?;
assert!(shall_attach_selfavatar(t, chat_id).await?);

remove_contact_from_chat(t, chat_id, ContactId::SELF).await?;
let sent_msg = t.pop_sent_msg().await;
assert!(!sent_msg.payload().contains("aae7b258ad3cabd9"));
assert!(!sent_msg.payload().contains("Chat-User-Avatar"));
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_set_mute_duration() {
let t = TestContext::new().await;
Expand Down
24 changes: 15 additions & 9 deletions src/mimefactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl MimeFactory {
pub async fn from_msg(context: &Context, msg: Message) -> Result<MimeFactory> {
let now = time();
let chat = Chat::load_from_db(context, msg.chat_id).await?;
let attach_profile_data = Self::should_attach_profile_data(&msg);
let attach_profile_data = Self::should_attach_profile_data(context, &msg).await?;
let undisclosed_recipients = chat.typ == Chattype::Broadcast;

let from_addr = context.get_primary_self_addr().await?;
Expand Down Expand Up @@ -312,7 +312,7 @@ impl MimeFactory {
.unwrap_or_default(),
false => "".to_string(),
};
let attach_selfavatar = Self::should_attach_selfavatar(context, &msg).await;
let attach_selfavatar = Self::should_attach_selfavatar(context, &msg).await?;

debug_assert!(
member_timestamps.is_empty()
Expand Down Expand Up @@ -434,8 +434,14 @@ impl MimeFactory {
}
}

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

async fn should_attach_selfavatar(context: &Context, msg: &Message) -> bool {
Self::should_attach_profile_data(msg)
async fn should_attach_selfavatar(context: &Context, msg: &Message) -> Result<bool> {
Ok(Self::should_attach_profile_data(context, msg).await?
&& match chat::shall_attach_selfavatar(context, msg.chat_id).await {
Ok(should) => should,
Err(err) => {
Expand All @@ -460,7 +466,7 @@ impl MimeFactory {
);
false
}
}
})
}

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

let self_name = match Self::should_attach_profile_data(msg) {
let self_name = match Self::should_attach_profile_data(context, msg).await? {
true => context.get_config(Config::Displayname).await?,
false => None,
};
Expand Down
Loading