Skip to content
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

Close the media preview screen ASAP with sending queue enabled #4089

Merged
merged 8 commits into from
Jan 8, 2025

Conversation

jmartinesp
Copy link
Member

Content

  • When the media file is done processing and we've pressed the 'send' button, just dismiss the attachment preview instead of waiting for the file to be sent.
  • For this, get the @SessionCoroutineScope from the SessionMatrixModule and use it to send the media even if the preview screen or the chat room screen are dismissed.
  • As soon as the sending process begins in background, dismiss the attachment preview screen.

Motivation and context

We decided to have this behaviour to improve the UX.

Screenshots / GIFs

Screen_recording_20241223_133920.mp4

Tests

  • Enable the 'Media upload through send queue' developer option.
  • Send a large media file, press the send button quickly.
  • There may still be some progress dialog while the thumbnail is being generated and the media is compressed, if enabled.
  • As seen in the video above, the preview screen should be dismissed and a local echo of the media file should appear.
  • After a few seconds, the media should be marked as sent.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

  • Changes have been tested on an Android device or Android emulator with API 23
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • Pull request includes a sign off
  • You've made a self review of your PR

@jmartinesp jmartinesp added the PR-Bugfix For bug fix label Dec 23, 2024
@jmartinesp jmartinesp requested a review from a team as a code owner December 23, 2024 12:43
@jmartinesp jmartinesp requested review from ganfra and removed request for a team December 23, 2024 12:43
Copy link
Contributor

github-actions bot commented Dec 23, 2024

📱 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/ejuVaG

@jmartinesp jmartinesp force-pushed the fix/early-dismiss-send-media-preview-screen branch from 8f2ed8f to 7e3d8b1 Compare December 23, 2024 13:01
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 80.88235% with 13 lines in your changes missing coverage. Please review.

Project coverage is 83.26%. Comparing base (6d1dac6) to head (52de78c).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
...attachments/preview/AttachmentsPreviewPresenter.kt 81.48% 2 Missing and 3 partials ⚠️
...oid/libraries/mediaupload/impl/ThumbnailFactory.kt 0.00% 4 Missing ⚠️
...impl/attachments/preview/AttachmentsPreviewView.kt 75.00% 2 Missing ⚠️
...mpl/attachments/preview/AttachmentsPreviewState.kt 88.88% 0 Missing and 1 partial ⚠️
...chments/preview/AttachmentsPreviewStateProvider.kt 94.44% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4089      +/-   ##
===========================================
- Coverage    83.28%   83.26%   -0.02%     
===========================================
  Files         1885     1885              
  Lines        49096    49128      +32     
  Branches      5764     5775      +11     
===========================================
+ Hits         40888    40908      +20     
- Misses        6139     6144       +5     
- Partials      2069     2076       +7     

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

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 improvement. I suspect that the gain is not as big as expected by the product, please read my comments for more details.


@SingleIn(RoomScope::class)
@MergeSubcomponent(RoomScope::class)
@MergeSubcomponent(RoomScope::class, modules = [SessionMatrixModule::class])
Copy link
Member

Choose a reason for hiding this comment

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

This change does not seem to be 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.

Either it is or the build cache was causing some issues locally for me, since I couldn't get the app to build until I explicitly added that. I think I also tried removing it later and came back to the same error where it couldn't find the @SessionCoroutineScope annotated coroutine scope, but I can double check just in case.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was the build cache ¯\_(ツ)_/¯.

@@ -240,7 +251,6 @@ class AttachmentsPreviewPresenter @AssistedInject constructor(
cleanUp(mediaUploadInfo)
// Reset the sendActionState to ensure that dialog is closed before the screen
sendActionState.value = SendActionState.Done
onDoneListener()
Copy link
Member

Choose a reason for hiding this comment

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

We still need to invoke this in the case of sendOnBackground is false, i.e. FeatureFlags.MediaUploadOnSendQueue is disabled.

Confirmed by test: the screen does not close

sendPreProcessedMedia(
mediaUploadInfo = mediaUploadInfo.data,
caption = caption,
sendActionState = sendActionState,
)
}

Copy link
Member

Choose a reason for hiding this comment

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

Just a remark here: when the send queue is enabled, the duration of the invokation of sendPreProcessedMedia stay quite short (but not negligible). I have measure that it can take up to 1s for big files. The processing of the thumbnail creation and video shrinking is much longer. So this PR is OK, but the gain is not that big.

Also note that if the user close the screen during the media pre-processing, it will cancel the media sending as well. So maybe use the session scope also for the media pre-processing? In this case the local echo will take longer to appear and killing the app during the processing will stop the sending.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also note that if the user close the screen during the media pre-processing, it will cancel the media sending as well.

But that's OK I think? The media pre-processing should be done before sending starts, and in the meantime the screen won't be dismissed since we'll have the progress dialog present: dismissing this dialog cancels the enqueued sending process, so AFAICT there's no way to close the screen before the preprocessing is done while expecting the sending to still work.

Copy link
Member

Choose a reason for hiding this comment

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

Also note that if the user close the screen during the media pre-processing, it will cancel the media sending as well. So maybe use the session scope also for the media pre-processing? In this case the local echo will take longer to appear and killing the app during the processing will stop the sending.

You can ignore this, I initially though that the PR will make the screen be closed as soon as the user press the send button (even if the pre-processing is not over), but this is not the case. Sorry about this!

@jmartinesp jmartinesp force-pushed the fix/early-dismiss-send-media-preview-screen branch from 7e3d8b1 to 47362ba Compare January 8, 2025 14:32
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.

LGTM, thanks for the update!

@jmartinesp jmartinesp enabled auto-merge (squash) January 8, 2025 15:30
Copy link

sonarqubecloud bot commented Jan 8, 2025

@jmartinesp jmartinesp merged commit 65ce91a into develop Jan 8, 2025
24 checks passed
@jmartinesp jmartinesp deleted the fix/early-dismiss-send-media-preview-screen branch January 8, 2025 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Bugfix For bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants