From 3da29a418f303458afb1bbbb9cdb160b32f4aa5b Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 13 Jan 2025 15:26:09 +0100 Subject: [PATCH] stylistic changes --- .../matrix-sdk-indexeddb/src/state_store/mod.rs | 12 ++++++++---- crates/matrix-sdk-sqlite/src/state_store.rs | 12 ++++++++---- crates/matrix-sdk/src/send_queue/mod.rs | 17 ++++------------- crates/matrix-sdk/src/send_queue/upload.rs | 1 + 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/matrix-sdk-indexeddb/src/state_store/mod.rs b/crates/matrix-sdk-indexeddb/src/state_store/mod.rs index c625c5b4999..ff8142104fb 100644 --- a/crates/matrix-sdk-indexeddb/src/state_store/mod.rs +++ b/crates/matrix-sdk-indexeddb/src/state_store/mod.rs @@ -443,8 +443,8 @@ struct PersistedQueuedRequest { priority: Option, /// The time the original message was first attempted to be sent at. - #[serde(skip_serializing_if = "Option::is_none")] - created_at: Option, + #[serde(default = "created_now")] + created_at: MilliSecondsSinceUnixEpoch, // Migrated fields: keep these private, they're not used anymore elsewhere in the code base. /// Deprecated (from old format), now replaced with error field. @@ -453,6 +453,10 @@ struct PersistedQueuedRequest { event: Option, } +fn created_now() -> MilliSecondsSinceUnixEpoch { + MilliSecondsSinceUnixEpoch::now() +} + impl PersistedQueuedRequest { fn into_queued_request(self) -> Option { let kind = @@ -476,7 +480,7 @@ impl PersistedQueuedRequest { transaction_id: self.transaction_id, error, priority, - created_at: self.created_at.unwrap_or(MilliSecondsSinceUnixEpoch::now()), + created_at: self.created_at, }) } } @@ -1412,7 +1416,7 @@ impl_state_store!({ is_wedged: None, event: None, priority: Some(priority), - created_at: Some(created_at), + created_at, }); // Save the new vector into db. diff --git a/crates/matrix-sdk-sqlite/src/state_store.rs b/crates/matrix-sdk-sqlite/src/state_store.rs index 8df4e75fcc8..e47fca481e1 100644 --- a/crates/matrix-sdk-sqlite/src/state_store.rs +++ b/crates/matrix-sdk-sqlite/src/state_store.rs @@ -1847,7 +1847,7 @@ impl StateStore for SqliteStateStore { // Note: ROWID is always present and is an auto-incremented integer counter. We // want to maintain the insertion order, so we can sort using it. // Note 2: transaction_id is not encoded, see why in `save_send_queue_event`. - let res: Vec<(String, Vec, Option>, usize, u64)> = self + let res: Vec<(String, Vec, Option>, usize, Option)> = self .acquire() .await? .prepare( @@ -1862,7 +1862,9 @@ impl StateStore for SqliteStateStore { let mut requests = Vec::with_capacity(res.len()); for entry in res { - let created_at = UInt::new(entry.4) + let created_at = entry + .4 + .and_then(UInt::new) .map_or_else(MilliSecondsSinceUnixEpoch::now, MilliSecondsSinceUnixEpoch); requests.push(QueuedRequest { transaction_id: entry.0.into(), @@ -2045,7 +2047,7 @@ impl StateStore for SqliteStateStore { let room_id = self.encode_key(keys::DEPENDENTS_SEND_QUEUE, room_id); // Note: transaction_id is not encoded, see why in `save_send_queue_event`. - let res: Vec<(String, String, Option>, Vec, u64)> = self + let res: Vec<(String, String, Option>, Vec, Option)> = self .acquire() .await? .prepare( @@ -2060,7 +2062,9 @@ impl StateStore for SqliteStateStore { let mut dependent_events = Vec::with_capacity(res.len()); for entry in res { - let created_at = UInt::new(entry.4) + let created_at = entry + .4 + .and_then(UInt::new) .map_or_else(MilliSecondsSinceUnixEpoch::now, MilliSecondsSinceUnixEpoch); dependent_events.push(DependentQueuedRequest { own_transaction_id: entry.0.into(), diff --git a/crates/matrix-sdk/src/send_queue/mod.rs b/crates/matrix-sdk/src/send_queue/mod.rs index a526fa48efa..be839ec39a7 100644 --- a/crates/matrix-sdk/src/send_queue/mod.rs +++ b/crates/matrix-sdk/src/send_queue/mod.rs @@ -1419,7 +1419,6 @@ impl QueueStorage { client: &Client, dependent_request: DependentQueuedRequest, new_updates: &mut Vec, - created_at: MilliSecondsSinceUnixEpoch, ) -> Result { let store = client.store(); @@ -1486,7 +1485,7 @@ impl QueueStorage { .save_send_queue_request( &self.room_id, dependent_request.own_transaction_id.into(), - created_at, + dependent_request.created_at, serializable.into(), Self::HIGH_PRIORITY, ) @@ -1574,7 +1573,7 @@ impl QueueStorage { .save_send_queue_request( &self.room_id, dependent_request.own_transaction_id.into(), - created_at, + dependent_request.created_at, serializable.into(), Self::HIGH_PRIORITY, ) @@ -1677,15 +1676,7 @@ impl QueueStorage { for dependent in canonicalized_dependent_requests { let dependent_id = dependent.own_transaction_id.clone(); - match self - .try_apply_single_dependent_request( - &client, - dependent, - new_updates, - MilliSecondsSinceUnixEpoch::now(), - ) - .await - { + match self.try_apply_single_dependent_request(&client, dependent, new_updates).await { Ok(should_remove) => { if should_remove { // The dependent request has been successfully applied, forget about it. @@ -1914,7 +1905,7 @@ pub struct SendHandle { /// Additional handles for a media upload. media_handles: Option, - /// The time that this send handle was first created + /// The time at which the event to be sent has been created. pub created_at: MilliSecondsSinceUnixEpoch, } diff --git a/crates/matrix-sdk/src/send_queue/upload.rs b/crates/matrix-sdk/src/send_queue/upload.rs index bf5a5f88a1b..96a0df45858 100644 --- a/crates/matrix-sdk/src/send_queue/upload.rs +++ b/crates/matrix-sdk/src/send_queue/upload.rs @@ -186,6 +186,7 @@ impl RoomSendQueue { ); let created_at = MilliSecondsSinceUnixEpoch::now(); + // Save requests in the queue storage. self.inner .queue