Skip to content

Commit 056d4a7

Browse files
authored
refactor(send_queue): vectorize media handles on SendHandle (#4898)
This was broken out of #4838 and is a preliminary step towards implementing [MSC4274](matrix-org/matrix-spec-proposals#4274). The `media_handles` field on `SendHandle` is turned into a vector so that it can hold handles for several media when upload a gallery later. Signed-off-by: Johannes Marbach <[email protected]>
1 parent 5753ca3 commit 056d4a7

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

crates/matrix-sdk/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ simpler methods:
290290
([#4879](https://github.com/matrix-org/matrix-rust-sdk/pull/4879))
291291
- `Oidc::issuer()` was removed.
292292
- The `issuer` field of `UserSession` was removed.
293+
- `SendHandle::media_handles` was generalized into a vector
294+
([#4898](https://github.com/matrix-org/matrix-rust-sdk/pull/4898))
293295

294296
## [0.10.0] - 2025-02-04
295297

crates/matrix-sdk/src/send_queue/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl RoomSendQueue {
455455
let send_handle = SendHandle {
456456
room: self.clone(),
457457
transaction_id: transaction_id.clone(),
458-
media_handles: None,
458+
media_handles: vec![],
459459
created_at,
460460
};
461461

@@ -1338,7 +1338,7 @@ impl QueueStorage {
13381338
send_handle: SendHandle {
13391339
room: room.clone(),
13401340
transaction_id: queued.transaction_id,
1341-
media_handles: None,
1341+
media_handles: vec![],
13421342
created_at: queued.created_at,
13431343
},
13441344
send_error: queued.error,
@@ -1395,10 +1395,10 @@ impl QueueStorage {
13951395
send_handle: SendHandle {
13961396
room: room.clone(),
13971397
transaction_id: dep.own_transaction_id.into(),
1398-
media_handles: Some(MediaHandles {
1398+
media_handles: vec![MediaHandles {
13991399
upload_thumbnail_txn: thumbnail_info.map(|info| info.txn),
14001400
upload_file_txn: file_upload,
1401-
}),
1401+
}],
14021402
created_at: dep.created_at,
14031403
},
14041404
send_error: None,
@@ -1911,15 +1911,15 @@ pub struct SendHandle {
19111911
transaction_id: OwnedTransactionId,
19121912

19131913
/// Additional handles for a media upload.
1914-
media_handles: Option<MediaHandles>,
1914+
media_handles: Vec<MediaHandles>,
19151915

19161916
/// The time at which the event to be sent has been created.
19171917
pub created_at: MilliSecondsSinceUnixEpoch,
19181918
}
19191919

19201920
impl SendHandle {
19211921
fn nyi_for_uploads(&self) -> Result<(), RoomSendQueueStorageError> {
1922-
if self.media_handles.is_some() {
1922+
if !self.media_handles.is_empty() {
19231923
Err(RoomSendQueueStorageError::OperationNotImplementedYet)
19241924
} else {
19251925
Ok(())
@@ -1936,7 +1936,7 @@ impl SendHandle {
19361936

19371937
let queue = &self.room.inner.queue;
19381938

1939-
if let Some(handles) = &self.media_handles {
1939+
for handles in &self.media_handles {
19401940
if queue.abort_upload(&self.transaction_id, handles).await? {
19411941
// Propagate a cancelled update.
19421942
let _ = self.room.inner.updates.send(RoomSendQueueUpdate::CancelledLocalEvent {
@@ -2069,7 +2069,7 @@ impl SendHandle {
20692069
// one entry will be updated in the store. The other two are either
20702070
// done, or dependent requests.
20712071

2072-
if let Some(handles) = &self.media_handles {
2072+
for handles in &self.media_handles {
20732073
room.queue
20742074
.mark_as_unwedged(&handles.upload_file_txn)
20752075
.await
@@ -2166,7 +2166,7 @@ impl SendReactionHandle {
21662166
let handle = SendHandle {
21672167
room: self.room.clone(),
21682168
transaction_id: self.transaction_id.clone().into(),
2169-
media_handles: None,
2169+
media_handles: vec![],
21702170
created_at: MilliSecondsSinceUnixEpoch::now(),
21712171
};
21722172

crates/matrix-sdk/src/send_queue/upload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl RoomSendQueue {
223223
let send_handle = SendHandle {
224224
room: self.clone(),
225225
transaction_id: send_event_txn.clone().into(),
226-
media_handles: Some(MediaHandles { upload_thumbnail_txn, upload_file_txn }),
226+
media_handles: vec![MediaHandles { upload_thumbnail_txn, upload_file_txn }],
227227
created_at,
228228
};
229229

0 commit comments

Comments
 (0)