@@ -394,16 +394,42 @@ impl BaseClient {
394
394
Ok ( room)
395
395
}
396
396
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`].
398
407
///
399
408
/// 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
+ /// ```
400
424
pub async fn room_joined ( & self , room_id : & RoomId ) -> Result < Room > {
401
425
let room = self . state_store . get_or_create_room (
402
426
room_id,
403
427
RoomState :: Joined ,
404
428
self . room_info_notable_update_sender . clone ( ) ,
405
429
) ;
406
430
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.
407
433
if room. state ( ) != RoomState :: Joined {
408
434
let _sync_lock = self . sync_lock ( ) . lock ( ) . await ;
409
435
0 commit comments