Skip to content

Commit c5d1ef2

Browse files
committed
Merge EventSendProgress::MediaUploadProgress and EventSendProgress::UploadedMedia into EventSendProgress::MediaUpload
1 parent 86ee02a commit c5d1ef2

File tree

6 files changed

+44
-33
lines changed

6 files changed

+44
-33
lines changed

bindings/matrix-sdk-ffi/src/timeline/mod.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl TryInto<Reply> for ReplyParameters {
273273
#[derive(Clone, Copy, uniffi::Enum)]
274274
pub enum EventSendProgress {
275275
/// A media is being uploaded.
276-
MediaUploadProgress {
276+
MediaUpload {
277277
/// The index of the media within the transaction. A file and its
278278
/// thumbnail share the same index.
279279
index: u64,
@@ -284,26 +284,13 @@ pub enum EventSendProgress {
284284
/// The current upload progress.
285285
progress: TransmissionProgress,
286286
},
287-
288-
/// A media has finished uploading.
289-
UploadedMedia {
290-
/// The index of the media within the transaction. A file and its
291-
/// thumbnail share the same index.
292-
index: u64,
293-
294-
/// Is the media a thumbnail?
295-
is_thumbnail: bool,
296-
},
297287
}
298288

299289
impl From<SdkEventSendProgress> for EventSendProgress {
300290
fn from(value: SdkEventSendProgress) -> Self {
301291
match value {
302-
SdkEventSendProgress::MediaUploadProgress { index, is_thumbnail, progress } => {
303-
Self::MediaUploadProgress { index, is_thumbnail, progress: progress.into() }
304-
}
305-
SdkEventSendProgress::UploadedMedia { index, is_thumbnail } => {
306-
Self::UploadedMedia { index, is_thumbnail }
292+
SdkEventSendProgress::MediaUpload { index, is_thumbnail, progress } => {
293+
Self::MediaUpload { index, is_thumbnail, progress: progress.into() }
307294
}
308295
}
309296
}

crates/matrix-sdk-base/src/store/send_queue.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ pub struct SentMediaInfo {
379379
/// thumbnail media source.
380380
pub file: MediaSource,
381381

382+
/// The number of bytes uploaded for the file.
383+
#[serde(default)]
384+
pub bytes: usize,
385+
382386
/// Optional thumbnail previously uploaded, when uploading a file.
383387
///
384388
/// When uploading a thumbnail, this is set to `None`.

crates/matrix-sdk-ui/src/timeline/controller/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use matrix_sdk::{
3131
send_queue::{
3232
LocalEcho, LocalEchoContent, RoomSendQueueUpdate, SendHandle, SendReactionHandle,
3333
},
34-
Result, Room,
34+
Result, Room, TransmissionProgress,
3535
};
3636
use ruma::{
3737
api::client::receipt::create_receipt::v3::ReceiptType as SendReceiptType,
@@ -1322,11 +1322,17 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
13221322
.await;
13231323
}
13241324

1325-
RoomSendQueueUpdate::UploadedMedia { related_to, index, is_thumbnail, .. } => {
1325+
RoomSendQueueUpdate::UploadedMedia {
1326+
related_to, bytes, index, is_thumbnail, ..
1327+
} => {
13261328
self.update_event_send_state(
13271329
&related_to,
13281330
EventSendState::NotSentYet {
1329-
progress: Some(EventSendProgress::UploadedMedia { index, is_thumbnail }),
1331+
progress: Some(EventSendProgress::MediaUpload {
1332+
index,
1333+
is_thumbnail,
1334+
progress: TransmissionProgress { current: bytes, total: bytes },
1335+
}),
13301336
},
13311337
)
13321338
.await;
@@ -1341,7 +1347,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
13411347
self.update_event_send_state(
13421348
&related_to,
13431349
EventSendState::NotSentYet {
1344-
progress: Some(EventSendProgress::MediaUploadProgress {
1350+
progress: Some(EventSendProgress::MediaUpload {
13451351
index,
13461352
is_thumbnail,
13471353
progress,

crates/matrix-sdk-ui/src/timeline/event_item/local.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub enum EventSendState {
9292
#[derive(Clone, Debug)]
9393
pub enum EventSendProgress {
9494
/// A media is being uploaded.
95-
MediaUploadProgress {
95+
MediaUpload {
9696
/// The index of the media within the transaction. A file and its
9797
/// thumbnail share the same index.
9898
index: u64,
@@ -103,13 +103,4 @@ pub enum EventSendProgress {
103103
/// The current upload progress.
104104
progress: TransmissionProgress,
105105
},
106-
107-
/// A media has finished uploading.
108-
UploadedMedia {
109-
/// The index of the media within the transaction. A file and its
110-
/// thumbnail share the same index.
111-
index: u64,
112-
/// Is the media a thumbnail?
113-
is_thumbnail: bool,
114-
},
115106
}

crates/matrix-sdk/src/encryption/futures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{config::RequestConfig, Client, Media, Result, TransmissionProgress};
3232
pub struct UploadEncryptedFile<'a, R: ?Sized> {
3333
client: &'a Client,
3434
reader: &'a mut R,
35-
send_progress: SharedObservable<TransmissionProgress>,
35+
pub(crate) send_progress: SharedObservable<TransmissionProgress>,
3636
request_config: Option<RequestConfig>,
3737
}
3838

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ impl RoomSendQueue {
643643
let _ = updates.send(RoomSendQueueUpdate::UploadedMedia {
644644
related_to: related_txn_id.as_ref().unwrap_or(&txn_id).clone(),
645645
file: media_info.file,
646+
bytes: media_info.bytes,
646647
index,
647648
is_thumbnail,
648649
});
@@ -776,6 +777,8 @@ impl RoomSendQueue {
776777
))
777778
})?;
778779

780+
let bytes;
781+
779782
#[cfg(feature = "e2e-encryption")]
780783
let media_source = if room.latest_encryption_state().await?.is_encrypted() {
781784
trace!("upload will be encrypted (encrypted room)");
@@ -789,28 +792,44 @@ impl RoomSendQueue {
789792
req = req.with_send_progress_observable(watcher);
790793
};
791794

795+
let progress = req.send_progress.clone();
792796
let encrypted_file = req.await?;
797+
bytes = progress.get().total;
798+
793799
MediaSource::Encrypted(Box::new(encrypted_file))
794800
} else {
795801
trace!("upload will be in clear text (room without encryption)");
796802
let request_config = RequestConfig::short_retry()
797803
.timeout(Media::reasonable_upload_timeout(&data));
798804
let mut req =
799805
room.client().media().upload(&mime, data, Some(request_config));
806+
800807
if let Some(watcher) = progress_watcher {
801808
req = req.with_send_progress_observable(watcher);
802809
};
803810

811+
let progress = req.send_progress.clone();
804812
let res = req.await?;
813+
bytes = progress.get().total;
814+
805815
MediaSource::Plain(res.content_uri)
806816
};
807817

808818
#[cfg(not(feature = "e2e-encryption"))]
809819
let media_source = {
810820
let request_config = RequestConfig::short_retry()
811821
.timeout(Media::reasonable_upload_timeout(&data));
812-
let res =
813-
room.client().media().upload(&mime, data, Some(request_config)).await?;
822+
let mut req =
823+
room.client().media().upload(&mime, data, Some(request_config));
824+
825+
if let Some(watcher) = progress_watcher {
826+
req = req.with_send_progress_observable(watcher);
827+
};
828+
829+
let progress = req.send_progress.clone();
830+
let res = req.await?;
831+
bytes = progress.get().total;
832+
814833
MediaSource::Plain(res.content_uri)
815834
};
816835

@@ -825,6 +844,7 @@ impl RoomSendQueue {
825844
thumbnail: thumbnail_source,
826845
#[cfg(feature = "unstable-msc4274")]
827846
accumulated,
847+
bytes,
828848
}))
829849
};
830850

@@ -2137,6 +2157,9 @@ pub enum RoomSendQueueUpdate {
21372157
/// The final media source for the file that was just uploaded.
21382158
file: MediaSource,
21392159

2160+
/// The number of bytes uploaded for the file.
2161+
bytes: usize,
2162+
21402163
/// The index of the media within the transaction. A file and its
21412164
/// thumbnail share the same index.
21422165
index: u64,

0 commit comments

Comments
 (0)