Skip to content

Commit 89a73d7

Browse files
committed
fix: Set GroupNameTimestamp on group promotion (#6729)
Otherwise if an invite link is generated and the group is renamed then before the promotion, the joined member will have the group name from the invite link, not the new one.
1 parent 66e3dc7 commit 89a73d7

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

src/chat.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,9 @@ impl Chat {
20632063
&& self.param.get_int(Param::Unpromoted).unwrap_or_default() == 1
20642064
{
20652065
msg.param.set_int(Param::AttachGroupImage, 1);
2066-
self.param.remove(Param::Unpromoted);
2066+
self.param
2067+
.remove(Param::Unpromoted)
2068+
.set_i64(Param::GroupNameTimestamp, timestamp);
20672069
self.update_param(context).await?;
20682070
// TODO: Remove this compat code needed because Core <= v1.143:
20692071
// - doesn't accept synchronization of QR code tokens for unpromoted groups, so we also
@@ -3917,7 +3919,9 @@ pub(crate) async fn add_contact_to_chat_ex(
39173919

39183920
let sync_qr_code_tokens;
39193921
if from_handshake && chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 1 {
3920-
chat.param.remove(Param::Unpromoted);
3922+
chat.param
3923+
.remove(Param::Unpromoted)
3924+
.set_i64(Param::GroupNameTimestamp, smeared_time(context));
39213925
chat.update_param(context).await?;
39223926
sync_qr_code_tokens = true;
39233927
} else {

src/receive_imf.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,16 +2450,16 @@ async fn apply_group_changes(
24502450
.filter(|grpname| grpname.len() < 200)
24512451
{
24522452
let grpname = &sanitize_single_line(grpname);
2453-
let old_name = &sanitize_single_line(old_name);
24542453

24552454
let chat_group_name_timestamp =
24562455
chat.param.get_i64(Param::GroupNameTimestamp).unwrap_or(0);
24572456
let group_name_timestamp = group_name_timestamp.unwrap_or(mime_parser.timestamp_sent);
24582457
// To provide group name consistency, compare names if timestamps are equal.
2459-
if (chat_group_name_timestamp, grpname) < (group_name_timestamp, old_name)
2458+
if (chat_group_name_timestamp, grpname) < (group_name_timestamp, &chat.name)
24602459
&& chat_id
24612460
.update_timestamp(context, Param::GroupNameTimestamp, group_name_timestamp)
24622461
.await?
2462+
&& grpname != &chat.name
24632463
{
24642464
info!(context, "Updating grpname for chat {chat_id}.");
24652465
context
@@ -2472,6 +2472,7 @@ async fn apply_group_changes(
24722472
.get_header(HeaderDef::ChatGroupNameChanged)
24732473
.is_some()
24742474
{
2475+
let old_name = &sanitize_single_line(old_name);
24752476
better_msg.get_or_insert(
24762477
stock_str::msg_grp_name(context, old_name, grpname, from_id).await,
24772478
);

src/receive_imf/receive_imf_tests.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5433,6 +5433,29 @@ async fn test_rename_chat_on_missing_message() -> Result<()> {
54335433
Ok(())
54345434
}
54355435

5436+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
5437+
async fn test_rename_chat_after_creating_invite() -> Result<()> {
5438+
let mut tcm = TestContextManager::new();
5439+
let alice = &tcm.alice().await;
5440+
let bob = &tcm.bob().await;
5441+
for populate_before_securejoin in [false, true] {
5442+
let alice_chat_id = create_group_chat(alice, ProtectionStatus::Protected, "Group").await?;
5443+
let qr = get_securejoin_qr(alice, Some(alice_chat_id)).await?;
5444+
5445+
SystemTime::shift(Duration::from_secs(60));
5446+
chat::set_chat_name(alice, alice_chat_id, "Renamed").await?;
5447+
if populate_before_securejoin {
5448+
send_text_msg(alice, alice_chat_id, "populate".to_string()).await?;
5449+
alice.pop_sent_msg().await;
5450+
}
5451+
5452+
let bob_chat_id = tcm.exec_securejoin_qr(bob, alice, &qr).await;
5453+
let bob_chat = Chat::load_from_db(bob, bob_chat_id).await?;
5454+
assert_eq!(bob_chat.get_name(), "Renamed");
5455+
}
5456+
Ok(())
5457+
}
5458+
54365459
/// Tests that creating a group
54375460
/// is preferred over assigning message to existing
54385461
/// chat based on `In-Reply-To` and `References`.

src/tools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub(crate) fn gm2local_offset() -> i64 {
179179

180180
/// Returns the current smeared timestamp,
181181
///
182-
/// The returned timestamp MUST NOT be sent out.
182+
/// The returned timestamp MAY NOT be unique and MUST NOT go to "Date" header.
183183
pub(crate) fn smeared_time(context: &Context) -> i64 {
184184
let now = time();
185185
let ts = context.smeared_timestamp.current();

0 commit comments

Comments
 (0)