From a6514b0cffa693eb80fe238920f122b5138f7c6d Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 25 Feb 2022 15:32:59 +0100 Subject: [PATCH] indexeddb formatting --- .../matrix-sdk-indexeddb/src/cryptostore.rs | 3 +- .../matrix-sdk-indexeddb/src/state_store.rs | 62 ++++++++----------- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/crates/matrix-sdk-indexeddb/src/cryptostore.rs b/crates/matrix-sdk-indexeddb/src/cryptostore.rs index 9040f581b..09b703425 100644 --- a/crates/matrix-sdk-indexeddb/src/cryptostore.rs +++ b/crates/matrix-sdk-indexeddb/src/cryptostore.rs @@ -770,8 +770,7 @@ impl IndexeddbStore { .object_store(KEYS::SECRET_REQUESTS_BY_INFO)? .get(&key_info.as_key().encode())? .await? - .map(|i| i.as_string()) - .flatten(); + .and_then(|i| i.as_string()); if let Some(id) = id { self.get_outgoing_key_request_helper(&id).await } else { diff --git a/crates/matrix-sdk-indexeddb/src/state_store.rs b/crates/matrix-sdk-indexeddb/src/state_store.rs index 8fd40f01c..2b2ede819 100644 --- a/crates/matrix-sdk-indexeddb/src/state_store.rs +++ b/crates/matrix-sdk-indexeddb/src/state_store.rs @@ -297,19 +297,17 @@ impl IndexeddbStore { .object_store(KEYS::SESSION)? .get(&(KEYS::FILTER, filter_name).encode())? .await? - .map(|f| f.as_string()) - .flatten()) + .and_then(|f| f.as_string())) } pub async fn get_sync_token(&self) -> Result> { - Ok(self - .inner + self.inner .transaction_on_one_with_mode(KEYS::SYNC_TOKEN, IdbTransactionMode::Readonly)? .object_store(KEYS::SYNC_TOKEN)? .get(&JsValue::from_str(KEYS::SYNC_TOKEN))? .await? .map(|f| self.deserialize_event(f)) - .transpose()?) + .transpose() } pub async fn save_changes(&self, changes: &StateChanges) -> Result<()> { @@ -495,11 +493,10 @@ impl IndexeddbStore { for (user_id, receipt) in receipts { let key = (room, receipt_type, user_id).encode(); - if let Some((old_event, _)) = room_user_receipts - .get(&key)? - .await? - .map(|f| self.deserialize_event::<(Box, Receipt)>(f).ok()) - .flatten() + if let Some((old_event, _)) = + room_user_receipts.get(&key)?.await?.and_then(|f| { + self.deserialize_event::<(Box, Receipt)>(f).ok() + }) { room_event_receipts .delete(&(room, receipt_type, &old_event, user_id).encode())?; @@ -700,14 +697,13 @@ impl IndexeddbStore { } pub async fn get_presence_event(&self, user_id: &UserId) -> Result>> { - Ok(self - .inner + self.inner .transaction_on_one_with_mode(KEYS::PRESENCE, IdbTransactionMode::Readonly)? .object_store(KEYS::PRESENCE)? .get(&user_id.encode())? .await? .map(|f| self.deserialize_event(f)) - .transpose()?) + .transpose() } pub async fn get_state_event( @@ -716,14 +712,13 @@ impl IndexeddbStore { event_type: EventType, state_key: &str, ) -> Result>> { - Ok(self - .inner + self.inner .transaction_on_one_with_mode(KEYS::ROOM_STATE, IdbTransactionMode::Readonly)? .object_store(KEYS::ROOM_STATE)? .get(&(room_id, &event_type, state_key).encode())? .await? .map(|f| self.deserialize_event(f)) - .transpose()?) + .transpose() } pub async fn get_state_events( @@ -748,14 +743,13 @@ impl IndexeddbStore { room_id: &RoomId, user_id: &UserId, ) -> Result> { - Ok(self - .inner + self.inner .transaction_on_one_with_mode(KEYS::PROFILES, IdbTransactionMode::Readonly)? .object_store(KEYS::PROFILES)? .get(&(room_id, user_id).encode())? .await? .map(|f| self.deserialize_event(f)) - .transpose()?) + .transpose() } pub async fn get_member_event( @@ -763,14 +757,13 @@ impl IndexeddbStore { room_id: &RoomId, state_key: &UserId, ) -> Result> { - Ok(self - .inner + self.inner .transaction_on_one_with_mode(KEYS::MEMBERS, IdbTransactionMode::Readonly)? .object_store(KEYS::MEMBERS)? .get(&(room_id, state_key).encode())? .await? .map(|f| self.deserialize_event(f)) - .transpose()?) + .transpose() } pub async fn get_user_ids_stream(&self, room_id: &RoomId) -> Result>> { @@ -867,14 +860,13 @@ impl IndexeddbStore { &self, event_type: EventType, ) -> Result>> { - Ok(self - .inner + self.inner .transaction_on_one_with_mode(KEYS::ACCOUNT_DATA, IdbTransactionMode::Readonly)? .object_store(KEYS::ACCOUNT_DATA)? .get(&JsValue::from_str(event_type.as_str()))? .await? .map(|f| self.deserialize_event(f).map_err::(|e| e)) - .transpose()?) + .transpose() } pub async fn get_room_account_data_event( @@ -882,14 +874,13 @@ impl IndexeddbStore { room_id: &RoomId, event_type: EventType, ) -> Result>> { - Ok(self - .inner + self.inner .transaction_on_one_with_mode(KEYS::ROOM_ACCOUNT_DATA, IdbTransactionMode::Readonly)? .object_store(KEYS::ROOM_ACCOUNT_DATA)? .get(&(room_id.as_str(), event_type.as_str()).encode())? .await? .map(|f| self.deserialize_event(f).map_err::(|e| e)) - .transpose()?) + .transpose() } async fn get_user_room_receipt_event( @@ -898,14 +889,13 @@ impl IndexeddbStore { receipt_type: ReceiptType, user_id: &UserId, ) -> Result, Receipt)>> { - Ok(self - .inner + self.inner .transaction_on_one_with_mode(KEYS::ROOM_USER_RECEIPTS, IdbTransactionMode::Readonly)? .object_store(KEYS::ROOM_USER_RECEIPTS)? .get(&(room_id.as_str(), receipt_type.as_ref(), user_id.as_str()).encode())? .await? .map(|f| self.deserialize_event(f)) - .transpose()?) + .transpose() } async fn get_event_room_receipt_events( @@ -956,14 +946,13 @@ impl IndexeddbStore { async fn get_media_content(&self, request: &MediaRequest) -> Result>> { let key = (&request.media_type.unique_key(), &request.format.unique_key()).encode(); - Ok(self - .inner + self.inner .transaction_on_one_with_mode(KEYS::MEDIA, IdbTransactionMode::Readonly)? .object_store(KEYS::MEDIA)? .get(&key)? .await? .map(|f| self.deserialize_event(f)) - .transpose()?) + .transpose() } async fn get_custom_value(&self, key: &[u8]) -> Result>> { @@ -974,14 +963,13 @@ impl IndexeddbStore { } async fn get_custom_value_for_js(&self, jskey: &JsValue) -> Result>> { - Ok(self - .inner + self.inner .transaction_on_one_with_mode(KEYS::CUSTOM, IdbTransactionMode::Readonly)? .object_store(KEYS::CUSTOM)? .get(jskey)? .await? .map(|f| self.deserialize_event(f)) - .transpose()?) + .transpose() } async fn set_custom_value(&self, key: &[u8], value: Vec) -> Result>> {