From 48becf0c66790a9501591eabf96b1123b3055bec Mon Sep 17 00:00:00 2001 From: Juan D Date: Wed, 24 Jan 2024 13:50:09 +0100 Subject: [PATCH] PIA-839: Add region's iso within the shadowsocks server response --- .../regions/internals/Regions.kt | 23 +++++++++++++++---- .../model/ShadowsocksRegionsResponse.kt | 7 +----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/regions/src/commonMain/kotlin/com/privateinternetaccess/regions/internals/Regions.kt b/regions/src/commonMain/kotlin/com/privateinternetaccess/regions/internals/Regions.kt index 3464c9d..d4552f3 100644 --- a/regions/src/commonMain/kotlin/com/privateinternetaccess/regions/internals/Regions.kt +++ b/regions/src/commonMain/kotlin/com/privateinternetaccess/regions/internals/Regions.kt @@ -321,9 +321,11 @@ public class Regions internal constructor( val localizedRegions = mutableListOf() for (region in shadowsocksRegionsResponse) { - val regionTranslation = shadowsocksRegionTranslation(region.region, vpnRegionsResponse) - ?: continue - localizedRegions.add(region.copy(region = regionTranslation)) + shadowsocksRegionTranslation(region.region, vpnRegionsResponse)?.let { translation -> + shadowsocksRegionIso(region.region, vpnRegionsResponse)?.let { iso -> + localizedRegions.add(region.copy(iso = iso, region = translation)) + } + } } return Result.success(localizedRegions) } @@ -369,14 +371,25 @@ public class Regions internal constructor( vpnRegionsResponse: VpnRegionsResponse ): String? { for (region in vpnRegionsResponse.regions) { - - if (region.id.startsWith(shadowsocksRegion, ignoreCase = true)) { + if (region.id.equals(shadowsocksRegion, ignoreCase = true)) { return region.name } } return null } + private fun shadowsocksRegionIso( + shadowsocksRegion: String, + vpnRegionsResponse: VpnRegionsResponse + ): String? { + for (region in vpnRegionsResponse.regions) { + if (region.id.equals(shadowsocksRegion, ignoreCase = true)) { + return region.country + } + } + return null + } + private fun coordinatesForRegionId( targetRegionId: String, translationsGeoResponse: TranslationsGeoResponse diff --git a/regions/src/commonMain/kotlin/com/privateinternetaccess/regions/model/ShadowsocksRegionsResponse.kt b/regions/src/commonMain/kotlin/com/privateinternetaccess/regions/model/ShadowsocksRegionsResponse.kt index ab9187a..428495f 100644 --- a/regions/src/commonMain/kotlin/com/privateinternetaccess/regions/model/ShadowsocksRegionsResponse.kt +++ b/regions/src/commonMain/kotlin/com/privateinternetaccess/regions/model/ShadowsocksRegionsResponse.kt @@ -18,20 +18,15 @@ package com.privateinternetaccess.regions.model * Internet Access Mobile Client. If not, see . */ -import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable public data class ShadowsocksRegionsResponse( - @SerialName("region") + val iso: String = "world", val region: String, - @SerialName("host") val host: String, - @SerialName("port") val port: Int, - @SerialName("key") val key: String, - @SerialName("cipher") val cipher: String )