Skip to content

Commit 3d6d798

Browse files
committed
docs(base): Document the room_joined() method a bit better
1 parent 935ffa5 commit 3d6d798

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/matrix-sdk-base/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ unicode-normalization.workspace = true
8686
uniffi = { workspace = true, optional = true }
8787

8888
[dev-dependencies]
89+
anyhow.workspace = true
8990
assert_matches.workspace = true
9091
assert_matches2.workspace = true
9192
assign = "1.1.1"

crates/matrix-sdk-base/src/client.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,42 @@ impl BaseClient {
419419
Ok(room)
420420
}
421421

422-
/// User has joined a room.
422+
/// The user has joined a room using this specific client.
423+
///
424+
/// This method should be called if the user accepts an invite or if they
425+
/// join a public room.
426+
///
427+
/// The method will create a [`Room`] object if one does not exist yet and
428+
/// set the state of the [`Room`] to [`RoomState::Joined`]. The [`Room`]
429+
/// object will be persisted in the cache. Please note that the [`Room`]
430+
/// will be a stub until a sync has been received with the full room
431+
/// state using [`BaseClient::receive_sync_response`].
423432
///
424433
/// Update the internal and cached state accordingly. Return the final Room.
434+
///
435+
/// # Examples
436+
///
437+
/// ```rust
438+
/// # use matrix_sdk_base::{BaseClient, store::StoreConfig, RoomState};
439+
/// # use ruma::OwnedRoomId;
440+
/// # async {
441+
/// # let client = BaseClient::new(StoreConfig::new("example".to_owned()));
442+
/// # async fn send_join_request() -> anyhow::Result<OwnedRoomId> { todo!() }
443+
/// let room_id = send_join_request().await?;
444+
/// let room = client.room_joined(&room_id).await?;
445+
///
446+
/// assert_eq!(room.state(), RoomState::Joined);
447+
/// # anyhow::Ok(()) };
448+
/// ```
425449
pub async fn room_joined(&self, room_id: &RoomId) -> Result<Room> {
426450
let room = self.state_store.get_or_create_room(
427451
room_id,
428452
RoomState::Joined,
429453
self.room_info_notable_update_sender.clone(),
430454
);
431455

456+
// If the state isn't `RoomState::Joined` then this means that we knew about
457+
// this room before. Let's modify the existing state now.
432458
if room.state() != RoomState::Joined {
433459
let _sync_lock = self.sync_lock().lock().await;
434460

0 commit comments

Comments
 (0)