summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Göransson <david.goransson@mullvad.net>2025-04-17 16:18:29 +0200
committerDavid Göransson <david.goransson@mullvad.net>2025-04-17 16:18:29 +0200
commit707827cbe7815e696dcdb78f747f8f396b0742b7 (patch)
tree2f71dd6330c3fc15f00d6873b68fc14695791445
parent0bc5042a286fece386f0f179320f23a3f339f11d (diff)
parent0bcf6d3b84c5ab1505ae370252a1d541baee70f2 (diff)
downloadmullvadvpn-707827cbe7815e696dcdb78f747f8f396b0742b7.tar.xz
mullvadvpn-707827cbe7815e696dcdb78f747f8f396b0742b7.zip
Merge branch 'fix-get-custom-list-by-id'
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt25
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt15
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt4
3 files changed, 26 insertions, 18 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 c53d07320f..32dd9a8e0e 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
@@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.repository
import arrow.core.Either
import arrow.core.raise.either
+import co.touchlab.kermit.Logger
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -9,7 +10,6 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.stateIn
-import net.mullvad.mullvadvpn.lib.common.util.firstOrNullWithTimeout
import net.mullvad.mullvadvpn.lib.daemon.grpc.ManagementService
import net.mullvad.mullvadvpn.lib.model.CustomList
import net.mullvad.mullvadvpn.lib.model.CustomListId
@@ -32,7 +32,7 @@ class CustomListsRepository(
suspend fun deleteCustomList(id: CustomListId) = managementService.deleteCustomList(id)
- private suspend fun updateCustomList(customList: CustomList) =
+ suspend fun updateCustomList(customList: CustomList) =
managementService.updateCustomList(customList)
suspend fun updateCustomListName(
@@ -55,16 +55,15 @@ class CustomListsRepository(
.bind()
}
- suspend fun getCustomListById(id: CustomListId): Either<GetCustomListError, CustomList> =
- either {
- customLists
- .mapNotNull { it?.find { customList -> customList.id == id } }
- .firstOrNullWithTimeout(GET_CUSTOM_LIST_TIMEOUT_MS)
- ?: raise(GetCustomListError(id))
- }
- .mapLeft { GetCustomListError(id) }
-
- companion object {
- private const val GET_CUSTOM_LIST_TIMEOUT_MS = 5000L
+ /**
+ * There is no guarantee this will return a up to date custom list. E.g if you invoked
+ * updateCustomList just before this you might get an out of date value.
+ */
+ fun getCustomListById(id: CustomListId): Either<GetCustomListError, CustomList> = either {
+ val customLists =
+ customLists.value
+ ?: raise(GetCustomListError(id)).also { Logger.e("Custom lists never loaded") }
+ customLists.firstOrNull { customList -> customList.id == id }
+ ?: raise(GetCustomListError(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 5fb7b0e964..b1326d57b9 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,8 +10,10 @@ 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
@@ -59,8 +61,14 @@ class CustomListActionUseCase(
val locationNames =
if (action.locations.isNotEmpty()) {
customListsRepository
- .updateCustomListLocations(customListId, action.locations)
- .mapLeft(CreateWithLocationsError::UpdateLocations)
+ .updateCustomList(
+ CustomList(
+ id = customListId,
+ name = action.name,
+ locations = action.locations,
+ )
+ )
+ .mapLeft(CreateWithLocationsError::UpdateCustomList)
.bind()
relayListRepository.relayList
@@ -121,8 +129,7 @@ sealed interface CreateWithLocationsError : CustomListActionError {
data class Create(val error: CreateCustomListError) : CreateWithLocationsError
- data class UpdateLocations(val error: UpdateCustomListLocationsError) :
- 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 233d429bc4..03d46cbde0 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
@@ -64,7 +64,9 @@ class CustomListActionUseCaseTest {
.right()
coEvery { mockCustomListsRepository.createCustomList(name) } returns createdId.right()
coEvery {
- mockCustomListsRepository.updateCustomListLocations(createdId, listOf(locationId))
+ mockCustomListsRepository.updateCustomList(
+ CustomList(createdId, name, listOf(locationId))
+ )
} returns Unit.right()
relayListFlow.value =
listOf(