Skip to content

Commit c1a2f65

Browse files
committed
Switch from percentage progress to abstract current / total progress
1 parent fd2b0e3 commit c1a2f65

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,21 @@ impl From<matrix_sdk::TransmissionProgress> for TransmissionProgress {
218218
}
219219
}
220220

221-
/// Progress of sending or receiving a payload in percent.
221+
/// Progress of an operation in abstract units.
222222
#[derive(Clone, Copy, uniffi::Record)]
223-
pub struct RelativeTransmissionProgress {
224-
/// The completion percentage as a number between 0 and 1.
225-
pub percentage: f32,
223+
pub struct AbstractProgress {
224+
/// How many units were already transferred.
225+
pub current: u64,
226+
/// How many units there are in total.
227+
pub total: u64,
226228
}
227229

228-
impl From<matrix_sdk::RelativeTransmissionProgress> for RelativeTransmissionProgress {
229-
fn from(value: matrix_sdk::RelativeTransmissionProgress) -> Self {
230-
Self { percentage: value.percentage }
230+
impl From<matrix_sdk::AbstractProgress> for AbstractProgress {
231+
fn from(value: matrix_sdk::AbstractProgress) -> Self {
232+
Self {
233+
current: value.current.try_into().unwrap_or(u64::MAX),
234+
total: value.total.try_into().unwrap_or(u64::MAX),
235+
}
231236
}
232237
}
233238

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

Lines changed: 2 additions & 2 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, RelativeTransmissionProgress},
70+
client::{AbstractProgress, ProgressWatcher},
7171
error::{ClientError, RoomError},
7272
event::EventOrTransactionId,
7373
helpers::unwrap_or_clone_arc,
@@ -280,7 +280,7 @@ pub enum EventSendProgress {
280280

281281
/// The current combined upload progress for both the file and,
282282
/// if it exists, its thumbnail.
283-
progress: RelativeTransmissionProgress,
283+
progress: AbstractProgress,
284284
},
285285
}
286286

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

Lines changed: 1 addition & 1 deletion
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, RelativeTransmissionProgress};
18+
use matrix_sdk::{send_queue::SendHandle, AbstractProgress, Error};
1919
use ruma::{EventId, OwnedEventId, OwnedTransactionId};
2020

2121
use super::TimelineEventItemId;

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

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

234-
/// Progress of sending or receiving a payload in percent.
234+
/// Progress of an operation in abstract units.
235235
#[derive(Clone, Copy, Debug, Default)]
236-
pub struct RelativeTransmissionProgress {
237-
/// The completion percentage as a number between 0 and 1.
238-
pub percentage: f32,
236+
pub struct AbstractProgress {
237+
/// How many units were already transferred.
238+
pub current: usize,
239+
/// How many units there are in total.
240+
pub total: usize,
239241
}
240242

241243
async fn response_to_http_response(

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::{RelativeTransmissionProgress, TransmissionProgress};
75+
pub use http_client::{AbstractProgress, TransmissionProgress};
7676
#[cfg(all(feature = "e2e-encryption", feature = "sqlite"))]
7777
pub use matrix_sdk_sqlite::SqliteCryptoStore;
7878
#[cfg(feature = "sqlite")]

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ use crate::{
177177
config::RequestConfig,
178178
error::RetryKind,
179179
room::{edit::EditedContent, WeakRoom},
180-
Client, Media, RelativeTransmissionProgress, Room, TransmissionProgress,
180+
AbstractProgress, Client, Media, Room, TransmissionProgress,
181181
};
182182

183183
mod upload;
@@ -910,18 +910,21 @@ fn compute_combined_progress(
910910
file_size: usize,
911911
thumbnail_file_size: Option<usize>,
912912
media_file_size: Option<usize>,
913-
) -> RelativeTransmissionProgress {
914-
let percentage = if progress.total != 0 {
913+
) -> AbstractProgress {
914+
if progress.total == 0 {
915+
AbstractProgress { current: 0, total: 0 }
916+
} else {
915917
// The uploaded file is possibly encrypted and, thus, larger than
916918
// the original one. Use the rule of 3 to proportionally map the
917919
// progress into units of the original file size.
918-
let mut current = progress.current as f32 / progress.total as f32 * file_size as f32;
920+
let mut current =
921+
(progress.current as f32 / progress.total as f32 * file_size as f32).round() as usize;
919922
let mut total = file_size;
920923

921924
// If a thumbnail was previously uploaded, add its file size to both
922925
// the current and total.
923926
if let Some(thumbnail_file_size) = thumbnail_file_size {
924-
current += thumbnail_file_size as f32;
927+
current += thumbnail_file_size;
925928
total += thumbnail_file_size;
926929
}
927930

@@ -931,16 +934,8 @@ fn compute_combined_progress(
931934
total += media_file_size;
932935
}
933936

934-
if total != 0 {
935-
current / total as f32
936-
} else {
937-
0.0
938-
}
939-
} else {
940-
0.0
941-
};
942-
943-
RelativeTransmissionProgress { percentage }
937+
AbstractProgress { current, total }
938+
}
944939
}
945940

946941
impl From<&crate::Error> for QueueWedgeError {

0 commit comments

Comments
 (0)