Skip to content

Commit b105550

Browse files
committed
Report the combined upload progress across thumbnail and media as a percentage
1 parent 3b932d1 commit b105550

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
@@ -224,6 +224,19 @@ impl From<matrix_sdk::TransmissionProgress> for TransmissionProgress {
224224
}
225225
}
226226

227+
/// Progress of sending or receiving a payload in percent.
228+
#[derive(Clone, Copy, uniffi::Record)]
229+
pub struct RelativeTransmissionProgress {
230+
/// The completion percentage as a number between 0 and 1.
231+
pub percentage: f32,
232+
}
233+
234+
impl From<matrix_sdk::RelativeTransmissionProgress> for RelativeTransmissionProgress {
235+
fn from(value: matrix_sdk::RelativeTransmissionProgress) -> Self {
236+
Self { percentage: value.percentage }
237+
}
238+
}
239+
227240
#[derive(uniffi::Object)]
228241
pub struct Client {
229242
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,
@@ -280,19 +280,17 @@ pub enum EventSendProgress {
280280
/// thumbnail share the same index.
281281
index: u64,
282282

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

291289
impl From<SdkEventSendProgress> for EventSendProgress {
292290
fn from(value: SdkEventSendProgress) -> Self {
293291
match value {
294-
SdkEventSendProgress::MediaUpload { index, is_thumbnail, progress } => {
295-
Self::MediaUpload { index, is_thumbnail, progress: progress.into() }
292+
SdkEventSendProgress::MediaUpload { index, progress } => {
293+
Self::MediaUpload { index, progress: progress.into() }
296294
}
297295
}
298296
}

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
@@ -1340,17 +1340,11 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
13401340
.await;
13411341
}
13421342

1343-
RoomSendQueueUpdate::MediaUpload {
1344-
related_to, index, is_thumbnail, progress, ..
1345-
} => {
1343+
RoomSendQueueUpdate::MediaUpload { related_to, index, progress, .. } => {
13461344
self.update_event_send_state(
13471345
&related_to,
13481346
EventSendState::NotSentYet {
1349-
progress: Some(EventSendProgress::MediaUpload {
1350-
index,
1351-
is_thumbnail,
1352-
progress,
1353-
}),
1347+
progress: Some(EventSendProgress::MediaUpload { index, progress }),
13541348
},
13551349
)
13561350
.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)