diff --git a/crates/matrix-sdk/src/send_queue.rs b/crates/matrix-sdk/src/send_queue.rs index e324c953af..28ed31a062 100644 --- a/crates/matrix-sdk/src/send_queue.rs +++ b/crates/matrix-sdk/src/send_queue.rs @@ -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>, } +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. @@ -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>>, diff --git a/crates/matrix-sdk/src/send_queue/upload.rs b/crates/matrix-sdk/src/send_queue/upload.rs index 7462d4585b..3f540de462 100644 --- a/crates/matrix-sdk/src/send_queue/upload.rs +++ b/crates/matrix-sdk/src/send_queue/upload.rs @@ -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"); } } } @@ -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"); } } }