-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ffi): add room display name to room alias transformation
- Loading branch information
1 parent
abecbf8
commit ba5ba66
Showing
3 changed files
with
28 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
use regex::Regex; | ||
use ruma::RoomAliasId; | ||
|
||
/// Verifies the passed `String` matches the expected room alias format. | ||
#[matrix_sdk_ffi_macros::export] | ||
fn is_room_alias_format_valid(alias: String) -> bool { | ||
RoomAliasId::parse(alias).is_ok() | ||
} | ||
|
||
/// Transforms a Room's display name into a valid room alias. | ||
#[matrix_sdk_ffi_macros::export] | ||
fn room_alias_from_room_display_name(room_name: String) -> String { | ||
let whitespace_regex = Regex::new(r"\s+").unwrap(); | ||
let symbol_regex = Regex::new(r"[!#$&'()*+,/:;=?@\[\]]+").unwrap(); | ||
|
||
// Replace whitespaces with `-` | ||
let sanitised = whitespace_regex.replace_all(&room_name, "-"); | ||
// Remove problematic symbols | ||
let sanitised = symbol_regex.replace_all(&sanitised, ""); | ||
// Lowercased | ||
sanitised.to_lowercase() | ||
} |