Skip to content

Commit f04c881

Browse files
authored
feat: Put self-name into group invite codes (#7398)
Fix #7015 by putting the self-name into invite codes for group and broadcast channels. The self-name will be truncated to 16 characters.
1 parent ee6b907 commit f04c881

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/securejoin.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,18 @@ fn inviter_progress(
6262
Ok(())
6363
}
6464

65-
/// Shorten name to max. 25 characters.
65+
/// Shorten name to max. `length` characters.
6666
/// This is to not make QR codes or invite links arbitrary long.
67-
fn shorten_name(name: &str) -> String {
68-
if name.chars().count() > 25 {
67+
fn shorten_name(name: &str, length: usize) -> String {
68+
if name.chars().count() > length {
6969
// We use _ rather than ... to avoid dots at the end of the URL, which would confuse linkifiers
70-
format!("{}_", &name.chars().take(24).collect::<String>())
70+
format!(
71+
"{}_",
72+
&name
73+
.chars()
74+
.take(length.saturating_sub(1))
75+
.collect::<String>()
76+
)
7177
} else {
7278
name.to_string()
7379
}
@@ -126,6 +132,11 @@ pub async fn get_securejoin_qr(context: &Context, chat: Option<ChatId>) -> Resul
126132
let self_addr = context.get_primary_self_addr().await?;
127133
let self_addr_urlencoded = utf8_percent_encode(&self_addr, DISALLOWED_CHARACTERS).to_string();
128134

135+
let self_name = context
136+
.get_config(Config::Displayname)
137+
.await?
138+
.unwrap_or_default();
139+
129140
let qr = if let Some(chat) = chat {
130141
if sync_token {
131142
context
@@ -135,27 +146,29 @@ pub async fn get_securejoin_qr(context: &Context, chat: Option<ChatId>) -> Resul
135146
}
136147

137148
let chat_name = chat.get_name();
138-
let chat_name_shortened = shorten_name(chat_name);
149+
let chat_name_shortened = shorten_name(chat_name, 25);
139150
let chat_name_urlencoded = utf8_percent_encode(&chat_name_shortened, DISALLOWED_CHARACTERS)
140151
.to_string()
141152
.replace("%20", "+");
142153
let grpid = &chat.grpid;
154+
155+
let self_name_shortened = shorten_name(&self_name, 16);
156+
let self_name_urlencoded = utf8_percent_encode(&self_name_shortened, DISALLOWED_CHARACTERS)
157+
.to_string()
158+
.replace("%20", "+");
159+
143160
if chat.typ == Chattype::OutBroadcast {
144161
// For historic reansons, broadcasts currently use j instead of i for the invitenumber.
145162
format!(
146-
"https://i.delta.chat/#{fingerprint}&x={grpid}&j={invitenumber}&s={auth}&a={self_addr_urlencoded}&b={chat_name_urlencoded}",
163+
"https://i.delta.chat/#{fingerprint}&x={grpid}&j={invitenumber}&s={auth}&a={self_addr_urlencoded}&n={self_name_urlencoded}&b={chat_name_urlencoded}",
147164
)
148165
} else {
149166
format!(
150-
"https://i.delta.chat/#{fingerprint}&x={grpid}&i={invitenumber}&s={auth}&a={self_addr_urlencoded}&g={chat_name_urlencoded}",
167+
"https://i.delta.chat/#{fingerprint}&x={grpid}&i={invitenumber}&s={auth}&a={self_addr_urlencoded}&n={self_name_urlencoded}&g={chat_name_urlencoded}",
151168
)
152169
}
153170
} else {
154-
let self_name = context
155-
.get_config(Config::Displayname)
156-
.await?
157-
.unwrap_or_default();
158-
let self_name_shortened = shorten_name(&self_name);
171+
let self_name_shortened = shorten_name(&self_name, 25);
159172
let self_name_urlencoded = utf8_percent_encode(&self_name_shortened, DISALLOWED_CHARACTERS)
160173
.to_string()
161174
.replace("%20", "+");

0 commit comments

Comments
 (0)