@@ -419,16 +419,42 @@ impl BaseClient {
419
419
Ok ( room)
420
420
}
421
421
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`].
423
432
///
424
433
/// 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
+ /// ```
425
449
pub async fn room_joined ( & self , room_id : & RoomId ) -> Result < Room > {
426
450
let room = self . state_store . get_or_create_room (
427
451
room_id,
428
452
RoomState :: Joined ,
429
453
self . room_info_notable_update_sender . clone ( ) ,
430
454
) ;
431
455
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.
432
458
if room. state ( ) != RoomState :: Joined {
433
459
let _sync_lock = self . sync_lock ( ) . lock ( ) . await ;
434
460
0 commit comments