Skip to content

Commit

Permalink
PIA-839: Add region's iso within the shadowsocks server response
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-juan-docal committed Jan 24, 2024
1 parent 1cb1658 commit 48becf0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,11 @@ public class Regions internal constructor(

val localizedRegions = mutableListOf<ShadowsocksRegionsResponse>()
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)
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ package com.privateinternetaccess.regions.model
* Internet Access Mobile Client. If not, see <https://www.gnu.org/licenses/>.
*/

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
)

0 comments on commit 48becf0

Please sign in to comment.