From 8ff134e4d7a57ffde2136b10bd90de1649419dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Fri, 19 Apr 2024 10:37:13 +0200 Subject: [PATCH] Fix duplicate entries when adding through bottom sheet --- .../mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt index 1759055bda9e..9772fb636286 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt @@ -19,6 +19,7 @@ import net.mullvad.mullvadvpn.model.Constraint import net.mullvad.mullvadvpn.model.Ownership import net.mullvad.mullvadvpn.relaylist.Provider import net.mullvad.mullvadvpn.relaylist.RelayItem +import net.mullvad.mullvadvpn.relaylist.descendants import net.mullvad.mullvadvpn.relaylist.filterOnOwnershipAndProvider import net.mullvad.mullvadvpn.relaylist.filterOnSearchTerm import net.mullvad.mullvadvpn.relaylist.toLocationConstraint @@ -137,7 +138,8 @@ class SelectLocationViewModel( fun addLocationToList(item: RelayItem, customList: RelayItem.CustomList) { viewModelScope.launch { - val newLocations = (customList.locations + item).map { it.code } + val newLocations = + (customList.locations + item).filter { it !in item.descendants() }.map { it.code } val result = customListActionUseCase.performAction( CustomListAction.UpdateLocations(customList.id, newLocations)