mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +03:00
slightly nicer and shorter QR and invite codes (#7390)
- sort garbage to the beginning, readable text to the end - instead of `%20`, make use of `+` to encode spaces - shorter invite links and smaller QR codes by truncation of the names the truncation of the name uses chars() which does not respect grapheme clusters, so that last character may be wrong. not sure if there is a nice and easy alternative, but maybe it's good engoug - the real, full name will come over the wire (exiting truncate() truncates on word boundaries, which is maybe too soft here - names may be long, depending on the language, and not contain any space) moreover, this resolves the "name too long" issue from https://github.com/chatmail/core/issues/7015 --------- Co-authored-by: Hocuri <hocuri@gmx.de>
This commit is contained in:
@@ -556,10 +556,14 @@ async fn decode_openpgp(context: &Context, qr: &str) -> Result<Qr> {
|
||||
fn decode_name(param: &BTreeMap<&str, &str>, key: &str) -> Result<Option<String>> {
|
||||
if let Some(encoded_name) = param.get(key) {
|
||||
let encoded_name = encoded_name.replace('+', "%20"); // sometimes spaces are encoded as `+`
|
||||
match percent_decode_str(&encoded_name).decode_utf8() {
|
||||
Ok(name) => Ok(Some(name.to_string())),
|
||||
let mut name = match percent_decode_str(&encoded_name).decode_utf8() {
|
||||
Ok(name) => name.to_string(),
|
||||
Err(err) => bail!("Invalid QR param {key}: {err}"),
|
||||
};
|
||||
if let Some(n) = name.strip_suffix('_') {
|
||||
name = format!("{n}…");
|
||||
}
|
||||
Ok(Some(name))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user