Skip to content

Media upload cancellation #1058

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

Merged
merged 7 commits into from
Aug 17, 2023
Merged

Conversation

jmartinesp
Copy link
Member

Changes

  • Adds MediaUploadHandler as an abstraction over SendAttachmentJoinHandler.
  • Adds a cancel option to the send media dialogs.
  • Ties media upload to the coroutine that runs the code, so if the coroutine is cancelled, so is the upload.
  • Makes sure we remove any temporary files from cache both when either finish uploading or it fails.

Why

Closes #769 .

@jmartinesp jmartinesp requested a review from a team as a code owner August 14, 2023 10:25
@jmartinesp jmartinesp requested review from bmarty and removed request for a team August 14, 2023 10:25
Copy link
Member Author

Choose a reason for hiding this comment

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

I actually have no idea why this screenshot was updated 🤔 .

@github-actions
Copy link
Contributor

github-actions bot commented Aug 14, 2023

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/ijMPuP

@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Patch coverage: 65.76% and project coverage change: +0.06% 🎉

Comparison is base (a911134) 56.91% compared to head (014b8ac) 56.98%.
Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1058      +/-   ##
===========================================
+ Coverage    56.91%   56.98%   +0.06%     
===========================================
  Files          997      999       +2     
  Lines        25343    25407      +64     
  Branches      5077     5090      +13     
===========================================
+ Hits         14424    14477      +53     
- Misses        8696     8705       +9     
- Partials      2223     2225       +2     
Files Changed Coverage Δ
...nt/android/libraries/matrix/api/room/MatrixRoom.kt 33.33% <ø> (ø)
...raries/matrix/impl/media/MediaUploadHandlerImpl.kt 0.00% <0.00%> (ø)
...droid/libraries/matrix/impl/room/RustMatrixRoom.kt 0.00% <0.00%> (ø)
...ent/android/features/messages/impl/MessagesView.kt 58.67% <42.85%> (-0.49%) ⬇️
...droid/libraries/matrix/test/room/FakeMatrixRoom.kt 90.18% <44.44%> (-1.07%) ⬇️
...raries/matrix/test/media/FakeMediaUploadHandler.kt 75.00% <75.00%> (ø)
...attachments/preview/AttachmentsPreviewPresenter.kt 86.95% <85.71%> (-1.28%) ⬇️
...s/impl/messagecomposer/MessageComposerPresenter.kt 91.39% <85.71%> (-0.59%) ⬇️
...t/android/libraries/mediaupload/api/MediaSender.kt 64.70% <93.75%> (+16.05%) ⬆️
...impl/attachments/preview/AttachmentsPreviewView.kt 59.74% <100.00%> (+1.07%) ⬆️
... and 2 more

... and 2 files with indirect coverage changes

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

@jmartinesp jmartinesp force-pushed the feature/jme/769-cancel-media-upload branch from c73f915 to cb8c096 Compare August 14, 2023 11:08
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Nice work.
I tried to send an image and cancel the upload. I was still on the image preview, like if the image had not been sent. But the image was sent in the timeline.

},
onFailure = {
sendActionState.value = SendActionState.Failure(it)
).getOrThrow()
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure. Is this .getOrThrow() necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need it to catch the CancellationException that won't come inside the Result. I tried several ways to get it wrapped inside this Result, but none of them worked.

) = launch {
when (attachment) {
is Attachment.Media -> {
) = when (attachment) {
Copy link
Member

Choose a reason for hiding this comment

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

There is some code duplication in the class AttachmentsPreviewPresenter, is there a (easy) way to reduce this?

Copy link
Member Author

Choose a reason for hiding this comment

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

The 2 functions are quite similar, but they pass different data to their sendMedia counterparts. We could try wrapping those in some use case or helper class, but I'm not sure it's worth it for just 2 occurrences. Also, I think we want to remove the upload progress from the AttachmentsPreviewView in the future as display it on the the timeline item instead, so part of this code will probably disappear.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@jmartinesp jmartinesp requested a review from bmarty August 17, 2023 06:41
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Thanks for the update and for your answers!

@jmartinesp
Copy link
Member Author

I tried to send an image and cancel the upload. I was still on the image preview, like if the image had not been sent. But the image was sent in the timeline.

I just saw this, sorry. Unless the upload takes long it's quite difficult to cancel it, and images are usually quite fast, so maybe the cancellation happened after the file has been uploaded but before we got the response from the server as a timeline item.

@jmartinesp jmartinesp added this pull request to the merge queue Aug 17, 2023
Merged via the queue into develop with commit 983b83a Aug 17, 2023
@jmartinesp jmartinesp deleted the feature/jme/769-cancel-media-upload branch August 17, 2023 09:02
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.

Cancel upload media
2 participants