Merge pull request #6376 from vector-im/fix/mna/geo-uri-pattern
[Location Share] - Adding missing prefix "u=" for uncertainty in geo URI (PSF-945)
This commit is contained in:
commit
af3718d202
|
@ -0,0 +1 @@
|
|||
[Location Share] - Adding missing prefix "u=" for uncertainty in geo URI
|
|
@ -22,7 +22,7 @@ import com.squareup.moshi.JsonClass
|
|||
@JsonClass(generateAdapter = true)
|
||||
data class LocationInfo(
|
||||
/**
|
||||
* Required. RFC5870 formatted geo uri 'geo:latitude,longitude;uncertainty' like 'geo:40.05,29.24;30' representing this location.
|
||||
* Required. RFC5870 formatted geo uri 'geo:latitude,longitude;u=uncertainty' like 'geo:40.05,29.24;u=30' representing this location.
|
||||
*/
|
||||
@Json(name = "uri") val geoUri: String? = null,
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ data class MessageLocationContent(
|
|||
@Json(name = "body") override val body: String,
|
||||
|
||||
/**
|
||||
* Required. RFC5870 formatted geo uri 'geo:latitude,longitude;uncertainty' like 'geo:40.05,29.24;30' representing this location.
|
||||
* Required. RFC5870 formatted geo uri 'geo:latitude,longitude;u=uncertainty' like 'geo:40.05,29.24;u=30' representing this location.
|
||||
*/
|
||||
@Json(name = "geo_uri") val geoUri: String,
|
||||
|
||||
|
|
|
@ -708,7 +708,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns RFC5870 formatted geo uri 'geo:latitude,longitude;uncertainty' like 'geo:40.05,29.24;30'
|
||||
* Returns RFC5870 formatted geo uri 'geo:latitude,longitude;u=uncertainty' like 'geo:40.05,29.24;u=30'
|
||||
* Uncertainty of the location is in meters and not required.
|
||||
*/
|
||||
private fun buildGeoUri(latitude: Double, longitude: Double, uncertainty: Double?): String {
|
||||
|
@ -718,7 +718,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||
append(",")
|
||||
append(longitude)
|
||||
uncertainty?.let {
|
||||
append(";")
|
||||
append(";u=")
|
||||
append(it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ private const val A_TIMEOUT_MILLIS = 15 * 60 * 1000L
|
|||
private const val A_LATITUDE = 40.05
|
||||
private const val A_LONGITUDE = 29.24
|
||||
private const val A_UNCERTAINTY = 30.0
|
||||
private const val A_GEO_URI = "geo:$A_LATITUDE,$A_LONGITUDE;$A_UNCERTAINTY"
|
||||
private const val A_GEO_URI = "geo:$A_LATITUDE,$A_LONGITUDE;u=$A_UNCERTAINTY"
|
||||
|
||||
internal class LiveLocationAggregationProcessorTest {
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ data class LocationData(
|
|||
|
||||
/**
|
||||
* Creates location data from a MessageLocationContent.
|
||||
* "geo:40.05,29.24;30" -> LocationData(40.05, 29.24, 30)
|
||||
* "geo:40.05,29.24;u=30" -> LocationData(40.05, 29.24, 30)
|
||||
* @return location data or null if geo uri is not valid
|
||||
*/
|
||||
fun MessageLocationContent.toLocationData(): LocationData? {
|
||||
|
@ -39,7 +39,7 @@ fun MessageLocationContent.toLocationData(): LocationData? {
|
|||
|
||||
/**
|
||||
* Creates location data from a geoUri String.
|
||||
* "geo:40.05,29.24;30" -> LocationData(40.05, 29.24, 30)
|
||||
* "geo:40.05,29.24;u=30" -> LocationData(40.05, 29.24, 30)
|
||||
* @return location data or null if geo uri is null or not valid
|
||||
*/
|
||||
fun String?.toLocationData(): LocationData? {
|
||||
|
|
|
@ -28,19 +28,26 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageLocationCont
|
|||
class LocationDataTest {
|
||||
@Test
|
||||
fun validCases() {
|
||||
parseGeo("geo:12.34,56.78;13.56") shouldBeEqualTo
|
||||
parseGeo("geo:12.34,56.78;u=13.56") shouldBeEqualTo
|
||||
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = 13.56)
|
||||
parseGeo("geo:12.34,56.78") shouldBeEqualTo
|
||||
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lenientCases() {
|
||||
// Error is ignored in case of invalid uncertainty
|
||||
parseGeo("geo:12.34,56.78;13.5z6") shouldBeEqualTo
|
||||
parseGeo("geo:12.34,56.78;u=13.5z6") shouldBeEqualTo
|
||||
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = null)
|
||||
parseGeo("geo:12.34,56.78;13. 56") shouldBeEqualTo
|
||||
parseGeo("geo:12.34,56.78;u=13. 56") shouldBeEqualTo
|
||||
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = null)
|
||||
// Space are ignored (trim)
|
||||
parseGeo("geo: 12.34,56.78;13.56") shouldBeEqualTo
|
||||
parseGeo("geo: 12.34,56.78;u=13.56") shouldBeEqualTo
|
||||
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = 13.56)
|
||||
parseGeo("geo:12.34,56.78; 13.56") shouldBeEqualTo
|
||||
parseGeo("geo:12.34,56.78; u=13.56") shouldBeEqualTo
|
||||
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = 13.56)
|
||||
// missing "u=" for uncertainty is ignored
|
||||
parseGeo("geo:12.34,56.78;13.56") shouldBeEqualTo
|
||||
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = 13.56)
|
||||
}
|
||||
|
||||
|
@ -50,17 +57,17 @@ class LocationDataTest {
|
|||
parseGeo("geo").shouldBeNull()
|
||||
parseGeo("geo:").shouldBeNull()
|
||||
parseGeo("geo:12.34").shouldBeNull()
|
||||
parseGeo("geo:12.34;13.56").shouldBeNull()
|
||||
parseGeo("gea:12.34,56.78;13.56").shouldBeNull()
|
||||
parseGeo("geo:12.x34,56.78;13.56").shouldBeNull()
|
||||
parseGeo("geo:12.34,56.7y8;13.56").shouldBeNull()
|
||||
parseGeo("geo:12.34;u=13.56").shouldBeNull()
|
||||
parseGeo("gea:12.34,56.78;u=13.56").shouldBeNull()
|
||||
parseGeo("geo:12.x34,56.78;u=13.56").shouldBeNull()
|
||||
parseGeo("geo:12.34,56.7y8;u=13.56").shouldBeNull()
|
||||
// Spaces are not ignored if inside the numbers
|
||||
parseGeo("geo:12.3 4,56.78;13.56").shouldBeNull()
|
||||
parseGeo("geo:12.34,56.7 8;13.56").shouldBeNull()
|
||||
parseGeo("geo:12.3 4,56.78;u=13.56").shouldBeNull()
|
||||
parseGeo("geo:12.34,56.7 8;u=13.56").shouldBeNull()
|
||||
// Or in the protocol part
|
||||
parseGeo(" geo:12.34,56.78;13.56").shouldBeNull()
|
||||
parseGeo("ge o:12.34,56.78;13.56").shouldBeNull()
|
||||
parseGeo("geo :12.34,56.78;13.56").shouldBeNull()
|
||||
parseGeo(" geo:12.34,56.78;u=13.56").shouldBeNull()
|
||||
parseGeo("ge o:12.34,56.78;u=13.56").shouldBeNull()
|
||||
parseGeo("geo :12.34,56.78;u=13.56").shouldBeNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -77,7 +84,7 @@ class LocationDataTest {
|
|||
|
||||
@Test
|
||||
fun unstablePrefixTest() {
|
||||
val geoUri = "geo :12.34,56.78;13.56"
|
||||
val geoUri = "aGeoUri"
|
||||
|
||||
val contentWithUnstablePrefixes = MessageLocationContent(body = "", geoUri = "", unstableLocationInfo = LocationInfo(geoUri = geoUri))
|
||||
contentWithUnstablePrefixes.getBestLocationInfo()?.geoUri.shouldBeEqualTo(geoUri)
|
||||
|
|
|
@ -46,7 +46,7 @@ private const val A_LOCATION_TIMESTAMP = 122L
|
|||
private const val A_LATITUDE = 40.05
|
||||
private const val A_LONGITUDE = 29.24
|
||||
private const val A_UNCERTAINTY = 30.0
|
||||
private const val A_GEO_URI = "geo:$A_LATITUDE,$A_LONGITUDE;$A_UNCERTAINTY"
|
||||
private const val A_GEO_URI = "geo:$A_LATITUDE,$A_LONGITUDE;u=$A_UNCERTAINTY"
|
||||
|
||||
class UserLiveLocationViewStateMapperTest {
|
||||
|
||||
|
|
Loading…
Reference in New Issue