diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 3f2c8e81..e928b18e 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -3421,6 +3421,7 @@ mod test { .with_status(200) .match_header("authorization", "Bearer 1234") .with_body(test_json::SYNC.to_string()) + .expect_at_least(1) .create(); let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); @@ -3430,6 +3431,19 @@ mod test { let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap(); assert_eq!("tutorial".to_string(), room.display_name().await.unwrap()); + + let _m = mock("GET", Matcher::Regex(r"^/_matrix/client/r0/sync\?.*$".to_string())) + .with_status(200) + .match_header("authorization", "Bearer 1234") + .with_body(test_json::INVITE_SYNC.to_string()) + .expect_at_least(1) + .create(); + + let _response = client.sync_once(SyncSettings::new()).await.unwrap(); + + let invited_room = client.get_invited_room(&room_id!("!696r7674:example.com")).unwrap(); + + assert_eq!("My Room Name".to_string(), invited_room.display_name().await.unwrap()); } #[tokio::test] diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index d24a2f1c..e24bbcab 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -685,7 +685,7 @@ impl BaseClient { for room_id in rooms { if let Some(room) = changes.room_infos.get_mut(room_id) { room.base_info.dm_target = Some(user_id.clone()); - } else if let Some(room) = self.store.get_bare_room(room_id) { + } else if let Some(room) = self.store.get_room(room_id) { let mut info = room.clone_info(); info.base_info.dm_target = Some(user_id.clone()); changes.add_room(info); @@ -931,7 +931,7 @@ impl BaseClient { async fn apply_changes(&self, changes: &StateChanges) { for (room_id, room_info) in &changes.room_infos { - if let Some(room) = self.store.get_bare_room(&room_id) { + if let Some(room) = self.store.get_room(&room_id) { room.update_summary(room_info.clone()) } } @@ -958,7 +958,7 @@ impl BaseClient { .collect(); let mut ambiguity_cache = AmbiguityCache::new(self.store.clone()); - if let Some(room) = self.store.get_bare_room(room_id) { + if let Some(room) = self.store.get_room(room_id) { let mut room_info = room.clone_info(); room_info.mark_members_synced(); diff --git a/matrix_sdk_base/src/store/mod.rs b/matrix_sdk_base/src/store/mod.rs index a9b20dd0..f995d311 100644 --- a/matrix_sdk_base/src/store/mod.rs +++ b/matrix_sdk_base/src/store/mod.rs @@ -291,11 +291,6 @@ impl Store { Ok((Self::new(Box::new(inner.clone())), inner.inner)) } - pub(crate) fn get_bare_room(&self, room_id: &RoomId) -> Option { - #[allow(clippy::map_clone)] - self.rooms.get(room_id).map(|r| r.clone()) - } - /// Get all the rooms this store knows about. pub fn get_rooms(&self) -> Vec { self.rooms.iter().filter_map(|r| self.get_room(r.key())).collect() @@ -303,15 +298,17 @@ impl Store { /// Get the room with the given room id. pub fn get_room(&self, room_id: &RoomId) -> Option { - self.get_bare_room(room_id).and_then(|r| match r.room_type() { - RoomType::Joined => Some(r), - RoomType::Left => Some(r), - RoomType::Invited => self.get_stripped_room(room_id), - }) + self.rooms + .get(room_id) + .and_then(|r| match r.room_type() { + RoomType::Joined => Some(r.clone()), + RoomType::Left => Some(r.clone()), + RoomType::Invited => self.get_stripped_room(room_id), + }) + .or_else(|| self.get_stripped_room(room_id)) } fn get_stripped_room(&self, room_id: &RoomId) -> Option { - #[allow(clippy::map_clone)] self.stripped_rooms.get(room_id).map(|r| r.clone()) } @@ -404,7 +401,7 @@ impl StateChanges { /// Update the `StateChanges` struct with the given `RoomInfo`. pub fn add_stripped_room(&mut self, room: RoomInfo) { - self.invited_room_info.insert(room.room_id.as_ref().to_owned(), room); + self.room_infos.insert(room.room_id.as_ref().to_owned(), room); } /// Update the `StateChanges` struct with the given `AnyBasicEvent`. diff --git a/matrix_sdk_test/src/test_json/sync.rs b/matrix_sdk_test/src/test_json/sync.rs index 862b126a..cb1dc57c 100644 --- a/matrix_sdk_test/src/test_json/sync.rs +++ b/matrix_sdk_test/src/test_json/sync.rs @@ -720,7 +720,7 @@ lazy_static! { lazy_static! { pub static ref INVITE_SYNC: JsonValue = json!({ "device_one_time_keys_count": {}, - "next_batch": "s526_47314_0_7_1_1_1_11444_1", + "next_batch": "s526_47314_0_7_1_1_1_11444_2", "device_lists": { "changed": [ "@example:example.org"