Skip to content

feat(send_queue): Implement sending of MSC4274 galleries#4977

Merged
bnjbvr merged 25 commits intomatrix-org:mainfrom
Johennes:johannes/msc4274-step2
May 27, 2025
Merged

feat(send_queue): Implement sending of MSC4274 galleries#4977
bnjbvr merged 25 commits intomatrix-org:mainfrom
Johennes:johannes/msc4274-step2

Conversation

@Johennes
Copy link
Copy Markdown
Contributor

@Johennes Johennes commented Apr 25, 2025

This was broken out of #4838 and is a step towards implementing MSC4274.

  • The entry point for sending galleries via the send queue is a new method RoomSendQueue::send_gallery which is a generalization of RoomSendQueue::send_attachment.
    • send_gallery takes as input parameters a GalleryConfig (containing info about the gallery itself, such as its caption) and a vector of GalleryItemInfos (containing info about each image / file / etc. in the gallery).
    • send_gallery creates the gallery event content via Room:make_message_event which was renamed from make_attachment_event to reflect the fact that it creates general msgtype events now.
    • send_gallery maps the passed item infos into GalleryItemQueueInfos. This additional struct allows grouping all the metadata for a single gallery item together.
  • Finally send_gallery invokes QueueStorage::push_gallery which is a generalization of QueueStorage::push_media.
    • send_gallery pushes upload requests for the media and thumbnails to the queue in a "daisy chain" manner. The first thumbnail (or media if no thumbnail exists) is pushed as a QueuedRequestKind::MediaUpload. The remaining thumbnails and media are pushed as DependentQueuedRequestKind::UploadFileOrThumbnails while chaining each request to the previous one.
    • Finally a DependentQueuedRequestKind::FinishGallery is pushed to finalize the gallery upload (analogous to the existing FinishUpload for single media uploads).
  • The FinishGallery request is handled in QueueStorage::handle_dependent_finish_gallery_upload which was modeled after handle_dependent_finish_upload.
  • An integration test has been added to demonstrate the functionality.

This is relatively large, unfortunately, but including everything needed to actually send the event made it possible to also add a test for it. It would be nice if the amount of new code could be reduced but I'm struggling a bit to find ways to integrate galleries with the existing media uploads further.

  • Public API changes documented in changelogs (optional)

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
@Johennes Johennes force-pushed the johannes/msc4274-step2 branch from ba8aa4b to 0c3161b Compare April 25, 2025 06:46
Comment thread crates/matrix-sdk/src/room/mod.rs Outdated
Comment on lines +2325 to +2334
let info = assign!(info.map(ImageInfo::from).unwrap_or_default(), {
mimetype: Some(content_type.as_ref().to_owned()),
thumbnail_source,
thumbnail_info
});
let content = assign!(ImageMessageEventContent::new(body, source), {
info: Some(Box::new(info)),
formatted: formatted_caption,
filename
});
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These blocks could maybe share the logic with make_attachment_type by extracting a function to create the content for each mime-type? I wasn't sure if it's really worth it because it might not be shorter due to the number of arguments on the call.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some form of code sharing would be nice, since it's a direct copy-pasto. I think a local macro (defined with macro_rules!) that contains the entire match would be nice here: the only thing that changes is the GalleryItemType vs MessageType, if I'm following correctly?

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2025

Codecov Report

Attention: Patch coverage is 83.92857% with 27 lines in your changes missing coverage. Please review.

Project coverage is 85.81%. Comparing base (40ffd40) to head (f235e56).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/room/mod.rs 53.65% 19 Missing ⚠️
crates/matrix-sdk/src/send_queue/upload.rs 90.12% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4977      +/-   ##
==========================================
+ Coverage   85.80%   85.81%   +0.01%     
==========================================
  Files         332      332              
  Lines       36195    36211      +16     
==========================================
+ Hits        31056    31076      +20     
+ Misses       5139     5135       -4     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Johennes Johennes marked this pull request as ready for review April 25, 2025 07:16
@Johennes Johennes requested a review from a team as a code owner April 25, 2025 07:16
@Johennes Johennes requested review from poljar and removed request for a team April 25, 2025 07:16
@bnjbvr bnjbvr requested review from bnjbvr and removed request for poljar May 12, 2025 11:38
@Johennes
Copy link
Copy Markdown
Contributor Author

I'm mindful that it's probably just a matter of lack of time but if there's anything I can do to simplify reviewing this PR, I'd be happy to follow any suggestions.

@bnjbvr
Copy link
Copy Markdown
Member

bnjbvr commented May 20, 2025

Sorry about the long review time. I'll take a look this week, but indeed one large commit with that many changes is a bit overwhelming and hard to review. For PRs that large, in general, in the core team, we tend to do some synchronous video meeting with screen sharing, where the author explains the changes in real-time, giving some kind of "map" of the changes (where to start reading from, where to continue, etc.). If there's any chance you can do any of this in written form, that'd be great, but it is not mandatory :)

