diff --git a/crates/matrix-sdk-crypto/src/session_manager/sessions.rs b/crates/matrix-sdk-crypto/src/session_manager/sessions.rs index 23a3f5cbe..8cb95ff6b 100644 --- a/crates/matrix-sdk-crypto/src/session_manager/sessions.rs +++ b/crates/matrix-sdk-crypto/src/session_manager/sessions.rs @@ -516,7 +516,6 @@ mod tests { let users_for_key_claim = Arc::new(DashMap::new()); let account = ReadOnlyAccount::with_device_id(user_id, device_id); let store = Arc::new(CryptoStoreWrapper::new(user_id, MemoryStore::new())); - store.save_account(account.clone()).await.unwrap(); let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id))); let verification = VerificationMachine::new( account.static_data().clone(), @@ -525,6 +524,7 @@ mod tests { ); let store = Store::new(account.clone(), identity, store, verification); + store.save_account(account.clone()).await.unwrap(); let account = Account { static_data: account.static_data.clone(), store: store.clone() }; diff --git a/crates/matrix-sdk-crypto/src/store/integration_tests.rs b/crates/matrix-sdk-crypto/src/store/integration_tests.rs index 5a5dc4e53..899bc2d83 100644 --- a/crates/matrix-sdk-crypto/src/store/integration_tests.rs +++ b/crates/matrix-sdk-crypto/src/store/integration_tests.rs @@ -65,7 +65,8 @@ macro_rules! cryptostore_integration_tests { pub async fn get_loaded_store(name: &str) -> (ReadOnlyAccount, impl CryptoStore) { let store = get_store(name, None).await; let account = get_account(); - store.save_account(account.clone()).await.expect("Can't save account"); + + store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account"); (account, store) } @@ -114,7 +115,7 @@ macro_rules! cryptostore_integration_tests { assert!(store.load_account().await.unwrap().is_none()); let account = get_account(); - store.save_account(account).await.expect("Can't save account"); + store.save_changes(Changes { account: Some(account), ..Default::default() }).await.expect("Can't save account"); assert!(store.get_static_account().is_some()); } @@ -123,7 +124,7 @@ macro_rules! cryptostore_integration_tests { let store = get_store("load_account", None).await; let account = get_account(); - store.save_account(account.clone()).await.expect("Can't save account"); + store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account"); let loaded_account = store.load_account().await.expect("Can't load account"); let loaded_account = loaded_account.unwrap(); @@ -137,7 +138,7 @@ macro_rules! cryptostore_integration_tests { get_store("load_account_with_passphrase", Some("secret_passphrase")).await; let account = get_account(); - store.save_account(account.clone()).await.expect("Can't save account"); + store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account"); let loaded_account = store.load_account().await.expect("Can't load account"); let loaded_account = loaded_account.unwrap(); @@ -150,12 +151,12 @@ macro_rules! cryptostore_integration_tests { let store = get_store("save_and_share_account", None).await; let account = get_account(); - store.save_account(account.clone()).await.expect("Can't save account"); + store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account"); account.mark_as_shared(); account.update_uploaded_key_count(50); - store.save_account(account.clone()).await.expect("Can't save account"); + store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account"); let loaded_account = store.load_account().await.expect("Can't load account"); let loaded_account = loaded_account.unwrap(); @@ -168,7 +169,7 @@ macro_rules! cryptostore_integration_tests { async fn load_sessions() { let store = get_store("load_sessions", None).await; let (account, session) = get_account_and_session().await; - store.save_account(account.clone()).await.expect("Can't save account"); + store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account"); let changes = Changes { sessions: vec![session.clone()], ..Default::default() }; @@ -192,7 +193,7 @@ macro_rules! cryptostore_integration_tests { let sender_key = session.sender_key.to_base64(); let session_id = session.session_id().to_owned(); - store.save_account(account.clone()).await.expect("Can't save account"); + store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account"); let changes = Changes { sessions: vec![session.clone()], ..Default::default() }; store.save_changes(changes).await.unwrap(); @@ -490,7 +491,9 @@ macro_rules! cryptostore_integration_tests { let account = ReadOnlyAccount::with_device_id(&user_id, device_id); - store.save_account(account.clone()).await.expect("Can't save account"); + store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }) + .await + .expect("Can't save account"); let own_identity = get_own_identity(); diff --git a/crates/matrix-sdk-crypto/src/store/memorystore.rs b/crates/matrix-sdk-crypto/src/store/memorystore.rs index fa2602d4f..594cc3fdb 100644 --- a/crates/matrix-sdk-crypto/src/store/memorystore.rs +++ b/crates/matrix-sdk-crypto/src/store/memorystore.rs @@ -130,10 +130,6 @@ impl CryptoStore for MemoryStore { Ok(None) } - async fn save_account(&self, _: ReadOnlyAccount) -> Result<()> { - Ok(()) - } - async fn load_identity(&self) -> Result> { Ok(None) } @@ -419,7 +415,7 @@ mod tests { let store = MemoryStore::new(); assert!(store.load_account().await.unwrap().is_none()); - store.save_account(account).await.unwrap(); + store.save_changes(Changes { account: Some(account), ..Default::default() }).await.unwrap(); store.save_sessions(vec![session.clone()]).await; diff --git a/crates/matrix-sdk-crypto/src/store/mod.rs b/crates/matrix-sdk-crypto/src/store/mod.rs index 1b6f982ea..1b5e30852 100644 --- a/crates/matrix-sdk-crypto/src/store/mod.rs +++ b/crates/matrix-sdk-crypto/src/store/mod.rs @@ -609,6 +609,13 @@ impl Store { self.inner.store.save_changes(changes).await } + pub(crate) async fn save_account(&self, account: ReadOnlyAccount) -> Result<()> { + self.inner + .store + .save_changes(Changes { account: Some(account), ..Default::default() }) + .await + } + /// Compare the given `InboundGroupSession` with an existing session we have /// in the store. /// diff --git a/crates/matrix-sdk-crypto/src/store/traits.rs b/crates/matrix-sdk-crypto/src/store/traits.rs index 8c206b448..fa41870c4 100644 --- a/crates/matrix-sdk-crypto/src/store/traits.rs +++ b/crates/matrix-sdk-crypto/src/store/traits.rs @@ -43,13 +43,6 @@ pub trait CryptoStore: AsyncTraitDeps { /// Load an account that was previously stored. async fn load_account(&self) -> Result, Self::Error>; - /// Save the given account in the store. - /// - /// # Arguments - /// - /// * `account` - The account that should be stored. - async fn save_account(&self, account: ReadOnlyAccount) -> Result<(), Self::Error>; - /// Try to load a private cross signing identity, if one is stored. async fn load_identity(&self) -> Result, Self::Error>; @@ -287,10 +280,6 @@ impl CryptoStore for EraseCryptoStoreError { self.0.load_account().await.map_err(Into::into) } - async fn save_account(&self, account: ReadOnlyAccount) -> Result<()> { - self.0.save_account(account).await.map_err(Into::into) - } - async fn load_identity(&self) -> Result> { self.0.load_identity().await.map_err(Into::into) } diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store.rs b/crates/matrix-sdk-indexeddb/src/crypto_store.rs index 757fe5e61..fb60e3ffa 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store.rs @@ -823,11 +823,6 @@ impl_crypto_store! { } } - async fn save_account(&self, account: ReadOnlyAccount) -> Result<()> { - self.save_changes(Changes { account: Some(account), ..Default::default() }) - .await - } - async fn load_identity(&self) -> Result> { if let Some(pickle) = self .inner diff --git a/crates/matrix-sdk-sqlite/src/crypto_store.rs b/crates/matrix-sdk-sqlite/src/crypto_store.rs index e981a0911..af213aa72 100644 --- a/crates/matrix-sdk-sqlite/src/crypto_store.rs +++ b/crates/matrix-sdk-sqlite/src/crypto_store.rs @@ -665,15 +665,6 @@ impl CryptoStore for SqliteCryptoStore { } } - async fn save_account(&self, account: ReadOnlyAccount) -> Result<()> { - *self.static_account.write().unwrap() = Some(account.static_data().clone()); - - let pickled_account = account.pickle().await; - let serialized_account = self.serialize_value(&pickled_account)?; - self.acquire().await?.set_kv("account", serialized_account).await?; - Ok(()) - } - async fn load_identity(&self) -> Result> { let conn = self.acquire().await?; if let Some(i) = conn.get_kv("identity").await? {