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

Remove duplicated code regarding user (room member and user profile) screens #3700

Merged
merged 8 commits into from
Oct 18, 2024

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Oct 17, 2024

Content

Let RoomMemberDetailsPresenter delegates the computation of profile state to UserProfilePresenter, which allow to reduce code duplication.

Motivation and context

Less code duplication (production and test).

Preparatory work for #3684

Screenshots / GIFs

Tests

There should be no change.

  • Navigate to some room member details page
  • Open matrix user profile, with member not in room (can be done using adb)

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-Misc For other changes label Oct 17, 2024
@bmarty bmarty requested a review from a team as a code owner October 17, 2024 12:19
@bmarty bmarty requested review from jmartinesp and removed request for a team October 17, 2024 12:19
@bmarty bmarty changed the title Feature/bma/remove duplicated code Remove duplicated code regarding user (room member and user profile) screens Oct 17, 2024
Copy link
Contributor

github-actions bot commented Oct 17, 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/QTwTpH

private val factory: UserProfilePresenter.Factory,
) : UserProfilePresenterFactory {
override fun create(userId: UserId): Presenter<UserProfileState> = factory.create(userId)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This double factory level is a bit weird, there is maybe a better way to handle this. Any ideas @ganfra @jmartinesp ?

Copy link
Member

Choose a reason for hiding this comment

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

I can't see any, sorry... I was going to suggest trying to reuse UserProfilePresenter.Factory but that's not possible since the AssistedFactory needs to return a concrete type.

The best I could get was making UserProfilePresenter.Factory implement UserProfilePresenterFactory, then use it in DefaultUserProfilePresenterFactory like this:

@ContributesBinding(SessionScope::class)
class DefaultUserProfilePresenterFactory @Inject constructor(
    private val factory: UserProfilePresenter.Factory,
) : UserProfilePresenterFactory by factory

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for looking into it. Let's keep it like this then!

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 68.88889% with 14 lines in your changes missing coverage. Please review.

Project coverage is 82.77%. Comparing base (e3bc9a2) to head (6106d7b).
Report is 11 commits behind head on develop.

Files with missing lines Patch % Lines
...d/features/roomdetails/impl/di/RoomMemberModule.kt 0.00% 4 Missing ⚠️
...s/userprofile/shared/blockuser/BlockUserSection.kt 42.85% 1 Missing and 3 partials ⚠️
...profile/impl/DefaultUserProfilePresenterFactory.kt 0.00% 3 Missing ⚠️
...ures/userprofile/impl/root/UserProfilePresenter.kt 86.36% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3700      +/-   ##
===========================================
- Coverage    82.79%   82.77%   -0.02%     
===========================================
  Files         1752     1751       -1     
  Lines        41967    41926      -41     
  Branches      5125     5120       -5     
===========================================
- Hits         34746    34705      -41     
- Misses        5398     5401       +3     
+ Partials      1823     1820       -3     

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

Copy link
Member

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

LGTM, it's a shame we can't simplify it anymore.

@@ -55,6 +55,7 @@ class UserProfilePresenter @AssistedInject constructor(
@Composable
override fun present(): UserProfileState {
val coroutineScope = rememberCoroutineScope()
val isCurrentUser = remember { client.isMe(userId) }
Copy link
Member

Choose a reason for hiding this comment

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

👌

client = client,
)
@Composable
fun getDmRoomId(): State<RoomId?> {
Copy link
Member

Choose a reason for hiding this comment

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

private fun here and below?

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, done in the latest commit: e46503a

private val factory: UserProfilePresenter.Factory,
) : UserProfilePresenterFactory {
override fun create(userId: UserId): Presenter<UserProfileState> = factory.create(userId)
}
Copy link
Member

Choose a reason for hiding this comment

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

I can't see any, sorry... I was going to suggest trying to reuse UserProfilePresenter.Factory but that's not possible since the AssistedFactory needs to return a concrete type.

The best I could get was making UserProfilePresenter.Factory implement UserProfilePresenterFactory, then use it in DefaultUserProfilePresenterFactory like this:

@ContributesBinding(SessionScope::class)
class DefaultUserProfilePresenterFactory @Inject constructor(
    private val factory: UserProfilePresenter.Factory,
) : UserProfilePresenterFactory by factory

@bmarty bmarty added the Run-Maestro Starts a Maestro Cloud session to run integration tests label Oct 17, 2024
@bmarty bmarty enabled auto-merge October 17, 2024 14:35
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label Oct 17, 2024
Copy link

sonarcloud bot commented Oct 17, 2024

@bmarty bmarty disabled auto-merge October 18, 2024 07:13
@bmarty bmarty merged commit f632a1f into develop Oct 18, 2024
27 of 30 checks passed
@bmarty bmarty deleted the feature/bma/removeDuplicatedCode branch October 18, 2024 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Misc For other changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants