Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ffi): add room alias format validation & room name to alias #4219

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

jmartinesp
Copy link
Contributor

Add two FFI functions:

is_room_alias_format_valid: to check if a passed string has a valid room alias format in Ruma.
room_alias_from_room_display_name: to get a suggestion of a room alias to use given a room name.

  • Public API changes documented in changelogs (optional)

Signed-off-by:

@jmartinesp jmartinesp requested a review from a team as a code owner November 5, 2024 16:46
@jmartinesp jmartinesp requested review from Hywan and removed request for a team November 5, 2024 16:46
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some nits, looks sane.

/// 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put those strings into a const at the top of the function and let's then document what each of those do.

Additionally, let's replace the unwrap() with an expect().


/// 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some simple smoke tests for this function would be nice.

RoomAliasId::parse(alias).is_ok()
}

/// Transforms a Room's display name into a valid room alias.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should implement this on the DisplayName type, seem like it might be generally useful.

Copy link

codecov bot commented Nov 5, 2024

Codecov Report

Attention: Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.

Project coverage is 84.84%. Comparing base (933033c) to head (c19a12a).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk-base/src/rooms/mod.rs 69.23% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4219      +/-   ##
==========================================
- Coverage   84.85%   84.84%   -0.01%     
==========================================
  Files         272      272              
  Lines       29172    29185      +13     
==========================================
+ Hits        24753    24762       +9     
- Misses       4419     4423       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jmartinesp jmartinesp force-pushed the feat/add-room-alias-format-validation branch from 06df59f to c19a12a Compare November 6, 2024 08:06
@jmartinesp
Copy link
Contributor Author

I implemented all those suggestions and some changes to how the room name -> room alias transform works in the last commit.

@jmartinesp jmartinesp enabled auto-merge (rebase) November 6, 2024 08:17
@jmartinesp jmartinesp merged commit fbc914f into main Nov 6, 2024
40 checks passed
@jmartinesp jmartinesp deleted the feat/add-room-alias-format-validation branch November 6, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants