Skip to content

Commit f5d3bcb

Browse files
author
Maxime NATUREL
committed
Sending a reply to a live location share
1 parent 0a0eb08 commit f5d3bcb

File tree

8 files changed

+27
-9
lines changed

8 files changed

+27
-9
lines changed

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/location/LocationSharingService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ interface LocationSharingService {
4848
/**
4949
* Starts sharing live location in the room.
5050
* @param timeoutMillis timeout of the live in milliseconds
51+
* @param description description of the live for text fallback
5152
* @return the result of the update of the live
5253
*/
53-
suspend fun startLiveLocationShare(timeoutMillis: Long): UpdateLiveLocationShareResult
54+
suspend fun startLiveLocationShare(timeoutMillis: Long, description: String): UpdateLiveLocationShareResult
5455

5556
/**
5657
* Stops sharing live location in the room.

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/location/DefaultLocationSharingService.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ internal class DefaultLocationSharingService @AssistedInject constructor(
7272
return sendLiveLocationTask.execute(params)
7373
}
7474

75-
override suspend fun startLiveLocationShare(timeoutMillis: Long): UpdateLiveLocationShareResult {
75+
override suspend fun startLiveLocationShare(timeoutMillis: Long, description: String): UpdateLiveLocationShareResult {
7676
// Ensure to stop any active live before starting a new one
7777
if (checkIfExistingActiveLive()) {
7878
val result = stopLiveLocationShare()
@@ -82,7 +82,8 @@ internal class DefaultLocationSharingService @AssistedInject constructor(
8282
}
8383
val params = StartLiveLocationShareTask.Params(
8484
roomId = roomId,
85-
timeoutMillis = timeoutMillis
85+
timeoutMillis = timeoutMillis,
86+
description = description
8687
)
8788
return startLiveLocationShareTask.execute(params)
8889
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/location/StartLiveLocationShareTask.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internal interface StartLiveLocationShareTask : Task<StartLiveLocationShareTask.
3030
data class Params(
3131
val roomId: String,
3232
val timeoutMillis: Long,
33+
val description: String,
3334
)
3435
}
3536

@@ -41,6 +42,7 @@ internal class DefaultStartLiveLocationShareTask @Inject constructor(
4142

4243
override suspend fun execute(params: StartLiveLocationShareTask.Params): UpdateLiveLocationShareResult {
4344
val beaconContent = MessageBeaconInfoContent(
45+
body = params.description,
4446
timeout = params.timeoutMillis,
4547
isLive = true,
4648
unstableTimestampMillis = clock.epochMillis()

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import android.content.Context
2020
import android.graphics.Bitmap
2121
import android.media.MediaMetadataRetriever
2222
import androidx.exifinterface.media.ExifInterface
23+
import org.matrix.android.sdk.api.extensions.ensureNotEmpty
2324
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
2425
import org.matrix.android.sdk.api.session.events.model.Content
2526
import org.matrix.android.sdk.api.session.events.model.Event
@@ -700,6 +701,7 @@ internal class LocalEchoEventFactory @Inject constructor(
700701
MessageType.MSGTYPE_AUDIO -> return TextContent("sent an audio file.")
701702
MessageType.MSGTYPE_IMAGE -> return TextContent("sent an image.")
702703
MessageType.MSGTYPE_VIDEO -> return TextContent("sent a video.")
704+
MessageType.MSGTYPE_BEACON_INFO -> return TextContent(content.body.ensureNotEmpty() ?: "shared live location.")
703705
MessageType.MSGTYPE_POLL_START -> {
704706
return TextContent((content as? MessagePollContent)?.getBestPollCreationInfo()?.question?.getBestQuestion() ?: "")
705707
}

matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/location/DefaultLocationSharingServiceTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private const val A_LATITUDE = 1.4
5151
private const val A_LONGITUDE = 40.0
5252
private const val AN_UNCERTAINTY = 5.0
5353
private const val A_TIMEOUT = 15_000L
54+
private const val A_DESCRIPTION = "description"
5455

5556
@ExperimentalCoroutinesApi
5657
internal class DefaultLocationSharingServiceTest {
@@ -137,7 +138,7 @@ internal class DefaultLocationSharingServiceTest {
137138
coEvery { stopLiveLocationShareTask.execute(any()) } returns UpdateLiveLocationShareResult.Success("stopped-event-id")
138139
coEvery { startLiveLocationShareTask.execute(any()) } returns UpdateLiveLocationShareResult.Success(AN_EVENT_ID)
139140

140-
val result = defaultLocationSharingService.startLiveLocationShare(A_TIMEOUT)
141+
val result = defaultLocationSharingService.startLiveLocationShare(A_TIMEOUT, A_DESCRIPTION)
141142

142143
result shouldBeEqualTo UpdateLiveLocationShareResult.Success(AN_EVENT_ID)
143144
val expectedCheckExistingParams = CheckIfExistingActiveLiveTask.Params(
@@ -150,7 +151,8 @@ internal class DefaultLocationSharingServiceTest {
150151
coVerify { stopLiveLocationShareTask.execute(expectedStopParams) }
151152
val expectedStartParams = StartLiveLocationShareTask.Params(
152153
roomId = A_ROOM_ID,
153-
timeoutMillis = A_TIMEOUT
154+
timeoutMillis = A_TIMEOUT,
155+
description = A_DESCRIPTION
154156
)
155157
coVerify { startLiveLocationShareTask.execute(expectedStartParams) }
156158
}

matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/location/DefaultStartLiveLocationShareTaskTest.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import org.matrix.android.sdk.test.fakes.FakeSendStateTask
3434
private const val A_USER_ID = "user-id"
3535
private const val A_ROOM_ID = "room-id"
3636
private const val AN_EVENT_ID = "event-id"
37+
private const val A_DESCRIPTION = "description"
3738
private const val A_TIMEOUT = 15_000L
3839
private const val AN_EPOCH = 1655210176L
3940

@@ -58,7 +59,8 @@ internal class DefaultStartLiveLocationShareTaskTest {
5859
fun `given parameters and no error when calling the task then result is success`() = runTest {
5960
val params = StartLiveLocationShareTask.Params(
6061
roomId = A_ROOM_ID,
61-
timeoutMillis = A_TIMEOUT
62+
timeoutMillis = A_TIMEOUT,
63+
description = A_DESCRIPTION
6264
)
6365
fakeClock.givenEpoch(AN_EPOCH)
6466
fakeSendStateTask.givenExecuteRetryReturns(AN_EVENT_ID)
@@ -67,6 +69,7 @@ internal class DefaultStartLiveLocationShareTaskTest {
6769

6870
result shouldBeEqualTo UpdateLiveLocationShareResult.Success(AN_EVENT_ID)
6971
val expectedBeaconContent = MessageBeaconInfoContent(
72+
body = A_DESCRIPTION,
7073
timeout = params.timeoutMillis,
7174
isLive = true,
7275
unstableTimestampMillis = AN_EPOCH
@@ -87,7 +90,8 @@ internal class DefaultStartLiveLocationShareTaskTest {
8790
fun `given parameters and an empty returned event id when calling the task then result is failure`() = runTest {
8891
val params = StartLiveLocationShareTask.Params(
8992
roomId = A_ROOM_ID,
90-
timeoutMillis = A_TIMEOUT
93+
timeoutMillis = A_TIMEOUT,
94+
description = A_DESCRIPTION
9195
)
9296
fakeClock.givenEpoch(AN_EPOCH)
9397
fakeSendStateTask.givenExecuteRetryReturns("")
@@ -101,7 +105,8 @@ internal class DefaultStartLiveLocationShareTaskTest {
101105
fun `given parameters and error during event sending when calling the task then result is failure`() = runTest {
102106
val params = StartLiveLocationShareTask.Params(
103107
roomId = A_ROOM_ID,
104-
timeoutMillis = A_TIMEOUT
108+
timeoutMillis = A_TIMEOUT,
109+
description = A_DESCRIPTION
105110
)
106111
fakeClock.givenEpoch(AN_EPOCH)
107112
val error = Throwable()

vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ class TimelineFragment @Inject constructor(
12591259
val nonFormattedBody = when (messageContent) {
12601260
is MessageAudioContent -> getAudioContentBodyText(messageContent)
12611261
is MessagePollContent -> messageContent.getBestPollCreationInfo()?.question?.getBestQuestion()
1262+
is MessageBeaconInfoContent -> getString(R.string.sent_live_location)
12621263
else -> messageContent?.body.orEmpty()
12631264
}
12641265
var formattedBody: CharSequence? = null

vector/src/main/java/im/vector/app/features/location/LocationSharingService.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.os.Binder
2121
import android.os.IBinder
2222
import android.os.Parcelable
2323
import dagger.hilt.android.AndroidEntryPoint
24+
import im.vector.app.R
2425
import im.vector.app.core.di.ActiveSessionHolder
2526
import im.vector.app.core.services.VectorService
2627
import im.vector.app.features.location.live.GetLiveLocationShareSummaryUseCase
@@ -112,7 +113,10 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
112113
val updateLiveResult = session
113114
.getRoom(roomArgs.roomId)
114115
?.locationSharingService()
115-
?.startLiveLocationShare(timeoutMillis = roomArgs.durationMillis)
116+
?.startLiveLocationShare(
117+
timeoutMillis = roomArgs.durationMillis,
118+
description = getString(R.string.sent_live_location)
119+
)
116120

117121
updateLiveResult
118122
?.let { result ->

0 commit comments

Comments
 (0)