diff options
Diffstat (limited to 'android')
4 files changed, 19 insertions, 26 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt index 32dd9a8e0e..6b8fd69ff8 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt @@ -28,7 +28,10 @@ class CustomListsRepository( .mapNotNull { it.customLists } .stateIn(CoroutineScope(dispatcher), SharingStarted.Eagerly, null) - suspend fun createCustomList(name: CustomListName) = managementService.createCustomList(name) + suspend fun createCustomList( + name: CustomListName, + locations: List<GeoLocationId> = emptyList(), + ) = managementService.createCustomList(name, locations) suspend fun deleteCustomList(id: CustomListId) = managementService.deleteCustomList(id) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt index b1326d57b9..da1b6fcb56 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt @@ -10,10 +10,8 @@ import net.mullvad.mullvadvpn.compose.communication.Deleted import net.mullvad.mullvadvpn.compose.communication.LocationsChanged import net.mullvad.mullvadvpn.compose.communication.Renamed import net.mullvad.mullvadvpn.lib.model.CreateCustomListError -import net.mullvad.mullvadvpn.lib.model.CustomList import net.mullvad.mullvadvpn.lib.model.DeleteCustomListError import net.mullvad.mullvadvpn.lib.model.GetCustomListError -import net.mullvad.mullvadvpn.lib.model.UpdateCustomListError import net.mullvad.mullvadvpn.lib.model.UpdateCustomListLocationsError import net.mullvad.mullvadvpn.lib.model.UpdateCustomListNameError import net.mullvad.mullvadvpn.relaylist.getRelayItemsByCodes @@ -54,23 +52,12 @@ class CustomListActionUseCase( ): Either<CreateWithLocationsError, Created> = either { val customListId = customListsRepository - .createCustomList(action.name) + .createCustomList(action.name, action.locations) .mapLeft(CreateWithLocationsError::Create) .bind() val locationNames = if (action.locations.isNotEmpty()) { - customListsRepository - .updateCustomList( - CustomList( - id = customListId, - name = action.name, - locations = action.locations, - ) - ) - .mapLeft(CreateWithLocationsError::UpdateCustomList) - .bind() - relayListRepository.relayList .firstOrNull() ?.getRelayItemsByCodes(action.locations) @@ -129,8 +116,6 @@ sealed interface CreateWithLocationsError : CustomListActionError { data class Create(val error: CreateCustomListError) : CreateWithLocationsError - data class UpdateCustomList(val error: UpdateCustomListError) : CreateWithLocationsError - data object UnableToFetchRelayList : CreateWithLocationsError } diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt index 03d46cbde0..d9a687362a 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt @@ -62,12 +62,8 @@ class CustomListActionUseCaseTest { undo = action.not(createdId), ) .right() - coEvery { mockCustomListsRepository.createCustomList(name) } returns createdId.right() - coEvery { - mockCustomListsRepository.updateCustomList( - CustomList(createdId, name, listOf(locationId)) - ) - } returns Unit.right() + coEvery { mockCustomListsRepository.createCustomList(name, listOf(locationId)) } returns + createdId.right() relayListFlow.value = listOf( RelayItem.Location.Country( @@ -91,7 +87,7 @@ class CustomListActionUseCaseTest { val locationId = GeoLocationId.Country("AB") val action = CustomListAction.Create(name = name, locations = listOf(locationId)) val expectedError = CreateWithLocationsError.Create(CustomListAlreadyExists).left() - coEvery { mockCustomListsRepository.createCustomList(name) } returns + coEvery { mockCustomListsRepository.createCustomList(name, listOf(locationId)) } returns CustomListAlreadyExists.left() // Act diff --git a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt index f306c9f833..cff4e2bd3e 100644 --- a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt +++ b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt @@ -76,6 +76,7 @@ import net.mullvad.mullvadvpn.lib.model.DnsOptions as ModelDnsOptions import net.mullvad.mullvadvpn.lib.model.DnsOptions import net.mullvad.mullvadvpn.lib.model.DnsState as ModelDnsState import net.mullvad.mullvadvpn.lib.model.DnsState +import net.mullvad.mullvadvpn.lib.model.GeoLocationId import net.mullvad.mullvadvpn.lib.model.GetAccountDataError import net.mullvad.mullvadvpn.lib.model.GetAccountHistoryError import net.mullvad.mullvadvpn.lib.model.GetDeviceListError @@ -576,9 +577,17 @@ class ManagementService( .mapEmpty() suspend fun createCustomList( - name: CustomListName + name: CustomListName, + locations: List<GeoLocationId> = emptyList(), ): Either<CreateCustomListError, CustomListId> = - Either.catch { grpc.createCustomList(StringValue.of(name.value)) } + Either.catch { + grpc.createCustomList( + ManagementInterface.NewCustomList.newBuilder() + .setName(name.value) + .addAllLocations(locations.map(GeoLocationId::fromDomain)) + .build() + ) + } .map { CustomListId(it.value) } .mapLeftStatus { when (it.status.code) { |
