Skip to content

Commit

Permalink
chore(knocking): Add optional reason and server_names parameters …
Browse files Browse the repository at this point in the history
…to `Client::knock`
  • Loading branch information
jmartinesp committed Oct 22, 2024
1 parent f2f99fb commit cab394b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
11 changes: 9 additions & 2 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,9 +977,16 @@ impl Client {
}

/// Knock on a room to join it using its ID or alias.
pub async fn knock(&self, room_id_or_alias: String) -> Result<Arc<Room>, ClientError> {
pub async fn knock(
&self,
room_id_or_alias: String,
reason: Option<String>,
server_names: Vec<String>,
) -> Result<Arc<Room>, ClientError> {
let room_id = RoomOrAliasId::parse(&room_id_or_alias)?;
let room = self.inner.knock(room_id).await?;
let server_names =
server_names.iter().map(ServerName::parse).collect::<Result<Vec<_>, _>>()?;
let room = self.inner.knock(room_id, reason, server_names).await?;
Ok(Arc::new(Room::new(room)))
}

Expand Down
10 changes: 8 additions & 2 deletions crates/matrix-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2243,8 +2243,14 @@ impl Client {

/// Knock on a room given its `room_id_or_alias` to ask for permission to
/// join it.
pub async fn knock(&self, room_id_or_alias: OwnedRoomOrAliasId) -> Result<Room> {
let request = knock_room::v3::Request::new(room_id_or_alias);
pub async fn knock(
&self,
room_id_or_alias: OwnedRoomOrAliasId,
reason: Option<String>,
server_names: Vec<OwnedServerName>,
) -> Result<Room> {
let request =
assign!(knock_room::v3::Request::new(room_id_or_alias), { reason, via: server_names });
let response = self.send(request, None).await?;
let base_room = self.inner.base_client.room_knocked(&response.room_id).await?;
Ok(Room::new(self.clone(), base_room))
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk/tests/integration/room/left.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async fn test_knocking() {
let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap();
assert_eq!(room.state(), RoomState::Left);

let room =
client.knock(OwnedRoomOrAliasId::from((*DEFAULT_TEST_ROOM_ID).to_owned())).await.unwrap();
let room_id = OwnedRoomOrAliasId::from((*DEFAULT_TEST_ROOM_ID).to_owned());
let room = client.knock(room_id, None, Vec::new()).await.unwrap();
assert_eq!(room.state(), RoomState::Knocked);
}

0 comments on commit cab394b

Please sign in to comment.