Skip to content

feat(send_queue): report progress for media uploads #5008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b609637
feat(send_queue): add global setting for sending media progress updates
Johennes Jul 7, 2025
98ded6d
chore(send_queue): collect thumbnail-related metadata in a dedicated …
Johennes Jul 7, 2025
ed36540
feat(send_queue): cache thumbnail sizes to use them in progress repor…
Johennes Jul 7, 2025
84fa087
chore(send_queue): Make parent_is_thumbnail_upload available outside …
Johennes Jul 7, 2025
1c9436b
feat(send_queue): enable progress monitoring in RoomSendQueue::handle…
Johennes Jul 7, 2025
d2f47f3
feat(sdk): introduce AbstractProgress for tracking media progress in …
Johennes Jul 7, 2025
5c0bb6a
chore(send_queue): rename RoomSendQueueUpdate::UploadedMedia to Media…
Johennes Jul 7, 2025
e4e2796
feat(send_queue): communicate media upload progress in RoomSendQueueU…
Johennes Jul 7, 2025
6a82e29
feat(timeline): communicate media upload progress through EventSendSt…
Johennes Jul 7, 2025
5da557d
feat(ffi): expose media upload progress through EventSendState::NotSe…
Johennes Jul 7, 2025
7ce947b
fixup! feat(send_queue): add global setting for sending media progres…
Johennes Jul 9, 2025
80be2d2
fixup! feat(send_queue): communicate media upload progress in RoomSen…
Johennes Jul 9, 2025
f91be75
fixup! feat(timeline): communicate media upload progress through Even…
Johennes Jul 9, 2025
0f2eb69
fixup! feat(send_queue): enable progress monitoring in RoomSendQueue:…
Johennes Jul 9, 2025
1d1e9a6
fixup! feat(send_queue): communicate media upload progress in RoomSen…
Johennes Jul 9, 2025
08a805d
fixup! feat(send_queue): communicate media upload progress in RoomSen…
Johennes Jul 9, 2025
66827e1
fixup! feat(send_queue): communicate media upload progress in RoomSen…
Johennes Jul 9, 2025
5cb65e1
fixup! feat(timeline): communicate media upload progress through Even…
Johennes Jul 9, 2025
8ba3aa6
fixup! feat(ffi): expose media upload progress through EventSendState…
Johennes Jul 9, 2025
207fc5f
fixup! feat(send_queue): communicate media upload progress in RoomSen…
Johennes Jul 9, 2025
50ed24c
fixup! feat(send_queue): communicate media upload progress in RoomSen…
Johennes Jul 9, 2025
c7d1934
fixup! feat(timeline): communicate media upload progress through Even…
Johennes Jul 9, 2025
48ccad9
fixup! feat(send_queue): communicate media upload progress in RoomSen…
Johennes Jul 9, 2025
13631d5
fixup! feat(send_queue): communicate media upload progress in RoomSen…
Johennes Jul 9, 2025
50696e1
fixup! feat(send_queue): communicate media upload progress in RoomSen…
Johennes Jul 9, 2025
0e1baac
fixup! feat(send_queue): communicate media upload progress in RoomSen…
Johennes Jul 9, 2025
cf51ac9
fixup! feat(send_queue): cache thumbnail sizes to use them in progres…
Johennes Jul 9, 2025
97a553f
fixup! feat(send_queue): cache thumbnail sizes to use them in progres…
Johennes Jul 9, 2025
971dcda
fixup! feat(send_queue): cache thumbnail sizes to use them in progres…
Johennes Jul 10, 2025
ad963c7
fixup! feat(send_queue): communicate media upload progress in RoomSen…
Johennes Jul 10, 2025
7cba439
Merge branch 'main' into johannes/send-queue-media-progress
Johennes Jul 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,30 @@ impl From<matrix_sdk::TransmissionProgress> for TransmissionProgress {
}
}

