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

refactor: remove not needed usage of observe self user [WPB-15414] #3283

Merged

Conversation

MohamadJaara
Copy link
Member

@MohamadJaara MohamadJaara commented Feb 7, 2025

TaskWPB-15414 [Android] Fix issue with self user observation


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

ObserveSelfUserUseCase is often used like this:
val userId = observeSelf().first()

This may cause two issues:

NoSuchElementException if emptyFlow is returned.

Endless waiting for item if flow does not emit any blocking the UI in inconsistent state.

Solutions

Replace with GetSelfUserUseCase and handle possible null return value.

Dependencies (Optional)

If there are some other pull requests related to this one (e.g. new releases of frameworks), specify them here.

Needs releases with:

  • GitHub link to other pull request

Testing

Test Coverage (Optional)

  • I have added automated test to this contribution

How to Test

Briefly describe how this change was tested and if applicable the exact steps taken to verify that it works as expected.

Notes (Optional)

Specify here any other facts that you think are important for this issue.

Attachments (Optional)

Attachments like images, videos, etc. (drag and drop in the text box)


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.

Copy link

sonarqubecloud bot commented Feb 7, 2025

Copy link
Contributor

github-actions bot commented Feb 7, 2025

Test Results

3 513 tests  ±0   3 405 ✅ ±0   6m 22s ⏱️ +27s
  603 suites ±0     108 💤 ±0 
  603 files   ±0       0 ❌ ±0 

Results for commit 5ef80ec. ± Comparison against base commit 20791fd.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Feb 7, 2025

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 50.85%. Comparing base (9ca21c1) to head (5ef80ec).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3283      +/-   ##
===========================================
- Coverage    50.87%   50.85%   -0.03%     
===========================================
  Files         1606     1607       +1     
  Lines        57189    58051     +862     
  Branches      5105     5199      +94     
===========================================
+ Hits         29097    29519     +422     
- Misses       26078    26517     +439     
- Partials      2014     2015       +1     

see 35 files 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 9ca21c1...5ef80ec. Read the comment docs.

@datadog-wireapp
Copy link

Datadog Report

Branch report: refactor/remove-not-needed-usage-of-observe-self-user
Commit report: 935ab77
Test service: kalium-jvm

✅ 0 Failed, 3405 Passed, 108 Skipped, 1m 1.19s Total Time

override suspend operator fun invoke(): SelfUser? = withContext(dispatcher.io) {
userRepository.getSelfUser()
}
override suspend operator fun invoke(): SelfUser? = userRepository.getSelfUser().getOrNull()
Copy link
Contributor

Choose a reason for hiding this comment

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

Where do we switch to IO dispatcher for an IO call? I do not see it in the repository.

Copy link
Member

Choose a reason for hiding this comment

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

For network calls, Ktor will do it under the hood.
For DB, we should be doing it.

So, to keep it all tight, I guess we could do it on a repository or UseCase level. Nice catch :)

Copy link
Member Author

Choose a reason for hiding this comment

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

for db we always have withContext on the DB dispatcher


val avatarAsset = when (val publicAsset = session.users.getPublicAsset(selfUser.previewPicture!!)) {
val avatarAsset = when (val publicAsset = session.users.getPublicAsset(selfUser?.previewPicture!!)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we not handle null value in MainActivity (previewPicture!! and selfUser!!) ?

Copy link
Member

Choose a reason for hiding this comment

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

This android module within kalium is just a Sandbox for testing code.
It's an archeological relic from the times where we were bootstraping the new code in a sample app before actually porting everything to the wire/android project.

We could delete the whole module, from my personal point of view. But I guess it could be useful at some point to just test some changes in kalium without having to wait for a PR on Android ?

override suspend operator fun invoke(): SelfUser? = withContext(dispatcher.io) {
userRepository.getSelfUser()
}
override suspend operator fun invoke(): SelfUser? = userRepository.getSelfUser().getOrNull()
Copy link
Member

Choose a reason for hiding this comment

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

For network calls, Ktor will do it under the hood.
For DB, we should be doing it.

So, to keep it all tight, I guess we could do it on a repository or UseCase level. Nice catch :)

@MohamadJaara MohamadJaara added this pull request to the merge queue Feb 11, 2025
Merged via the queue into develop with commit 00d2335 Feb 11, 2025
24 checks passed
@MohamadJaara MohamadJaara deleted the refactor/remove-not-needed-usage-of-observe-self-user branch February 11, 2025 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants