Skip to content

Commit 1d58cd6

Browse files
committed
Merge branch 'user-can-have-duplicate-entries-in-custom-list-droid-912'
2 parents 5815716 + 28563f3 commit 1d58cd6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import net.mullvad.mullvadvpn.model.Constraint
1919
import net.mullvad.mullvadvpn.model.Ownership
2020
import net.mullvad.mullvadvpn.relaylist.Provider
2121
import net.mullvad.mullvadvpn.relaylist.RelayItem
22+
import net.mullvad.mullvadvpn.relaylist.descendants
2223
import net.mullvad.mullvadvpn.relaylist.filterOnOwnershipAndProvider
2324
import net.mullvad.mullvadvpn.relaylist.filterOnSearchTerm
2425
import net.mullvad.mullvadvpn.relaylist.toLocationConstraint
@@ -137,7 +138,8 @@ class SelectLocationViewModel(
137138

138139
fun addLocationToList(item: RelayItem, customList: RelayItem.CustomList) {
139140
viewModelScope.launch {
140-
val newLocations = (customList.locations + item).map { it.code }
141+
val newLocations =
142+
(customList.locations + item).filter { it !in item.descendants() }.map { it.code }
141143
val result =
142144
customListActionUseCase.performAction(
143145
CustomListAction.UpdateLocations(customList.id, newLocations)

android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import net.mullvad.mullvadvpn.model.Providers
2929
import net.mullvad.mullvadvpn.relaylist.Provider
3030
import net.mullvad.mullvadvpn.relaylist.RelayItem
3131
import net.mullvad.mullvadvpn.relaylist.RelayList
32+
import net.mullvad.mullvadvpn.relaylist.descendants
3233
import net.mullvad.mullvadvpn.relaylist.filterOnSearchTerm
3334
import net.mullvad.mullvadvpn.relaylist.toLocationConstraint
3435
import net.mullvad.mullvadvpn.ui.serviceconnection.ConnectionProxy
@@ -264,7 +265,10 @@ class SelectLocationViewModelTest {
264265
fun `after adding a location to a list should emit location added side effect`() = runTest {
265266
// Arrange
266267
val expectedResult: CustomListResult.LocationsChanged = mockk()
267-
val location: RelayItem = mockk { every { code } returns "code" }
268+
val location: RelayItem = mockk {
269+
every { code } returns "code"
270+
every { descendants() } returns emptyList()
271+
}
268272
val customList: RelayItem.CustomList = mockk {
269273
every { id } returns "1"
270274
every { locations } returns emptyList()

0 commit comments

Comments
 (0)