Skip to content

Commit 7394b34

Browse files
committed
docs(base): Document the room_joined() method a bit better
1 parent be3af5e commit 7394b34

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
@@ -394,16 +394,42 @@ impl BaseClient {
394394
Ok(room)
395395
}
396396

397-
/// User has joined a room.
397+
/// The user has joined a room using this specific client.
398+
///
399+
/// This method should be called if the user accepts an invite or if they
400+
/// join a public room.
401+
///
402+
/// The method will create a [`Room`] object if one does not exist yet and
403+
/// set the state of the [`Room`] to [`RoomState::Joined`]. The [`Room`]
404+
/// object will be persisted in the cache. Please note that the [`Room`]
405+
/// will be a stub until a sync has been received with the full room
406+
/// state using [`BaseClient::receive_sync_response`].
398407
///
399408
/// Update the internal and cached state accordingly. Return the final Room.
409+
///
410+
/// # Examples
411+
///
412+
/// ```rust
413+
/// # use matrix_sdk_base::{BaseClient, store::StoreConfig, RoomState};
414+
/// # use ruma::OwnedRoomId;
415+
/// # async {
416+
/// # let client = BaseClient::new(StoreConfig::new("example".to_owned()));
417+
/// # async fn send_join_request() -> anyhow::Result<OwnedRoomId> { todo!() }
418+
/// let room_id = send_join_request().await?;
419+
/// let room = client.room_joined(&room_id).await?;
420+
///
421+
/// assert_eq!(room.state(), RoomState::Joined);
422+
/// # anyhow::Ok(()) };
423+
/// ```
400424
pub async fn room_joined(&self, room_id: &RoomId) -> Result<Room> {
401425
let room = self.state_store.get_or_create_room(
402426
room_id,
403427
RoomState::Joined,
404428
self.room_info_notable_update_sender.clone(),
405429
);
406430

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

0 commit comments

Comments
 (0)