diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index 7c66f271f01..625c66baff5 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -1516,8 +1516,14 @@ impl BaseClient { /// # Arguments /// /// * `room_id` - The id of the room that should be forgotten. - pub async fn forget_room(&self, room_id: &RoomId) -> StoreResult<()> { - self.store.forget_room(room_id).await + pub async fn forget_room(&self, room_id: &RoomId) -> Result<()> { + // Forget the room in the state store. + self.store.forget_room(room_id).await?; + + // Remove the room in the event cache store too. + self.event_cache_store().lock().await?.remove_room(room_id).await?; + + Ok(()) } /// Get the olm machine. diff --git a/crates/matrix-sdk-base/src/error.rs b/crates/matrix-sdk-base/src/error.rs index 8d1a2dd3e22..bc3f2a13633 100644 --- a/crates/matrix-sdk-base/src/error.rs +++ b/crates/matrix-sdk-base/src/error.rs @@ -15,10 +15,13 @@ //! Error conditions. +use matrix_sdk_common::store_locks::LockStoreError; #[cfg(feature = "e2e-encryption")] use matrix_sdk_crypto::{CryptoStoreError, MegolmError, OlmError}; use thiserror::Error; +use crate::event_cache::store::EventCacheStoreError; + /// Result type of the rust-sdk. pub type Result = std::result::Result; @@ -42,6 +45,14 @@ pub enum Error { #[error(transparent)] StateStore(#[from] crate::store::StoreError), + /// An error happened while manipulating the event cache store. + #[error(transparent)] + EventCacheStore(#[from] EventCacheStoreError), + + /// An error happened while attempting to lock the event cache store. + #[error(transparent)] + EventCacheLock(#[from] LockStoreError), + /// An error occurred in the crypto store. #[cfg(feature = "e2e-encryption")] #[error(transparent)] diff --git a/crates/matrix-sdk/tests/integration/room/left.rs b/crates/matrix-sdk/tests/integration/room/left.rs index 7bad0b2377b..723b8572f0a 100644 --- a/crates/matrix-sdk/tests/integration/room/left.rs +++ b/crates/matrix-sdk/tests/integration/room/left.rs @@ -12,6 +12,7 @@ use ruma::{ user_id, OwnedRoomOrAliasId, }; use serde_json::json; +use tokio::task::yield_now; use wiremock::{ matchers::{header, method, path, path_regex}, Mock, ResponseTemplate, @@ -24,6 +25,10 @@ async fn test_forget_non_direct_room() { let (client, server) = logged_in_client_with_server().await; let user_id = client.user_id().unwrap(); + let event_cache = client.event_cache(); + event_cache.subscribe().unwrap(); + event_cache.enable_storage().unwrap(); + Mock::given(method("POST")) .and(path_regex(r"^/_matrix/client/r0/rooms/.*/forget$")) .and(header("authorization", "Bearer 1234")) @@ -47,12 +52,29 @@ async fn test_forget_non_direct_room() { let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); let _response = client.sync_once(sync_settings).await.unwrap(); + // Let the event cache process updates. + yield_now().await; + + { + // There is some data in the cache store. + let event_cache_store = client.event_cache_store().lock().await.unwrap(); + let room_data = event_cache_store.reload_linked_chunk(&DEFAULT_TEST_ROOM_ID).await.unwrap(); + assert!(!room_data.is_empty()); + } + let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap(); assert_eq!(room.state(), RoomState::Left); room.forget().await.unwrap(); assert!(client.get_room(&DEFAULT_TEST_ROOM_ID).is_none()); + + { + // Data in the event cache store has been removed. + let event_cache_store = client.event_cache_store().lock().await.unwrap(); + let room_data = event_cache_store.reload_linked_chunk(&DEFAULT_TEST_ROOM_ID).await.unwrap(); + assert!(room_data.is_empty()); + } } #[async_test]