One early comment, though:

Room::make_attachment_event was renamed to make_message_event because it is now reused to create gallery events as well

I think this could be named make_media_event (to distinguish from the general use case of text messages, as messages is so general). In retrospect I wonder if it could have been in its own separate commit (although it wouldn't have changed the overall size of the other commit that much :)).

Comment thread crates/matrix-sdk/src/room/mod.rs Outdated
@Johennes
Copy link
Copy Markdown
Contributor Author

Sorry about the long review time. I'll take a look this week, but indeed one large commit with that many changes is a bit overwhelming and hard to review. For PRs that large, in general, in the core team, we tend to do some synchronous video meeting with screen sharing, where the author explains the changes in real-time, giving some kind of "map" of the changes (where to start reading from, where to continue, etc.). If there's any chance you can do any of this in written form, that'd be great, but it is not mandatory :)

No worries at all. I'm really grateful to get input on this hefty change at all. ❤️

I have expanded the bullets in the PR description to describe the code path in some more detail. I hope this is helpful.

One early comment, though:

Room::make_attachment_event was renamed to make_message_event because it is now reused to create gallery events as well

I think this could be named make_media_event (to distinguish from the general use case of text messages, as messages is so general).

Good call. I have copied your comment into the diff and will address it together with any other feedback you might have later.

In retrospect I wonder if it could have been in its own separate commit (although it wouldn't have changed the overall size of the other commit that much :)).

Yes, you're probably right. I will try to pay more attention to canonicalizing commits in future.

Copy link
Copy Markdown
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.

Looks great! The test is quite comprehensive, that's nice.

A first batch of comments; I think we might be able to reduce the code duplication with the existing send_attachment functionality in various places, so let's try it out. If it turns out to be more trouble (e.g. require doing too much data/parameters shuffling, etc.), in some places, please don't hesitate to not do it.

I'd like to take another look after that, but it looks like this is on the right track. Thanks!

Comment thread crates/matrix-sdk/src/attachment.rs Outdated
Comment thread crates/matrix-sdk/src/attachment.rs Outdated
Comment thread crates/matrix-sdk/src/send_queue/upload.rs Outdated
Comment thread crates/matrix-sdk/src/send_queue/upload.rs Outdated
Comment thread crates/matrix-sdk/src/send_queue/upload.rs Outdated
Comment thread crates/matrix-sdk/src/send_queue/mod.rs Outdated
Comment thread crates/matrix-sdk/src/send_queue/upload.rs Outdated
Comment thread crates/matrix-sdk/src/send_queue/upload.rs Outdated
Comment thread crates/matrix-sdk/src/send_queue/upload.rs Outdated
Comment thread crates/matrix-sdk-base/src/store/send_queue.rs Outdated
@Johennes
Copy link
Copy Markdown
Contributor Author

Thanks a ton for the review. 🙏

I've addressed most comment but will have to return to this next week for the refactoring of send_gallery and push_gallery.

@Johennes
Copy link
Copy Markdown
Contributor Author

Ok, I think I've addressed everything now.

@Johennes Johennes requested a review from bnjbvr May 26, 2025 18:25
Copy link
Copy Markdown
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.

Thanks, looking great! I didn't expect some of the refactorings to happen that cleanly, that's super nice; thanks for making separate commits for those, that really helped.

What a journey! A few more stylistics comments, and I think we can merge this then 🥳

Comment thread crates/matrix-sdk/src/send_queue/upload.rs Outdated
Comment thread crates/matrix-sdk/tests/integration/send_queue.rs Outdated
Comment on lines +121 to +122
match itemtype {
GalleryItemType::Audio(event) => match sent.get(&event.source.unique_key()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we invert the position of the match sent.get(...) and match itemtype? Then, we don't need to repeat it in each match arm.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm, I think this doesn't work because event used in the inner match is only set through the outer match? We could maybe add an fn source(&self): Option<MediaSource> on GalleryItemType. That would probably have to go into Ruma though?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah you're right; let's defer!

Comment thread crates/matrix-sdk/src/send_queue/mod.rs Outdated
Comment thread crates/matrix-sdk/src/send_queue/upload.rs
@bnjbvr bnjbvr merged commit 10668f2 into matrix-org:main May 27, 2025
43 checks passed
@bnjbvr
Copy link
Copy Markdown
Member

bnjbvr commented May 27, 2025

Thanks a bunch for getting this through the finish line 🥳 Excited to see it in action soon!

bnjbvr pushed a commit that referenced this pull request Jun 3, 2025
This was broken out of
#4838 and is a step
towards implementing
matrix-org/matrix-spec-proposals#4274. Building
upon #4977, a new
method `Timeline::send_gallery` in matrix-sdk-ui for sending galleries.

- [x] Public API changes documented in changelogs (optional)

---------

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
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