From a4cae9ef077eea29f047b5be5953a4e85f395449 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Thu, 23 Jun 2022 17:40:16 +0200 Subject: [PATCH] Fixing missing "u=" in geo URI pattern for uncertainty --- .../room/model/message/LocationInfo.kt | 2 +- .../model/message/MessageLocationContent.kt | 2 +- .../room/send/LocalEchoEventFactory.kt | 4 +-- .../LiveLocationAggregationProcessorTest.kt | 2 +- .../app/features/location/LocationData.kt | 4 +-- .../app/features/location/LocationDataTest.kt | 33 ++++++++++--------- .../UserLiveLocationViewStateMapperTest.kt | 2 +- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/LocationInfo.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/LocationInfo.kt index a1fd3bd2ec..3c603962cb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/LocationInfo.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/LocationInfo.kt @@ -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;uncertainty' like 'geo:40.05,29.24;u=30' representing this location. */ @Json(name = "uri") val geoUri: String? = null, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageLocationContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageLocationContent.kt index 0a66a6e400..1275642b5f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageLocationContent.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageLocationContent.kt @@ -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;uncertainty' like 'geo:40.05,29.24;u=30' representing this location. */ @Json(name = "geo_uri") val geoUri: String, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt index bcaa257d78..f52500de1b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt @@ -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) } } diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/livelocation/LiveLocationAggregationProcessorTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/livelocation/LiveLocationAggregationProcessorTest.kt index e6d63f5e5e..933087af2b 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/livelocation/LiveLocationAggregationProcessorTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/livelocation/LiveLocationAggregationProcessorTest.kt @@ -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 { diff --git a/vector/src/main/java/im/vector/app/features/location/LocationData.kt b/vector/src/main/java/im/vector/app/features/location/LocationData.kt index b3466ff871..3c25a5b398 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationData.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationData.kt @@ -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? { diff --git a/vector/src/test/java/im/vector/app/features/location/LocationDataTest.kt b/vector/src/test/java/im/vector/app/features/location/LocationDataTest.kt index 6b97b715db..d3a1e79922 100644 --- a/vector/src/test/java/im/vector/app/features/location/LocationDataTest.kt +++ b/vector/src/test/java/im/vector/app/features/location/LocationDataTest.kt @@ -28,19 +28,22 @@ 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) // 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 +53,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 +80,7 @@ class LocationDataTest { @Test fun unstablePrefixTest() { - val geoUri = "geo :12.34,56.78;13.56" + val geoUri = "geo :12.34,56.78;u=13.56" val contentWithUnstablePrefixes = MessageLocationContent(body = "", geoUri = "", unstableLocationInfo = LocationInfo(geoUri = geoUri)) contentWithUnstablePrefixes.getBestLocationInfo()?.geoUri.shouldBeEqualTo(geoUri) diff --git a/vector/src/test/java/im/vector/app/features/location/live/map/UserLiveLocationViewStateMapperTest.kt b/vector/src/test/java/im/vector/app/features/location/live/map/UserLiveLocationViewStateMapperTest.kt index 95e0ff1b0b..46742da874 100644 --- a/vector/src/test/java/im/vector/app/features/location/live/map/UserLiveLocationViewStateMapperTest.kt +++ b/vector/src/test/java/im/vector/app/features/location/live/map/UserLiveLocationViewStateMapperTest.kt @@ -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 {