Skip to content

Commit

Permalink
Merge branch 'filter-in-location-always-block-uk-droid-323'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Sep 8, 2023
2 parents 49f624c + 639c4a8 commit d5c67e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.shareIn
Expand Down Expand Up @@ -132,14 +131,10 @@ class ConnectViewModel(
.debounce(UI_STATE_DEBOUNCE_DURATION_MILLIS)
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), ConnectUiState.INITIAL)

private fun LocationInfoCache.locationCallbackFlow() =
callbackFlow {
onNewLocation = { this.trySend(it) }
awaitClose { onNewLocation = null }
}
// Filter out empty or short-name country representations.
// We want to keep null location to handle those situations
.filter { it?.let { location -> location.country.length > 2 } ?: true }
private fun LocationInfoCache.locationCallbackFlow() = callbackFlow {
onNewLocation = { this.trySend(it) }
awaitClose { onNewLocation = null }
}

private fun RelayListListener.relayListCallbackFlow() = callbackFlow {
onRelayCountriesChange = { _, item -> this.trySend(item) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,30 +223,6 @@ class ConnectViewModelTest {
}
}

@Test
fun testLocationUpdateFilteredCountry() =
// Arrange
runTest(testCoroutineRule.testDispatcher) {
val locationTestItem =
GeoIpLocation(
ipv4 = mockk(relaxed = true),
ipv6 = mockk(relaxed = true),
country = "SW",
city = "gb",
hostname = "Ho"
)

// Act, Assert
viewModel.uiState.test {
assertEquals(ConnectUiState.INITIAL, awaitItem())
serviceConnectionState.value =
ServiceConnectionState.ConnectedReady(mockServiceConnectionContainer)
locationSlot.captured.invoke(locationTestItem)
relaySlot.captured.invoke(mockk(), mockk())
expectNoEvents()
}
}

@Test
fun testLocationUpdateNullLocation() =
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class LocationInfoCache(private val endpoint: ServiceEndpoint) {
when (newState.actionAfterDisconnect) {
ActionAfterDisconnect.Nothing -> location = lastKnownRealLocation
ActionAfterDisconnect.Block -> location = null
ActionAfterDisconnect.Reconnect -> location = selectedRelayLocation
ActionAfterDisconnect.Reconnect -> {
lastKnownRealLocation?.let { location = it }
}
}
}
is TunnelState.Error -> location = null
Expand Down

0 comments on commit d5c67e4

Please sign in to comment.