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

Disconnect provider and ownership #7386

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

Rawa
Copy link
Contributor

@Rawa Rawa commented Dec 19, 2024

This PR changes the one-to-one relationship to one-to-many between provider and ownership.


This change is Reviewable

Copy link

linear bot commented Dec 19, 2024

@Pururun Pururun added the Android Issues related to Android label Dec 19, 2024
Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

Reviewed 12 of 12 files at r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Rawa)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt line 60 at r1 (raw file):

                            Ownership.entries
                        } else {
                            Ownership.entries.filter { ownership ->

I think this could be simplified and be more like this:

allProviders.filter { it.providerId in selectedProviders }
                     .flatMap { it.ownership }
                     .distinct()

Could probably improve on the flatmap as well.


android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt line 107 at r1 (raw file):

    fun onApplyButtonClicked() {
        val newSelectedOwnership = selectedOwnership.value.toOwnershipConstraint()
        // TODO should be all providers?!

Could do something like
availableProvidersUseCase.invoke().first()
maybe?

Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewable status: 5 of 16 files reviewed, 2 unresolved discussions (waiting on @Pururun)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt line 60 at r1 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

I think this could be simplified and be more like this:

allProviders.filter { it.providerId in selectedProviders }
                     .flatMap { it.ownership }
                     .distinct()

Could probably improve on the flatmap as well.

Fixed by reworking data.

Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewable status: 5 of 16 files reviewed, 2 unresolved discussions (waiting on @Pururun)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt line 107 at r1 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

Could do something like
availableProvidersUseCase.invoke().first()
maybe?

Simplified in new version.

@Rawa Rawa force-pushed the multiple-ownership-for-providers-droid-1704 branch 2 times, most recently from 9aa8c89 to 0529627 Compare December 20, 2024 06:35
@Rawa Rawa requested review from Pururun, kl and albin-mullvad December 20, 2024 08:22
Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 11 files at r2, 15 of 15 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Rawa)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt line 107 at r1 (raw file):

Previously, Rawa (David Göransson) wrote…

Simplified in new version.

Do we actually need allProviders in the ui state?

Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Pururun)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt line 107 at r1 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

Do we actually need allProviders in the ui state?

We need it to see if all providers are selected.

    val isAllProvidersChecked = allProviders.size == selectedProviders.size

We could use the providersToOwnershipUseCase here to get the full list of providers, but we would still need it in the UI state.

Pururun
Pururun previously approved these changes Dec 20, 2024
Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved


android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt line 107 at r1 (raw file):

Previously, Rawa (David Göransson) wrote…

We need it to see if all providers are selected.

    val isAllProvidersChecked = allProviders.size == selectedProviders.size

We could use the providersToOwnershipUseCase here to get the full list of providers, but we would still need it in the UI state.

Right, then all good!

@Rawa Rawa force-pushed the multiple-ownership-for-providers-droid-1704 branch from 0529627 to 04d9fb7 Compare December 20, 2024 09:55
Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 12 files at r1, 3 of 11 files at r2, 15 of 15 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Rawa)


android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCaseTest.kt line 25 at r3 (raw file):

    private val mockRelayListFilterRepository: RelayListFilterRepository = mockk()
    private val mockProvidersOwnershipUseCase: ProviderToOwnershipsUseCase = mockk()

nit: mockProviderToOwnershipsUseCase

Code quote:

ProvidersOwnership

android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCase.kt line 65 at r3 (raw file):

                                true
                            } else {
                                providerOwnershipRelationship[providerId]!!.contains(

Is this safe? E.g. what if a provider is used as a constraint is later removed from the relay list?

Code quote:

!!

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @Rawa)


a discussion (no related file):
Don't forget to update the changelog!

Pururun
Pururun previously approved these changes Dec 20, 2024
Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r4, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @Rawa)

Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewable status: 24 of 25 files reviewed, 1 unresolved discussion (waiting on @albin-mullvad)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCase.kt line 65 at r3 (raw file):

Previously, albin-mullvad wrote…

Is this safe? E.g. what if a provider is used as a constraint is later removed from the relay list?

Addressed. Was not safe.

Pururun
Pururun previously approved these changes Dec 20, 2024
Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @albin-mullvad)

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r4, 2 of 2 files at r5, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Rawa)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCase.kt line 65 at r3 (raw file):

Previously, Rawa (David Göransson) wrote…

Addressed. Was not safe.

Nice! 👍

Can we add some unit test to somehow cover this case as well? Basically something like:

  • Set a provider in the provider filter
  • Change the underlying relay list
  • Ensure that the provider is part of the removed relays

Might even be easier ways to achieve this 🤔


android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCase.kt line 69 at r5 (raw file):

                                // so it is visible for the user. Because we won't know what
                                // ownerships it
                                // had

nit

Code quote:

                                // ownerships it
                                // had

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Rawa)

Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewable status: 24 of 25 files reviewed, all discussions resolved (waiting on @albin-mullvad and @Pururun)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCase.kt line 65 at r3 (raw file):

Previously, albin-mullvad wrote…

Nice! 👍

Can we add some unit test to somehow cover this case as well? Basically something like:

  • Set a provider in the provider filter
  • Change the underlying relay list
  • Ensure that the provider is part of the removed relays

Might even be easier ways to achieve this 🤔

I believe @Pururun fixed tests


android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCase.kt line 69 at r5 (raw file):

Previously, albin-mullvad wrote…

nit

Addressed

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@Pururun Pururun force-pushed the multiple-ownership-for-providers-droid-1704 branch from cbbb316 to 99bd279 Compare December 20, 2024 13:28
@Pururun Pururun merged commit 7301123 into main Dec 20, 2024
38 checks passed
@Pururun Pururun deleted the multiple-ownership-for-providers-droid-1704 branch December 20, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Issues related to Android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants