Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove subject prefix from ad-hoc group names (#5385) #5693

Merged
merged 2 commits into from
Jun 19, 2024
Merged
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
13 changes: 6 additions & 7 deletions src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::simplify;
use crate::sql;
use crate::stock_str;
use crate::sync::Sync::*;
use crate::tools::{self, buf_compress};
use crate::tools::{self, buf_compress, remove_subject_prefix};
use crate::{chatlist_events, location};
use crate::{contact, imap};
use iroh_net::NodeAddr;
Expand Down Expand Up @@ -1938,8 +1938,9 @@ async fn create_group(
let grpname = mime_parser
.get_header(HeaderDef::ChatGroupName)
.context("Chat-Group-Name vanished")?
// W/a for "Space added before long group names after MIME serialization/deserialization
// #3650" issue. DC itself never creates group names with leading/trailing whitespace.
// Workaround for the "Space added before long group names after MIME
// serialization/deserialization #3650" issue. DC itself never creates group names with
// leading/trailing whitespace.
.trim();
let new_chat_id = ChatId::create_multiuser_record(
context,
Expand Down Expand Up @@ -2129,12 +2130,10 @@ async fn apply_group_changes(
}
} else if let Some(old_name) = mime_parser
.get_header(HeaderDef::ChatGroupNameChanged)
// See create_or_lookup_group() for explanation
.map(|s| s.trim())
{
if let Some(grpname) = mime_parser
.get_header(HeaderDef::ChatGroupName)
// See create_or_lookup_group() for explanation
.map(|grpname| grpname.trim())
.filter(|grpname| grpname.len() < 200)
{
Expand Down Expand Up @@ -2549,10 +2548,10 @@ async fn create_adhoc_group(
return Ok(None);
}

// use subject as initial chat name
let grpname = mime_parser
.get_subject()
.unwrap_or_else(|| "Unnamed group".to_string());
.map(|s| remove_subject_prefix(&s))
.unwrap_or_else(|| "👥📧".to_string());

let new_chat_id: ChatId = ChatId::create_multiuser_record(
context,
Expand Down
27 changes: 27 additions & 0 deletions src/receive_imf/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4268,6 +4268,33 @@ async fn test_keep_member_list_if_possibly_nomember() -> Result<()> {
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_adhoc_grp_name_no_prefix() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let chat_id = receive_imf(
alice,
b"Subject: Re: Once upon a time this was with the only Re: here\n\
From: <[email protected]>\n\
To: <[email protected]>, <[email protected]>\n\
Date: Mon, 12 Dec 3000 14:32:39 +0000\n\
Message-ID: <[email protected]>\n\
In-Reply-To: <[email protected]>\n\
\n\
Adding Alice the Delta Chat lover",
false,
)
.await?
.unwrap()
.chat_id;
let chat = Chat::load_from_db(alice, chat_id).await.unwrap();
assert_eq!(
chat.get_name(),
"Once upon a time this was with the only Re: here"
);
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_download_later() -> Result<()> {
let mut tcm = TestContextManager::new();
Expand Down
Loading