Skip to content

Commit

Permalink
fixup! chore(send queue): review
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Nov 6, 2024
1 parent 94d566b commit d7c8aa4
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions crates/matrix-sdk/src/send_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
//! - An initial media event is created and uses this temporary MXC ID, and
//! propagated as a local echo for an event.
//! - A [`QueuedRequest`] is pushed to upload the file's media
//! ([`QueuedRequestKind::Upload`]).
//! ([`QueuedRequestKind::MediaUpload`]).
//! - A [`DependentQueuedRequest`] is pushed to finish the upload
//! ([`DependentQueuedRequestKind::FinishUpload`]).
//!
Expand All @@ -106,7 +106,8 @@
//! When there is a thumbnail, things behave similarly, with some tweaks:
//!
//! - the thumbnail's content is also stored into the cache store immediately,
//! - the thumbnail is sent first as an [`QueuedRequestKind::Upload`] request,
//! - the thumbnail is sent first as an [`QueuedRequestKind::MediaUpload`]
//! request,
//! - the file upload is pushed as a dependent request of kind
//! [`DependentQueuedRequestKind::UploadFileWithThumbnail`] (this variant
//! keeps the file's key used to look it up in the cache store).
Expand All @@ -117,11 +118,11 @@
//!
//! - After the thumbnail has been uploaded, the dependent query will retrieve
//! the final MXC ID returned by the homeserver for the thumbnail, and store
//! it into the [`QueuedRequestKind::Upload`]'s `thumbnail_source` field,
//! it into the [`QueuedRequestKind::MediaUpload`]'s `thumbnail_source` field,
//! allowing to remember the thumbnail MXC ID when it's time to finish the
//! upload later.
//! - The dependent request is morphed into another
//! [`QueuedRequestKind::Upload`], for the file itself.
//! [`QueuedRequestKind::MediaUpload`], for the file itself.
//!
//! The rest of the process is then similar to that of uploading a file without
//! a thumbnail. The only difference is that there's a thumbnail source (MXC ID)
Expand Down Expand Up @@ -697,12 +698,8 @@ impl RoomSendQueue {
crate::Error::SendQueueWedgeError(QueueWedgeError::MissingMediaContent),
)?;

let is_encrypted = false;
#[cfg(feature = "e2e-encryption")]
// "is_encrypted ||" is a trick to avoid an unused variable.
let is_encrypted = is_encrypted || room.is_encrypted().await?;

let media_source = if is_encrypted {
let media_source = if room.is_encrypted().await? {
trace!("upload will be encrypted (encrypted room)");
let mut cursor = std::io::Cursor::new(data);
let encrypted_file =
Expand All @@ -714,6 +711,12 @@ impl RoomSendQueue {
MediaSource::Plain(res.content_uri)
};

#[cfg(not(feature = "e2e-encryption"))]
let media_source = {
let res = room.client().media().upload(&mime, data).await?;
MediaSource::Plain(res.content_uri)
};

let uri = match &media_source {
MediaSource::Plain(uri) => uri,
MediaSource::Encrypted(encrypted_file) => &encrypted_file.url,
Expand Down

0 comments on commit d7c8aa4

Please sign in to comment.