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

Do not delete the original file if it's not a temporary file when sending it to a room. #3819

Merged
merged 6 commits into from
Nov 8, 2024

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Nov 6, 2024

Content

When sending file using Element X the original file may be deleted by the application. This is an error of course and this PR fixes it.

This PR also ensure that temporary files that are created when taking a photo or a video are correctly deleted if the process is cancelled. Else such file were living in the application cache folder until this one get deleted.

Motivation and context

Fixes #3800

Screenshots / GIFs

MediaDeletion

Tests

Tested devices

  • Physical
  • Emulator
  • OS version(s):

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

@bmarty bmarty added the PR-Bugfix For bug fix label Nov 6, 2024
@bmarty bmarty requested a review from a team as a code owner November 6, 2024 14:50
@bmarty bmarty requested review from ganfra and removed request for a team November 6, 2024 14:50
@bmarty bmarty changed the title Feature/bma/fix delete original file Do not delete the original file if it's not a temporary file when sending it to a room. Nov 6, 2024
Copy link
Contributor

github-actions bot commented Nov 6, 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/3CUFXa

@bmarty bmarty added the Z-NextRelease For issues and PRs which should be included in the NextRelease. label Nov 6, 2024
import io.element.android.tests.testutils.lambda.lambdaError

class FakeTemporaryUriDeleter(
val deleteCallback: (uri: Uri?) -> Unit = { lambdaError() }
Copy link
Member

Choose a reason for hiding this comment

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

name it deleteLambda like we do elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -57,6 +60,20 @@ class AttachmentsPreviewPresenter @AssistedInject constructor(

val ongoingSendAttachmentJob = remember { mutableStateOf<Job?>(null) }

DisposableEffect(Unit) {
Copy link
Member

Choose a reason for hiding this comment

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

What if it's disposed for some reason (new screen on the backstack, config changes not handled)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes good point, so I guess I have to handle the cancellation with an event.

Copy link
Member Author

Choose a reason for hiding this comment

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

@bmarty
Copy link
Member Author

bmarty commented Nov 7, 2024

@ganfra thanks for the review, I have taken your remarks in to account. Let me know if it's fine for you!

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

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

Project coverage is 82.98%. Comparing base (64b1f30) to head (8dfe530).
Report is 7 commits behind head on develop.

Files with missing lines Patch % Lines
...libraries/androidutils/file/TemporaryUriDeleter.kt 0.00% 7 Missing ⚠️
...impl/attachments/preview/AttachmentsPreviewView.kt 50.00% 2 Missing ⚠️
.../impl/user/editprofile/EditUserProfilePresenter.kt 88.88% 0 Missing and 2 partials ⚠️
.../roomdetails/impl/edit/RoomDetailsEditPresenter.kt 88.88% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3819      +/-   ##
===========================================
+ Coverage    82.97%   82.98%   +0.01%     
===========================================
  Files         1782     1783       +1     
  Lines        44911    44961      +50     
  Branches      5287     5288       +1     
===========================================
+ Hits         37265    37311      +46     
- Misses        5799     5805       +6     
+ Partials      1847     1845       -2     

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

Copy link
Member

@ganfra ganfra left a comment

Choose a reason for hiding this comment

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

I've just realised this might be be incompatible with the new async media upload?

LaunchedEffect(state.sendActionState) {
latestOnDismiss()
}
BackHandler(enabled = state.sendActionState !is SendActionState.Sending) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need this check?

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 cancellation during the sending state is emitting a ClearSendState event, so I did not want to change this behavior.

@ganfra
Copy link
Member

ganfra commented Nov 7, 2024

I've just realised this might be be incompatible with the new async media upload?

Lets rebase on develop with the latest changes and see how it reacts?

@vidyava
Copy link

vidyava commented Nov 7, 2024

I can confirm that the issue is fixed on my physical device with the debug build posted earlier. I'll give it another try with the rebased build when one is available. Thanks for the quick turnaround on this!

@bmarty
Copy link
Member Author

bmarty commented Nov 8, 2024

Thanks a lot @vidyava . I need to rebase the branch to test again with the new way we send media, introduced in #3827

@bmarty bmarty force-pushed the feature/bma/fixDeleteOriginalFile branch from b13605d to 8dfe530 Compare November 8, 2024 09:13
Copy link

sonarcloud bot commented Nov 8, 2024

@bmarty
Copy link
Member Author

bmarty commented Nov 8, 2024

It seems to work as expected 🎉

@bmarty bmarty merged commit a0fb244 into develop Nov 8, 2024
25 of 26 checks passed
@bmarty bmarty deleted the feature/bma/fixDeleteOriginalFile branch November 8, 2024 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Bugfix For bug fix Z-NextRelease For issues and PRs which should be included in the NextRelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sharing to Element X from certain apps deletes original files
3 participants