diff --git a/bindings/matrix-sdk-ffi/src/encryption.rs b/bindings/matrix-sdk-ffi/src/encryption.rs index ab54911b6c4..1ec9547cd92 100644 --- a/bindings/matrix-sdk-ffi/src/encryption.rs +++ b/bindings/matrix-sdk-ffi/src/encryption.rs @@ -254,7 +254,7 @@ impl Encryption { /// Therefore it is necessary to poll the server for an answer every time /// you want to differentiate between those two states. pub async fn backup_exists_on_server(&self) -> Result { - Ok(self.inner.backups().exists_on_server().await?) + Ok(self.inner.backups().fetch_exists_on_server().await?) } pub fn recovery_state(&self) -> RecoveryState { diff --git a/crates/matrix-sdk/src/encryption/backups/mod.rs b/crates/matrix-sdk/src/encryption/backups/mod.rs index 23fa8cb5b3e..0e7800ff9dc 100644 --- a/crates/matrix-sdk/src/encryption/backups/mod.rs +++ b/crates/matrix-sdk/src/encryption/backups/mod.rs @@ -386,8 +386,8 @@ impl Backups { /// Does a backup exist on the server? /// /// This method will request info about the current backup from the - /// homeserver and if a backup exits return `true`, otherwise `false`. - pub async fn exists_on_server(&self) -> Result { + /// homeserver and if a backup exists return `true`, otherwise `false`. + pub async fn fetch_exists_on_server(&self) -> Result { let exists_on_server = self.get_current_version().await?.is_some(); self.client.inner.e2ee.backup_state.set_backup_exists_on_server(exists_on_server); Ok(exists_on_server) @@ -395,23 +395,23 @@ impl Backups { /// Does a backup exist on the server? /// - /// This method is identical to [`Self::exists_on_server`] except that we - /// cache the latest answer in memory and only empty the cache if the local - /// device adds or deletes a backup itself. + /// This method is identical to [`Self::fetch_exists_on_server`] except that + /// we cache the latest answer in memory and only empty the cache if the + /// local device adds or deletes a backup itself. /// /// Do not use this method if you need an accurate answer about whether a - /// backup exists - instead use [`Self::exists_on_server`]. This method is - /// useful when performance is more important than guaranteed accuracy, - /// such as when classifying UTDs. + /// backup exists - instead use [`Self::fetch_exists_on_server`]. This + /// method is useful when performance is more important than guaranteed + /// accuracy, such as when classifying UTDs. pub async fn fast_exists_on_server(&self) -> Result { // If we have an answer cached, return it immediately if let Some(cached_value) = self.client.inner.e2ee.backup_state.backup_exists_on_server() { return Ok(cached_value); } - // Otherwise, delegate to exists_on_server. (It will update the cached value for - // us.) - self.exists_on_server().await + // Otherwise, delegate to fetch_exists_on_server. (It will update the cached + // value for us.) + self.fetch_exists_on_server().await } /// Subscribe to a stream that notifies when a room key for the specified @@ -1147,7 +1147,7 @@ mod test { } #[async_test] - async fn test_when_a_backup_exists_then_exists_on_server_returns_true() { + async fn test_when_a_backup_exists_then_fetch_exists_on_server_returns_true() { let server = MatrixMockServer::new().await; let client = server.client_builder().build().await; @@ -1156,7 +1156,7 @@ mod test { let exists = client .encryption() .backups() - .exists_on_server() + .fetch_exists_on_server() .await .expect("We should be able to check if backups exist on the server"); @@ -1164,7 +1164,7 @@ mod test { } #[async_test] - async fn test_repeated_calls_to_exists_on_server_makes_repeated_requests() { + async fn test_repeated_calls_to_fetch_exists_on_server_makes_repeated_requests() { let server = MatrixMockServer::new().await; let client = server.client_builder().build().await; @@ -1173,15 +1173,15 @@ mod test { let backups = client.encryption().backups(); - // Call exists_on_server twice - backups.exists_on_server().await.unwrap(); - let exists = backups.exists_on_server().await.unwrap(); + // Call fetch_exists_on_server twice + backups.fetch_exists_on_server().await.unwrap(); + let exists = backups.fetch_exists_on_server().await.unwrap(); assert!(exists, "We should deduce that a backup exists on the server"); } #[async_test] - async fn test_when_no_backup_exists_then_exists_on_server_returns_false() { + async fn test_when_no_backup_exists_then_fetch_exists_on_server_returns_false() { let server = MatrixMockServer::new().await; let client = server.client_builder().build().await; @@ -1190,7 +1190,7 @@ mod test { let exists = client .encryption() .backups() - .exists_on_server() + .fetch_exists_on_server() .await .expect("We should be able to check if backups exist on the server"); @@ -1198,7 +1198,7 @@ mod test { } #[async_test] - async fn test_when_server_returns_an_error_then_exists_on_server_returns_an_error() { + async fn test_when_server_returns_an_error_then_fetch_exists_on_server_returns_an_error() { let server = MatrixMockServer::new().await; let client = server.client_builder().build().await; @@ -1206,7 +1206,7 @@ mod test { let _scope = server.mock_room_keys_version().error429().expect(1).mount_as_scoped().await; - client.encryption().backups().exists_on_server().await.expect_err( + client.encryption().backups().fetch_exists_on_server().await.expect_err( "If the /version endpoint returns a non 404 error we should throw an error", ); } @@ -1215,7 +1215,7 @@ mod test { let _scope = server.mock_room_keys_version().error404().expect(1).mount_as_scoped().await; - client.encryption().backups().exists_on_server().await.expect_err( + client.encryption().backups().fetch_exists_on_server().await.expect_err( "If the /version endpoint returns a non-Matrix 404 error we should throw an error", ); } diff --git a/crates/matrix-sdk/src/encryption/backups/types.rs b/crates/matrix-sdk/src/encryption/backups/types.rs index 9d6c089f503..7f338f4ebfd 100644 --- a/crates/matrix-sdk/src/encryption/backups/types.rs +++ b/crates/matrix-sdk/src/encryption/backups/types.rs @@ -126,7 +126,8 @@ pub enum BackupState { /// The reason we don't know whether a server-side backup exists is that we /// don't get notified by the server about the creation and deletion of /// backups. If we want to know the current state, we need to poll the - /// server, which is done using the [`Backups::exists_on_server()`] method. + /// server, which is done using the [`Backups::fetch_exists_on_server()`] + /// method. #[default] Unknown, /// A new backup is being created by this [`Client`]. This state will be diff --git a/crates/matrix-sdk/src/encryption/recovery/futures.rs b/crates/matrix-sdk/src/encryption/recovery/futures.rs index 61acd9182b4..4317f95f972 100644 --- a/crates/matrix-sdk/src/encryption/recovery/futures.rs +++ b/crates/matrix-sdk/src/encryption/recovery/futures.rs @@ -88,7 +88,7 @@ impl<'a> IntoFuture for Enable<'a> { let future = async move { if !recovery.client.encryption().backups().are_enabled().await { - if recovery.client.encryption().backups().exists_on_server().await? { + if recovery.client.encryption().backups().fetch_exists_on_server().await? { return Err(RecoveryError::BackupExistsOnServer); } else { progress.set(EnableProgress::CreatingBackup); diff --git a/crates/matrix-sdk/src/encryption/recovery/mod.rs b/crates/matrix-sdk/src/encryption/recovery/mod.rs index 214e6cb42b6..18d0a53a3e1 100644 --- a/crates/matrix-sdk/src/encryption/recovery/mod.rs +++ b/crates/matrix-sdk/src/encryption/recovery/mod.rs @@ -243,7 +243,7 @@ impl Recovery { /// ``` #[instrument(skip_all)] pub async fn enable_backup(&self) -> Result<()> { - if !self.client.encryption().backups().exists_on_server().await? { + if !self.client.encryption().backups().fetch_exists_on_server().await? { self.mark_backup_as_enabled().await?; self.client.encryption().backups().create().await?; @@ -503,7 +503,7 @@ impl Recovery { // disabled, then we can automatically enable them. Ok(self.client.inner.e2ee.encryption_settings.auto_enable_backups && !self.client.encryption().backups().are_enabled().await - && !self.client.encryption().backups().exists_on_server().await? + && !self.client.encryption().backups().fetch_exists_on_server().await? && !self.are_backups_marked_as_disabled().await?) } diff --git a/crates/matrix-sdk/src/test_utils/mocks.rs b/crates/matrix-sdk/src/test_utils/mocks.rs index da51b8388b6..74d25a5ac01 100644 --- a/crates/matrix-sdk/src/test_utils/mocks.rs +++ b/crates/matrix-sdk/src/test_utils/mocks.rs @@ -579,7 +579,7 @@ impl MatrixMockServer { /// mock_server.mock_room_keys_version().exists().expect(1).mount().await; /// /// let exists = - /// client.encryption().backups().exists_on_server().await.unwrap(); + /// client.encryption().backups().fetch_exists_on_server().await.unwrap(); /// /// assert!(exists); /// # });