Skip to content

Commit c824b3c

Browse files
committed
Report the combined upload progress across thumbnail and media as a percentage
1 parent 7634825 commit c824b3c

File tree

9 files changed

+183
-65
lines changed

9 files changed

+183
-65
lines changed

bindings/matrix-sdk-ffi/src/client.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ impl From<matrix_sdk::TransmissionProgress> for TransmissionProgress {
218218
}
219219
}
220220

221+
/// Progress of sending or receiving a payload in percent.
222+
#[derive(Clone, Copy, uniffi::Record)]
223+
pub struct RelativeTransmissionProgress {
224+
/// The completion percentage as a number between 0 and 1.
225+
pub percentage: f32,
226+
}
227+
228+
impl From<matrix_sdk::RelativeTransmissionProgress> for RelativeTransmissionProgress {
229+
fn from(value: matrix_sdk::RelativeTransmissionProgress) -> Self {
230+
Self { percentage: value.percentage }
231+
}
232+
}
233+
221234
#[derive(uniffi::Object)]
222235
pub struct Client {
223236
pub(crate) inner: AsyncRuntimeDropped<MatrixClient>,

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use uuid::Uuid;
6767
use self::content::TimelineItemContent;
6868
pub use self::msg_like::MessageContent;
6969
use crate::{
70-
client::{ProgressWatcher, TransmissionProgress},
70+
client::{ProgressWatcher, RelativeTransmissionProgress},
7171
error::{ClientError, RoomError},
7272
event::EventOrTransactionId,
7373
helpers::unwrap_or_clone_arc,
@@ -278,19 +278,17 @@ pub enum EventSendProgress {
278278
/// thumbnail share the same index.
279279
index: u64,
280280

281-
/// Is the media a thumbnail?
282-
is_thumbnail: bool,
283-
284-
/// The current upload progress.
285-
progress: TransmissionProgress,
281+
/// The current combined upload progress for both the file and,
282+
/// if it exists, its thumbnail.
283+
progress: RelativeTransmissionProgress,
286284
},
287285
}
288286

289287
impl From<SdkEventSendProgress> for EventSendProgress {
290288
fn from(value: SdkEventSendProgress) -> Self {
291289
match value {
292-
SdkEventSendProgress::MediaUpload { index, is_thumbnail, progress } => {
293-
Self::MediaUpload { index, is_thumbnail, progress: progress.into() }
290+
SdkEventSendProgress::MediaUpload { index, progress } => {
291+
Self::MediaUpload { index, progress: progress.into() }
294292
}
295293
}
296294
}

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

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,21 @@ pub enum QueuedRequestKind {
110110
#[serde(default)]
111111
accumulated: Vec<AccumulatedSentMediaInfo>,
112112

113-
/// Is this a thumbnail upload?
114-
#[serde(default = "default_is_thumbnail")]
115-
is_thumbnail: bool,
113+
/// The number of bytes in the unencrypted file (or thumbnail) to be
114+
/// uploaded by this request.
115+
#[serde(default)]
116+
file_size: usize,
117+
118+
/// If this is a media file upload and a related thumbnail was
119+
/// previously, uploaded, the number of bytes in the unencrypted
120+
/// thumbnail.
121+
#[serde(default)]
122+
thumbnail_file_size: Option<usize>,
123+
124+
/// If this is a thumbnail upload, the number of bytes in the
125+
/// unencrypted media file to be uploaded subsequently.
126+
#[serde(default)]
127+
media_file_size: Option<usize>,
116128
},
117129
}
118130

@@ -247,9 +259,21 @@ pub enum DependentQueuedRequestKind {
247259
#[serde(default = "default_parent_is_thumbnail_upload")]
248260
parent_is_thumbnail_upload: bool,
249261

250-
/// Is this a thumbnail upload?
251-
#[serde(default = "default_is_thumbnail")]
252-
is_thumbnail: bool,
262+
/// The number of bytes in the unencrypted file (or thumbnail) to be
263+
/// uploaded by this request.
264+
#[serde(default)]
265+
file_size: usize,
266+
267+
/// If this is a media file upload and a related thumbnail was
268+
/// previously, uploaded, the number of bytes in the unencrypted
269+
/// thumbnail.
270+
#[serde(default)]
271+
thumbnail_file_size: Option<usize>,
272+
273+
/// If this is a thumbnail upload, the number of bytes in the
274+
/// unencrypted media file to be uploaded subsequently.
275+
#[serde(default)]
276+
media_file_size: Option<usize>,
253277
},
254278

255279
/// Finish an upload by updating references to the media cache and sending
@@ -289,12 +313,6 @@ fn default_parent_is_thumbnail_upload() -> bool {
289313
true
290314
}
291315

292-
/// We don't really have a way to infer the value if it hasn't been set on an
293-
/// old request, so we just default to false.
294-
fn default_is_thumbnail() -> bool {
295-
false
296-
}
297-
298316
/// Detailed record about a thumbnail used when finishing a media upload.
299317
#[derive(Clone, Debug, Serialize, Deserialize)]
300318
pub struct FinishUploadThumbnailInfo {

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,17 +1322,11 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
13221322
.await;
13231323
}
13241324

1325-
RoomSendQueueUpdate::MediaUpload {
1326-
related_to, index, is_thumbnail, progress, ..
1327-
} => {
1325+
RoomSendQueueUpdate::MediaUpload { related_to, index, progress, .. } => {
13281326
self.update_event_send_state(
13291327
&related_to,
13301328
EventSendState::NotSentYet {
1331-
progress: Some(EventSendProgress::MediaUpload {
1332-
index,
1333-
is_thumbnail,
1334-
progress,
1335-
}),
1329+
progress: Some(EventSendProgress::MediaUpload { index, progress }),
13361330
},
13371331
)
13381332
.await;

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use std::sync::Arc;
1616

1717
use as_variant::as_variant;
18-
use matrix_sdk::{send_queue::SendHandle, Error, TransmissionProgress};
18+
use matrix_sdk::{send_queue::SendHandle, Error, RelativeTransmissionProgress};
1919
use ruma::{EventId, OwnedEventId, OwnedTransactionId};
2020

2121
use super::TimelineEventItemId;
@@ -97,10 +97,8 @@ pub enum EventSendProgress {
9797
/// thumbnail share the same index.
9898
index: u64,
9999

100-
/// Is the media a thumbnail?
101-
is_thumbnail: bool,
102-
103-
/// The current upload progress.
104-
progress: TransmissionProgress,
100+
/// The current combined upload progress for both the file and,
101+
/// if it exists, its thumbnail.
102+
progress: RelativeTransmissionProgress,
105103
},
106104
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ pub struct TransmissionProgress {
231231
pub total: usize,
232232
}
233233

234+
/// Progress of sending or receiving a payload in percent.
235+
#[derive(Clone, Copy, Debug, Default)]
236+
pub struct RelativeTransmissionProgress {
237+
/// The completion percentage as a number between 0 and 1.
238+
pub percentage: f32,
239+
}
240+
234241
async fn response_to_http_response(
235242
mut response: reqwest::Response,
236243
) -> Result<http::Response<Bytes>, reqwest::Error> {

crates/matrix-sdk/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub use error::{
7272
Error, HttpError, HttpResult, NotificationSettingsError, RefreshTokenError, Result,
7373
RumaApiError,
7474
};
75-
pub use http_client::TransmissionProgress;
75+
pub use http_client::{RelativeTransmissionProgress, TransmissionProgress};
7676
#[cfg(all(feature = "e2e-encryption", feature = "sqlite"))]
7777
pub use matrix_sdk_sqlite::SqliteCryptoStore;
7878
#[cfg(feature = "sqlite")]

0 commit comments

Comments
 (0)