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(room): add methods to customise a Room's privacy settings #4401

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jmartinesp
Copy link
Contributor

@jmartinesp jmartinesp commented Dec 10, 2024

These include:

  • Updating the canonical alias.
  • Creating and removing a room alias from the room directory.
  • Enabling encryption in a room.
  • Updating the join rule of a room.
  • Updating the room history visiblity.
  • Updating the room visibility in the room directory.

Also, expose the room history visibility through the FFI RoomInfo.

  • Public API changes documented in changelogs (optional)

Signed-off-by:

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.29%. Comparing base (d5e7a9c) to head (736f2c0).
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4401      +/-   ##
==========================================
+ Coverage   85.26%   85.29%   +0.03%     
==========================================
  Files         282      283       +1     
  Lines       31170    31225      +55     
==========================================
+ Hits        26576    26633      +57     
+ Misses       4594     4592       -2     

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

@jmartinesp jmartinesp force-pushed the feat/add-room-access-settings branch 3 times, most recently from 400ce36 to 15d2db1 Compare December 11, 2024 09:37
These include:
- Updating the canonical alias.
- Creating and removing a room alias from the room directory.
- Enabling encryption in a room.
- Updating the join rule of a room.
- Updating the room history visiblity.
@jmartinesp jmartinesp force-pushed the feat/add-room-access-settings branch from 15d2db1 to 736f2c0 Compare December 11, 2024 11:30
@jmartinesp jmartinesp marked this pull request as ready for review December 11, 2024 12:19
@jmartinesp jmartinesp requested a review from a team as a code owner December 11, 2024 12:19
@jmartinesp jmartinesp requested review from poljar and removed request for a team December 11, 2024 12:19
@@ -1152,17 +1152,6 @@ impl Client {
let alias = RoomAliasId::parse(alias)?;
self.inner.is_room_alias_available(&alias).await.map_err(Into::into)
}

/// Creates a new room alias associated with the provided room id.
pub async fn create_room_alias(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was just moved to a different file, to have the functions grouped.

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.

Looking good, I left a couple of recommendations but nothing major.

@@ -155,6 +155,12 @@ impl From<RoomSendQueueError> for ClientError {
}
}

impl From<NotYetImplemented> for ClientError {
fn from(_: NotYetImplemented) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're starting to use that more and more, I wonder if NotYetImplemented should contain more information, i.e. so we know which exact feature isn't yet implemented. (if you agree, this can be part of a separate PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, but as you suggest I'd rather make this change in a new PR.

/// Update the canonical alias of the room.
///
/// Note that publishing the alias in the room directory is done separately.
pub async fn update_canonical_alias(&self, new_alias: Option<OwnedRoomAliasId>) -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should explain what providing a None does. An example wouldn't hurt either.


use crate::{Error, Result, Room};

impl Room {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is already in a separate module and adds a lot of functionality, I think it makes sense to introduce a "fake" struct for this that groups all the privacy settings under its umbrella.

pub struct RoomPrivacySettings<'a> {
    room: &'a Room
}

impl RoomPrivacySettings {
    ...
}

That way you would call:

room.privacy_settings().update_canonical_alias(my_alias).await?

Take a look at the Encryption struct and module, we do the same thing there to avoid cluttering the Client object with a lot of E2EE related methods.

Ok(())
}

/// Update room history visibility for this room.
Copy link
Contributor

Choose a reason for hiding this comment

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

The docs on all these methods are a bit terse, it might be nice to explain briefly what the history visibility is and link to the spec for more info.

This applies to the other methods as well, an example here and there wouldn't hurt either.

Comment on lines +587 to +606
/// use matrix_sdk::{
/// ruma::room_alias_id, test_utils::mocks::MatrixMockServer,
/// };
/// use ruma::api::client::room::Visibility;
///
/// let mock_server = MatrixMockServer::new().await;
/// let client = mock_server.client_builder().build().await;
///
/// mock_server
/// .mock_room_directory_remove_room_alias()
/// .ok()
/// .mock_once()
/// .mount()
/// .await;
///
/// client
/// .remove_room_alias(room_alias_id!("#a:b.c"))
/// .await
/// .expect("We should be able to remove the room alias");
/// # anyhow::Ok(()) });
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks a bunch for adding examples on these.

@jmartinesp
Copy link
Contributor Author

It turns out this needs further work, so I'll upload some more changes tomorrow with both the needed changes and some logic changed too to take into account the public room visibility and being able to retry the whole 'publish and update alias' flow if the alias was published but the process got interrupted before.

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.

3 participants