/// Progress of an operation in abstract units.
///
/// Contrary to [`TransmissionProgress`], this allows tracking the progress
/// of sending or receiving a payload in estimated pseudo units representing a
/// percentage. This is helpful in cases where the exact progress in bytes isn't
/// known, for instance, because encryption (which changes the size) happens on
/// the fly.
#[derive(Clone, Copy, uniffi::Record)]
pub struct AbstractProgress {
/// How many units were already transferred.
pub current: u64,
/// How many units there are in total.
pub total: u64,
}

impl From<matrix_sdk::AbstractProgress> for AbstractProgress {
fn from(value: matrix_sdk::AbstractProgress) -> Self {
Self {
current: value.current.try_into().unwrap_or(u64::MAX),
total: value.total.try_into().unwrap_or(u64::MAX),
}
}
}

#[derive(uniffi::Object)]
pub struct Client {
pub(crate) inner: AsyncRuntimeDropped<MatrixClient>,
Expand Down Expand Up @@ -539,6 +563,12 @@ impl Client {
self.inner.send_queue().set_enabled(enable).await;
}

/// Enables or disables progress reporting for media uploads in the send
/// queue.
pub fn enable_send_queue_upload_progress(&self, enable: bool) {
self.inner.send_queue().enable_upload_progress(enable);
}

/// Subscribe to the global enablement status of the send queue, at the
/// client-wide level.
///
Expand Down
41 changes: 36 additions & 5 deletions bindings/matrix-sdk-ffi/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ use matrix_sdk_common::{
stream::StreamExt,
};
use matrix_sdk_ui::timeline::{
self, AttachmentSource, EventItemOrigin, Profile, TimelineDetails,
TimelineUniqueId as SdkTimelineUniqueId,
self, AttachmentSource, EventItemOrigin, EventSendProgress as SdkEventSendProgress, Profile,
TimelineDetails, TimelineUniqueId as SdkTimelineUniqueId,
};
use mime::Mime;
use reply::{EmbeddedEventDetails, InReplyToDetails};
Expand Down Expand Up @@ -66,7 +66,7 @@ use uuid::Uuid;
use self::content::TimelineItemContent;
pub use self::msg_like::MessageContent;
use crate::{
client::ProgressWatcher,
client::{AbstractProgress, ProgressWatcher},
error::{ClientError, RoomError},
event::EventOrTransactionId,
helpers::unwrap_or_clone_arc,
Expand Down Expand Up @@ -270,6 +270,32 @@ impl TryInto<Reply> for ReplyParameters {
}
}

/// This type represents the "send progress" of a local event timeline item.
#[derive(Clone, Copy, uniffi::Enum)]
pub enum EventSendProgress {
/// A media is being uploaded.
MediaUpload {
/// The index of the media within the transaction. A file and its
/// thumbnail share the same index. Will always be 0 for non-gallery
/// media uploads.
index: u64,

/// The current combined upload progress for both the file and,
/// if it exists, its thumbnail.
progress: AbstractProgress,
},
}

impl From<SdkEventSendProgress> for EventSendProgress {
fn from(value: SdkEventSendProgress) -> Self {
match value {
SdkEventSendProgress::MediaUpload { index, progress } => {
Self::MediaUpload { index, progress: progress.into() }
}
}
}
}

#[matrix_sdk_ffi_macros::export]
impl Timeline {
pub async fn add_listener(&self, listener: Box<dyn TimelineListener>) -> Arc<TaskHandle> {
Expand Down Expand Up @@ -1018,7 +1044,10 @@ impl TimelineItem {
#[derive(Clone, uniffi::Enum)]
pub enum EventSendState {
/// The local event has not been sent yet.
NotSentYet,
NotSentYet {
/// The progress of the sending operation, if any is available.
progress: Option<EventSendProgress>,
},

/// The local event has been sent to the server, but unsuccessfully: The
/// sending has failed.
Expand All @@ -1043,7 +1072,9 @@ impl From<&matrix_sdk_ui::timeline::EventSendState> for EventSendState {
use matrix_sdk_ui::timeline::EventSendState::*;

match value {
NotSentYet => Self::NotSentYet,
NotSentYet { progress } => {
Self::NotSentYet { progress: progress.clone().map(|p| p.into()) }
}
SendingFailed { error, is_recoverable } => {
let as_queue_wedge_error: matrix_sdk::QueueWedgeError = (&**error).into();
Self::SendingFailed {
Expand Down
2 changes: 0 additions & 2 deletions crates/matrix-sdk-base/src/store/send_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ pub enum DependentQueuedRequestKind {
related_to: OwnedTransactionId,

/// Whether the depended upon request was a thumbnail or a file upload.
#[cfg(feature = "unstable-msc4274")]
#[serde(default = "default_parent_is_thumbnail_upload")]
parent_is_thumbnail_upload: bool,
},
Expand Down Expand Up @@ -275,7 +274,6 @@ pub enum DependentQueuedRequestKind {
/// If parent_is_thumbnail_upload is missing, we assume the request is for a
/// file upload following a thumbnail upload. This was the only possible case
/// before parent_is_thumbnail_upload was introduced.
#[cfg(feature = "unstable-msc4274")]
fn default_parent_is_thumbnail_upload() -> bool {
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ mod tests {

fn local_event() -> Arc<TimelineItem> {
let event_kind = EventTimelineItemKind::Local(LocalEventTimelineItem {
send_state: EventSendState::NotSentYet,
send_state: EventSendState::NotSentYet { progress: None },
transaction_id: OwnedTransactionId::from("trans"),
send_handle: None,
});
Expand Down
25 changes: 17 additions & 8 deletions crates/matrix-sdk-ui/src/timeline/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ use super::{
item::TimelineUniqueId,
subscriber::TimelineSubscriber,
traits::{Decryptor, RoomDataProvider},
DateDividerMode, EmbeddedEvent, Error, EventSendState, EventTimelineItem, InReplyToDetails,
PaginationError, Profile, TimelineDetails, TimelineEventItemId, TimelineFocus, TimelineItem,
TimelineItemContent, TimelineItemKind, VirtualTimelineItem,
DateDividerMode, EmbeddedEvent, Error, EventSendProgress, EventSendState, EventTimelineItem,
InReplyToDetails, PaginationError, Profile, TimelineDetails, TimelineEventItemId,
TimelineFocus, TimelineItem, TimelineItemContent, TimelineItemKind, VirtualTimelineItem,
};
use crate::{
timeline::{
Expand Down Expand Up @@ -1068,7 +1068,7 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
warn!("We looked for a local item, but it transitioned as remote??");
return false;
};
prev_local_item.with_send_state(EventSendState::NotSentYet)
prev_local_item.with_send_state(EventSendState::NotSentYet { progress: None })
};

// Replace the local-related state (kind) and the content state.
Expand Down Expand Up @@ -1352,17 +1352,26 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
}

RoomSendQueueUpdate::RetryEvent { transaction_id } => {
self.update_event_send_state(&transaction_id, EventSendState::NotSentYet).await;
self.update_event_send_state(
&transaction_id,
EventSendState::NotSentYet { progress: None },
)
.await;
}

RoomSendQueueUpdate::SentEvent { transaction_id, event_id } => {
self.update_event_send_state(&transaction_id, EventSendState::Sent { event_id })
.await;
}

RoomSendQueueUpdate::UploadedMedia { related_to, .. } => {
// TODO(bnjbvr): Do something else?
info!(txn_id = %related_to, "some media for a media event has been uploaded");
RoomSendQueueUpdate::MediaUpload { related_to, index, progress, .. } => {
self.update_event_send_state(
&related_to,
EventSendState::NotSentYet {
progress: Some(EventSendProgress::MediaUpload { index, progress }),
},
)
.await;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ mod observable_items_tests {
thread_summary: None,
}),
EventTimelineItemKind::Local(LocalEventTimelineItem {
send_state: EventSendState::NotSentYet,
send_state: EventSendState::NotSentYet { progress: None },
transaction_id: transaction_id.into(),
send_handle: None,
}),
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-ui/src/timeline/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {

let kind: EventTimelineItemKind = match &self.ctx.flow {
Flow::Local { txn_id, send_handle } => LocalEventTimelineItem {
send_state: EventSendState::NotSentYet,
send_state: EventSendState::NotSentYet { progress: None },
transaction_id: txn_id.to_owned(),
send_handle: send_handle.clone(),
}
Expand Down
25 changes: 23 additions & 2 deletions crates/matrix-sdk-ui/src/timeline/event_item/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use std::sync::Arc;

use as_variant::as_variant;
use matrix_sdk::{send_queue::SendHandle, Error};
use matrix_sdk::{send_queue::SendHandle, AbstractProgress, Error};
use ruma::{EventId, OwnedEventId, OwnedTransactionId};

use super::TimelineEventItemId;
Expand Down Expand Up @@ -65,7 +65,10 @@ impl LocalEventTimelineItem {
#[derive(Clone, Debug)]
pub enum EventSendState {
/// The local event has not been sent yet.
NotSentYet,
NotSentYet {
/// The progress of the sending operation, if any is available.
progress: Option<EventSendProgress>,
},
/// The local event has been sent to the server, but unsuccessfully: The
/// sending has failed.
SendingFailed {
Expand All @@ -84,3 +87,21 @@ pub enum EventSendState {
event_id: OwnedEventId,
},
}

/// This type represents the "send progress" of a local event timeline item.
#[derive(Clone, Debug)]
pub enum EventSendProgress {
/// A media (consisting of a file and possibly a thumbnail) is being
/// uploaded.
MediaUpload {
/// The index of the media within the transaction. A file and its
/// thumbnail share the same index. Will always be 0 for non-gallery
/// media uploads.
index: u64,

/// The combined upload progress across the file and, if existing, its
/// thumbnail. For gallery uploads, the progress is reported per indexed
/// gallery item.
progress: AbstractProgress,
},
}
2 changes: 1 addition & 1 deletion crates/matrix-sdk-ui/src/timeline/event_item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub use self::{
PollResult, PollState, RoomMembershipChange, RoomPinnedEventsChange, Sticker,
ThreadSummary, TimelineItemContent,
},
local::EventSendState,
local::{EventSendProgress, EventSendState},
};

/// An item in the timeline that represents at least one event.
Expand Down
10 changes: 5 additions & 5 deletions crates/matrix-sdk-ui/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ pub use self::{
error::*,
event_item::{
AnyOtherFullStateEventContent, EmbeddedEvent, EncryptedMessage, EventItemOrigin,
EventSendState, EventTimelineItem, InReplyToDetails, MemberProfileChange, MembershipChange,
Message, MsgLikeContent, MsgLikeKind, OtherState, PollResult, PollState, Profile,
ReactionInfo, ReactionStatus, ReactionsByKeyBySender, RoomMembershipChange,
RoomPinnedEventsChange, Sticker, ThreadSummary, TimelineDetails, TimelineEventItemId,
TimelineItemContent,
EventSendProgress, EventSendState, EventTimelineItem, InReplyToDetails,
MemberProfileChange, MembershipChange, Message, MsgLikeContent, MsgLikeKind, OtherState,
PollResult, PollState, Profile, ReactionInfo, ReactionStatus, ReactionsByKeyBySender,
RoomMembershipChange, RoomPinnedEventsChange, Sticker, ThreadSummary, TimelineDetails,
TimelineEventItemId, TimelineItemContent,
},
event_type_filter::TimelineEventTypeFilter,
item::{TimelineItem, TimelineItemKind, TimelineUniqueId},
Expand Down
7 changes: 5 additions & 2 deletions crates/matrix-sdk-ui/src/timeline/tests/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ async fn test_remote_echo_full_trip() {
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
let event_item = item.as_event().unwrap();
assert!(event_item.is_local_echo());
assert_matches!(event_item.send_state(), Some(EventSendState::NotSentYet));
assert_matches!(
event_item.send_state(),
Some(EventSendState::NotSentYet { progress: None })
);
assert!(!event_item.can_be_replied_to());
item.unique_id().to_owned()
};
Expand Down Expand Up @@ -308,7 +311,7 @@ async fn test_no_reuse_of_counters() {
let local_id = assert_next_matches_with_timeout!(stream, VectorDiff::PushBack { value: item } => {
let event_item = item.as_event().unwrap();
assert!(event_item.is_local_echo());
assert_matches!(event_item.send_state(), Some(EventSendState::NotSentYet));
assert_matches!(event_item.send_state(), Some(EventSendState::NotSentYet { progress: None }));
assert!(!event_item.can_be_replied_to());
item.unique_id().to_owned()
});
Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-sdk-ui/tests/integration/timeline/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async fn test_echo() {

assert_let!(VectorDiff::PushBack { value: local_echo } = &timeline_updates[0]);
let item = local_echo.as_event().unwrap();
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet));
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet { progress: None }));
assert_let!(Some(msg) = item.content().as_message());
assert_let!(MessageType::Text(text) = msg.msgtype());
assert_eq!(text.body, "Hello, World!");
Expand Down Expand Up @@ -150,7 +150,7 @@ async fn test_retry_failed() {

// First, local echo is added.
assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => {
assert_matches!(value.send_state(), Some(EventSendState::NotSentYet));
assert_matches!(value.send_state(), Some(EventSendState::NotSentYet { progress: None }));
});

// Sending fails, because the error is a transient one that's recoverable,
Expand Down Expand Up @@ -216,7 +216,7 @@ async fn test_dedup_by_event_id_late() {
// Timeline: [local echo]
assert_let!(VectorDiff::PushBack { value: local_echo } = &timeline_updates[0]);
let item = local_echo.as_event().unwrap();
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet));
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet { progress: None }));

// Timeline: [date-divider, local echo]
assert_let!(VectorDiff::PushFront { value: date_divider } = &timeline_updates[1]);
Expand Down Expand Up @@ -283,7 +283,7 @@ async fn test_cancel_failed() {

// Local echo is added (immediately)
assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => {
assert_matches!(value.send_state(), Some(EventSendState::NotSentYet));
assert_matches!(value.send_state(), Some(EventSendState::NotSentYet { progress: None }));
});

// Sending fails, the mock server has no matching route
Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-sdk-ui/tests/integration/timeline/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async fn test_edit_local_echo() {
let internal_id = item.unique_id();

let item = item.as_event().unwrap();
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet));
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet { progress: None }));

assert_let!(VectorDiff::PushFront { value: date_divider } = &timeline_updates[1]);
assert!(date_divider.is_date_divider());
Expand Down Expand Up @@ -249,7 +249,7 @@ async fn test_edit_local_echo() {
assert!(item.is_local_echo());

// The send state has been reset.
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet));
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet { progress: None }));

let edit_message = item.content().as_message().unwrap();
assert_eq!(edit_message.body(), "hello, world");
Expand Down Expand Up @@ -635,7 +635,7 @@ async fn test_edit_local_echo_with_unsupported_content() {
assert_let!(VectorDiff::PushBack { value: item } = &timeline_updates[0]);

let item = item.as_event().unwrap();
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet));
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet { progress: None }));

assert_let!(VectorDiff::PushFront { value: date_divider } = &timeline_updates[1]);
assert!(date_divider.is_date_divider());
Expand Down Expand Up @@ -689,7 +689,7 @@ async fn test_edit_local_echo_with_unsupported_content() {
assert_let!(VectorDiff::PushBack { value: item } = &timeline_updates[0]);

let item = item.as_event().unwrap();
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet));
assert_matches!(item.send_state(), Some(EventSendState::NotSentYet { progress: None }));

// Let's edit the local echo (poll start) with an unsupported type (message).
let edit_err = timeline
Expand Down
Loading
Loading