From 51f0a487ceffd8463f8291c92b315bfe7359ada4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 13 May 2020 13:23:16 +0200 Subject: [PATCH] base: Remove the stale rooms from the hashmaps. --- matrix_sdk_base/src/client.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index 6f249d69..b0f4a26a 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -310,6 +310,11 @@ impl BaseClient { } pub(crate) async fn get_or_create_joined_room(&self, room_id: &RoomId) -> Arc> { + // If this used to be an invited or left room remove them from our other + // hashmaps. + self.invited_rooms.write().await.remove(room_id); + self.left_rooms.write().await.remove(room_id); + let mut rooms = self.joined_rooms.write().await; #[allow(clippy::or_fun_call)] rooms @@ -344,6 +349,10 @@ impl BaseClient { } pub(crate) async fn get_or_create_invited_room(&self, room_id: &RoomId) -> Arc> { + // Remove the left rooms only here, since a join -> invite action per + // spec can't happen. + self.left_rooms.write().await.remove(room_id); + let mut rooms = self.invited_rooms.write().await; #[allow(clippy::or_fun_call)] rooms @@ -378,6 +387,11 @@ impl BaseClient { } pub(crate) async fn get_or_create_left_room(&self, room_id: &RoomId) -> Arc> { + // If this used to be an invited or joined room remove them from our other + // hashmaps. + self.invited_rooms.write().await.remove(room_id); + self.joined_rooms.write().await.remove(room_id); + let mut rooms = self.left_rooms.write().await; #[allow(clippy::or_fun_call)] rooms