@@ -30,7 +30,8 @@ use matrix_sdk_common::{
30
30
stream:: StreamExt ,
31
31
} ;
32
32
use matrix_sdk_ui:: timeline:: {
33
- self , AttachmentConfig , AttachmentSource , EventItemOrigin , Profile , TimelineDetails ,
33
+ self , AttachmentConfig , AttachmentSource , EventItemOrigin ,
34
+ MediaUploadProgress as SdkMediaUploadProgress , Profile , TimelineDetails ,
34
35
TimelineUniqueId as SdkTimelineUniqueId ,
35
36
} ;
36
37
use mime:: Mime ;
@@ -239,6 +240,50 @@ impl From<UploadSource> for AttachmentSource {
239
240
}
240
241
}
241
242
243
+ /// This type represents the progress of a media (consisting of a file and
244
+ /// possibly a thumbnail) being uploaded.
245
+ #[ derive( Clone , Copy , uniffi:: Record ) ]
246
+ pub struct MediaUploadProgress {
247
+ /// The index of the media within the transaction. A file and its
248
+ /// thumbnail share the same index. Will always be 0 for non-gallery
249
+ /// media uploads.
250
+ pub index : u64 ,
251
+
252
+ /// The current combined upload progress for both the file and,
253
+ /// if it exists, its thumbnail.
254
+ pub progress : AbstractProgress ,
255
+ }
256
+
257
+ impl From < SdkMediaUploadProgress > for MediaUploadProgress {
258
+ fn from ( value : SdkMediaUploadProgress ) -> Self {
259
+ Self { index : value. index , progress : value. progress . into ( ) }
260
+ }
261
+ }
262
+
263
+ /// Progress of an operation in abstract units.
264
+ ///
265
+ /// Contrary to [`TransmissionProgress`], this allows tracking the progress
266
+ /// of sending or receiving a payload in estimated pseudo units representing a
267
+ /// percentage. This is helpful in cases where the exact progress in bytes isn't
268
+ /// known, for instance, because encryption (which changes the size) happens on
269
+ /// the fly.
270
+ #[ derive( Clone , Copy , uniffi:: Record ) ]
271
+ pub struct AbstractProgress {
272
+ /// How many units were already transferred.
273
+ pub current : u64 ,
274
+ /// How many units there are in total.
275
+ pub total : u64 ,
276
+ }
277
+
278
+ impl From < matrix_sdk:: send_queue:: AbstractProgress > for AbstractProgress {
279
+ fn from ( value : matrix_sdk:: send_queue:: AbstractProgress ) -> Self {
280
+ Self {
281
+ current : value. current . try_into ( ) . unwrap_or ( u64:: MAX ) ,
282
+ total : value. total . try_into ( ) . unwrap_or ( u64:: MAX ) ,
283
+ }
284
+ }
285
+ }
286
+
242
287
#[ matrix_sdk_ffi_macros:: export]
243
288
impl Timeline {
244
289
pub async fn add_listener ( & self , listener : Box < dyn TimelineListener > ) -> Arc < TaskHandle > {
@@ -928,7 +973,11 @@ impl TimelineItem {
928
973
#[ derive( Clone , uniffi:: Enum ) ]
929
974
pub enum EventSendState {
930
975
/// The local event has not been sent yet.
931
- NotSentYet ,
976
+ NotSentYet {
977
+ /// The progress of the sending operation, if the event involves a media
978
+ /// upload.
979
+ progress : Option < MediaUploadProgress > ,
980
+ } ,
932
981
933
982
/// The local event has been sent to the server, but unsuccessfully: The
934
983
/// sending has failed.
@@ -953,7 +1002,9 @@ impl From<&matrix_sdk_ui::timeline::EventSendState> for EventSendState {
953
1002
use matrix_sdk_ui:: timeline:: EventSendState :: * ;
954
1003
955
1004
match value {
956
- NotSentYet => Self :: NotSentYet ,
1005
+ NotSentYet { progress } => {
1006
+ Self :: NotSentYet { progress : progress. clone ( ) . map ( |p| p. into ( ) ) }
1007
+ }
957
1008
SendingFailed { error, is_recoverable } => {
958
1009
let as_queue_wedge_error: matrix_sdk:: QueueWedgeError = ( & * * error) . into ( ) ;
959
1010
Self :: SendingFailed {
0 commit comments