Skip to content

Commit ba5ba66

Browse files
committed
feat(ffi): add room display name to room alias transformation
1 parent abecbf8 commit ba5ba66

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

Cargo.lock

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/matrix-sdk-ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ url = { workspace = true }
4646
zeroize = { workspace = true }
4747
uuid = { version = "1.4.1", features = ["v4"] }
4848
language-tags = "0.3.2"
49+
regex = "1.11.1"
4950

5051
[target.'cfg(target_os = "android")'.dependencies]
5152
paranoid-android = "0.2.1"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
use regex::Regex;
12
use ruma::RoomAliasId;
23

34
/// Verifies the passed `String` matches the expected room alias format.
45
#[matrix_sdk_ffi_macros::export]
56
fn is_room_alias_format_valid(alias: String) -> bool {
67
RoomAliasId::parse(alias).is_ok()
8+
}
9+
10+
/// Transforms a Room's display name into a valid room alias.
11+
#[matrix_sdk_ffi_macros::export]
12+
fn room_alias_from_room_display_name(room_name: String) -> String {
13+
let whitespace_regex = Regex::new(r"\s+").unwrap();
14+
let symbol_regex = Regex::new(r"[!#$&'()*+,/:;=?@\[\]]+").unwrap();
15+
16+
// Replace whitespaces with `-`
17+
let sanitised = whitespace_regex.replace_all(&room_name, "-");
18+
// Remove problematic symbols
19+
let sanitised = symbol_regex.replace_all(&sanitised, "");
20+
// Lowercased
21+
sanitised.to_lowercase()
722
}

0 commit comments

Comments
 (0)