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

fix: self-deleting msg in doze mode on ConversationScreen [WPB-5894] #2653

Merged
merged 3 commits into from
Feb 2, 2024

Conversation

saleniuk
Copy link
Contributor

@saleniuk saleniuk commented Feb 1, 2024

BugWPB-5894 [Android] Self deleting messages timer stops when device is in doze mode

Cherry pick from the original PR:

Also contains fixes from this PR:


PR Submission Checklist for internal contributors

  • The PR Title

    • conforms to the style of semantic commits messages¹ supported in Wire's Github Workflow²
    • contains a reference JIRA issue number like SQPIT-764
    • answers the question: If merged, this PR will: ... ³
  • The PR Description

    • is free of optional paragraphs and you have filled the relevant parts to the best of your ability

What's new in this PR?

Issues

When the user receives a self-deleting message, leaves the app on ConversationScreen and the app is put into background, then the message is not removed after given time when app is opened again, only when the user closes the ConversationScreen and opens it again. When the given time is not fully passed, the message counter is not properly updated, it stays on the value it had when the app was put into background. Sometimes this counter doesn't get updated for the next interval, for instance it starts with "4 minutes left" and after a minute passes it's still "4 minutes left" but then after another minute it suddenly goes down to "2 minutes left".

Causes (Optional)

Previous solution was implemented to check and remove all expired messages when the user opens the ConversationScreen so it's not working when the user is still on that screen. For the counter, there's another delay which also doesn't work well when in doze mode and the counter composable isn't recomposed because the value is not being passed as a state. Also, the amount of time to be delayed is not calculated properly - it takes only one unit into account, so for instance if the time left for the message is equal to 1:59.900 left (1 minute 59 seconds and 900ms) then it will delay for 59 seconds, omitting the milliseconds value and resulting in next calculation being done when the time left is 1:00.900, so still over a minute, that's why it can give the result of "1 minute left" for 2 minutes.

Solutions

Implement a global observer to execute deleteEphemeralMessageEndDate each time the app is back in the foreground.
Refactor the SelfDeletionTimerHelper to take "end time" when handling self-deleting expiration and recalculate the time again each time the delay ends by comparing "current time" and "end time" instead of just subtracting the "delay time" - thanks to that it has more accurate time left in each iteration.
Fix the updateInterval function to return the full remaining time to the next given duration unit (for instance if we want to get time remaining to the next full minute and now the time is 1:59.900 then it should return 59.900)
Provide timeLeftFormatted as a state so that the composable that's showing it gets recomposed each time it's updated.
Implement another LaunchedEffect to recalculate the time left and restart the delay when the app is back in the foreground.

Testing

Test Coverage (Optional)

  • I have added automated test to this contribution

How to Test

Receive a self-deleting message and put the app in the background while still being on the ConversationScreen, turn off the screen so that it can enter doze mode and open the app again before or after the time for the self-deleting message passes.


PR Post Submission Checklist for internal contributors (Optional)

  • Wire's Github Workflow has automatically linked the PR to a JIRA issue

PR Post Merge Checklist for internal contributors

  • If any soft of configuration variable was introduced by this PR, it has been added to the relevant documents and the CI jobs have been updated.

References
  1. https://sparkbox.com/foundry/semantic_commit_messages
  2. https://github.com/wireapp/.github#usage
  3. E.g. feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764.

@saleniuk saleniuk added the cherry-pick PR is cherry-picking changes from another banch label Feb 1, 2024
Copy link

codecov bot commented Feb 1, 2024

Codecov Report

Attention: 58 lines in your changes are missing coverage. Please review.

Comparison is base (122ae8b) 41.49% compared to head (17d37f0) 41.82%.
Report is 1 commits behind head on develop.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #2653      +/-   ##
=============================================
+ Coverage      41.49%   41.82%   +0.32%     
- Complexity      1157     1158       +1     
=============================================
  Files            367      367              
  Lines          13305    13327      +22     
  Branches        1753     1769      +16     
=============================================
+ Hits            5521     5574      +53     
+ Misses          7256     7213      -43     
- Partials         528      540      +12     
Files Coverage Δ
.../kotlin/com/wire/android/GlobalObserversManager.kt 81.81% <87.50%> (+11.60%) ⬆️
...android/ui/home/conversations/MessageExpiration.kt 31.62% <33.72%> (+31.62%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 122ae8b...17d37f0. Read the comment docs.

Copy link
Contributor

github-actions bot commented Feb 1, 2024

Test Results

789 tests  +35   789 ✅ +35   6m 58s ⏱️ -21s
107 suites + 1     0 💤 ± 0 
107 files   + 1     0 ❌ ± 0 

Results for commit 17d37f0. ± Comparison against base commit 122ae8b.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Feb 1, 2024

APKs built during tests are available here. Scroll down to Artifacts!

@AndroidBob
Copy link
Collaborator

Build 2829 failed.

Copy link
Contributor

github-actions bot commented Feb 1, 2024

APKs built during tests are available here. Scroll down to Artifacts!

@AndroidBob
Copy link
Collaborator

Build 2834 failed.

@pull-request-size pull-request-size bot added size/XL and removed size/L labels Feb 2, 2024
Copy link

Ups 🫰🟨

This PR is too big. Please try to break it up into smaller PRs.

Copy link
Contributor

github-actions bot commented Feb 2, 2024

APKs built during tests are available here. Scroll down to Artifacts!

@AndroidBob
Copy link
Collaborator

Build 2846 succeeded.

The build produced the following APK's:

@saleniuk saleniuk added this pull request to the merge queue Feb 2, 2024
Merged via the queue into develop with commit b629f32 Feb 2, 2024
16 checks passed
@saleniuk saleniuk deleted the fix/self-deleting-msgs-in-doze-mode-cherry-pick branch February 2, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick PR is cherry-picking changes from another banch size/XL
Projects
None yet
4 participants