Skip to content

Commit

Permalink
stylistic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Jan 13, 2025
1 parent eb594cc commit 3da29a4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
12 changes: 8 additions & 4 deletions crates/matrix-sdk-indexeddb/src/state_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ struct PersistedQueuedRequest {
priority: Option<usize>,

/// The time the original message was first attempted to be sent at.
#[serde(skip_serializing_if = "Option::is_none")]
created_at: Option<MilliSecondsSinceUnixEpoch>,
#[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.
Expand All @@ -453,6 +453,10 @@ struct PersistedQueuedRequest {
event: Option<SerializableEventContent>,
}

fn created_now() -> MilliSecondsSinceUnixEpoch {
MilliSecondsSinceUnixEpoch::now()
}

impl PersistedQueuedRequest {
fn into_queued_request(self) -> Option<QueuedRequest> {
let kind =
Expand All @@ -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,
})
}
}
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 8 additions & 4 deletions crates/matrix-sdk-sqlite/src/state_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>, Option<Vec<u8>>, usize, u64)> = self
let res: Vec<(String, Vec<u8>, Option<Vec<u8>>, usize, Option<u64>)> = self
.acquire()
.await?
.prepare(
Expand All @@ -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(),
Expand Down Expand Up @@ -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<u8>>, Vec<u8>, u64)> = self
let res: Vec<(String, String, Option<Vec<u8>>, Vec<u8>, Option<u64>)> = self
.acquire()
.await?
.prepare(
Expand All @@ -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(),
Expand Down
17 changes: 4 additions & 13 deletions crates/matrix-sdk/src/send_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,6 @@ impl QueueStorage {
client: &Client,
dependent_request: DependentQueuedRequest,
new_updates: &mut Vec<RoomSendQueueUpdate>,
created_at: MilliSecondsSinceUnixEpoch,
) -> Result<bool, RoomSendQueueError> {
let store = client.store();

Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1914,7 +1905,7 @@ pub struct SendHandle {
/// Additional handles for a media upload.
media_handles: Option<MediaHandles>,

/// 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,
}

Expand Down
1 change: 1 addition & 0 deletions crates/matrix-sdk/src/send_queue/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ impl RoomSendQueue {
);

let created_at = MilliSecondsSinceUnixEpoch::now();

// Save requests in the queue storage.
self.inner
.queue
Expand Down

0 comments on commit 3da29a4

Please sign in to comment.