Skip to content

feat(timeline): report progress for media uploads #5454

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 4 commits into
base: main
Choose a base branch
from

Conversation

Johennes
Copy link
Contributor

@Johennes Johennes commented Jul 28, 2025

This is meant to only contain the timeline changes broken out from #5008 (together with #5453 which this depends on).

  • Public API changes documented in changelogs (optional)

Signed-off-by:

Copy link

codecov bot commented Jul 28, 2025

Codecov Report

❌ Patch coverage is 75.00000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.93%. Comparing base (5ad477a) to head (c23d92d).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rates/matrix-sdk-ui/src/timeline/controller/mod.rs 70.58% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5454   +/-   ##
=======================================
  Coverage   88.93%   88.93%           
=======================================
  Files         334      334           
  Lines       92420    92433   +13     
  Branches    92420    92433   +13     
=======================================
+ Hits        82196    82208   +12     
- Misses       6378     6379    +1     
  Partials     3846     3846           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Jul 28, 2025

CodSpeed Performance Report

Merging #5454 will improve performances by 21.81%

Comparing Johennes:johannes/timeline-media-upload-progress (c23d92d) with main (033c6bd)

Summary

⚡ 1 improvements
✅ 30 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
Restore session [SQLite][clear] 773.2 ms 634.8 ms +21.81%

@Johennes Johennes force-pushed the johannes/timeline-media-upload-progress branch from abc8928 to a01918f Compare August 1, 2025 11:58
@Johennes Johennes force-pushed the johannes/timeline-media-upload-progress branch from 8cf4c7d to 77966e5 Compare August 1, 2025 12:12
…::NotSentYet

Move AbstractProgress from client to timeline

Signed-off-by: Johannes Marbach <[email protected]>
…tSendState::NotSentYet

Retain progress when applying remote echo

Signed-off-by: Johannes Marbach <[email protected]>
@Johennes Johennes force-pushed the johannes/timeline-media-upload-progress branch from 3f36d7e to c23d92d Compare August 1, 2025 13:28
@bnjbvr bnjbvr self-requested a review August 4, 2025 09:42
@Johennes
Copy link
Contributor Author

Johennes commented Aug 6, 2025

I have addressed all comments from #5008, except for:

I do realize only now that it's a bit weird that message events also get a progress optional value here, despite this option being never set. This suggests that some variant EventSendState::Uploading that we could use for medias only, maybe?
[...]
Based on other comments: we might prefer to have a new variant NotUploadedYet, for medias. The progress field isn't used, for non-media uploads.

This is turning out a little more involved than expected, sadly.

There are places like here when a timeline item is added where I would have to peek into the content and figure out if it's a media event or not. There's also the retry handling here where I only have the transaction ID to figure out if it's a media upload transaction or not. It feels like working in a new enum variant there might introduce quite a bit of complexity.

Alternatively, we could only use NotUploadedYet once the upload actually starts and stick to NotSentYet otherwise. That might make things even more confusing than right now though.

I currently feel like keeping the progress optional in NotSentYet might do the least damage?

@Johennes Johennes marked this pull request as ready for review August 6, 2025 15:07
@Johennes Johennes requested a review from a team as a code owner August 6, 2025 15:07
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've discussed this with the Rust SDK core team, and we think this is a nice API. We might experiment with a new EventSendState::Uploading state later, but since this is unclear whether it'll be good or not, I won't request it now.

My final comments are mostly cosmetic improvements, so a last round and we should be good to go. Thanks for this PR!

#[derive(Clone, Copy, uniffi::Enum)]
pub enum EventSendProgress {
/// A media is being uploaded.
MediaUpload {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this isn't serialized: maybe we could make this enum with one variant a plain struct, instead? MediaUploadProgress or something like that?

@@ -990,7 +1041,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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we precise it's only available for media uploads, at the moment?

Comment on lines +1075 to +1078
// If the local echo had an upload progress, retain it.
let progress = as_variant!(&prev_local_item.send_state,
EventSendState::NotSentYet { progress } => progress.clone())
.flatten();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's let the code breath a bit, and simplify the as_variant! to do as little as possible:

Suggested change
// If the local echo had an upload progress, retain it.
let progress = as_variant!(&prev_local_item.send_state,
EventSendState::NotSentYet { progress } => progress.clone())
.flatten();
// If the local echo had an upload progress, retain it.
let progress = as_variant!(&prev_local_item.send_state, EventSendState::NotSentYet)
.and_then(|progress| progress.cloned());

@@ -65,7 +68,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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we precise it's only available for media uploads, please?

Comment on lines +96 to +99
pub enum EventSendProgress {
/// A media (consisting of a file and possibly a thumbnail) is being
/// uploaded.
MediaUpload {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, since this is an enum with a single variant, and that's not ser/de, let's use a struct instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants