Skip to content

Commit

Permalink
fixup! feat(send queue): allow aborting media uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Nov 14, 2024
1 parent 5b53112 commit 88ef6f4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
21 changes: 18 additions & 3 deletions crates/matrix-sdk/src/send_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,25 @@ struct BeingSentInfo {
transaction_id: OwnedTransactionId,

/// For an upload request, a trigger to cancel the upload before it
/// completed.
/// completes.
cancel_upload: Option<oneshot::Sender<()>>,
}

impl BeingSentInfo {
/// Aborts the upload, if a trigger is available.
///
/// Consumes the object because the sender is a oneshot and will be consumed
/// upon sending.
fn cancel_upload(self) -> bool {
if let Some(cancel_upload) = self.cancel_upload {
let _ = cancel_upload.send(());
true
} else {
false
}
}
}

#[derive(Clone)]
struct QueueStorage {
/// Reference to the client, to get access to the underlying store.
Expand All @@ -870,8 +885,8 @@ struct QueueStorage {
/// To which room is this storage related.
room_id: OwnedRoomId,

/// All the queued requests that are being sent at the moment, along with
/// associated data that can be useful to act upon them.
/// The one queued request that is being sent at the moment, along with
/// associated data that can be useful to act upon it.
///
/// It also serves as an internal lock on the storage backend.
being_sent: Arc<RwLock<Option<BeingSentInfo>>>,
Expand Down
10 changes: 4 additions & 6 deletions crates/matrix-sdk/src/send_queue/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,8 @@ impl QueueStorage {
if info.transaction_id == *thumbnail_txn {
// SAFETY: we knew it was Some(), two lines above.
let info = being_sent.take().unwrap();
if let Some(trigger) = info.cancel_upload {
trace!("aborting ongoing thumbnail upload");
let _ = trigger.send(());
if info.cancel_upload() {
trace!("aborted ongoing thumbnail upload");
}
}
}
Expand Down Expand Up @@ -483,9 +482,8 @@ impl QueueStorage {
if info.transaction_id == handles.upload_file_txn {
// SAFETY: we knew it was Some(), two lines above.
let info = being_sent.take().unwrap();
if let Some(trigger) = info.cancel_upload {
let _ = trigger.send(());
trace!("aborting ongoing file upload");
if info.cancel_upload() {
trace!("aborted ongoing file upload");
}
}
}
Expand Down

0 comments on commit 88ef6f4

Please sign in to comment.