Sending a reply to a live location share

This commit is contained in:
Maxime NATUREL 2022-06-28 17:32:39 +02:00
parent 0a0eb08de9
commit f5d3bcbb94
8 changed files with 27 additions and 9 deletions

View File

@ -48,9 +48,10 @@ interface LocationSharingService {
/** /**
* Starts sharing live location in the room. * Starts sharing live location in the room.
* @param timeoutMillis timeout of the live in milliseconds * @param timeoutMillis timeout of the live in milliseconds
* @param description description of the live for text fallback
* @return the result of the update of the live * @return the result of the update of the live
*/ */
suspend fun startLiveLocationShare(timeoutMillis: Long): UpdateLiveLocationShareResult suspend fun startLiveLocationShare(timeoutMillis: Long, description: String): UpdateLiveLocationShareResult
/** /**
* Stops sharing live location in the room. * Stops sharing live location in the room.

View File

@ -72,7 +72,7 @@ internal class DefaultLocationSharingService @AssistedInject constructor(
return sendLiveLocationTask.execute(params) return sendLiveLocationTask.execute(params)
} }
override suspend fun startLiveLocationShare(timeoutMillis: Long): UpdateLiveLocationShareResult { override suspend fun startLiveLocationShare(timeoutMillis: Long, description: String): UpdateLiveLocationShareResult {
// Ensure to stop any active live before starting a new one // Ensure to stop any active live before starting a new one
if (checkIfExistingActiveLive()) { if (checkIfExistingActiveLive()) {
val result = stopLiveLocationShare() val result = stopLiveLocationShare()
@ -82,7 +82,8 @@ internal class DefaultLocationSharingService @AssistedInject constructor(
} }
val params = StartLiveLocationShareTask.Params( val params = StartLiveLocationShareTask.Params(
roomId = roomId, roomId = roomId,
timeoutMillis = timeoutMillis timeoutMillis = timeoutMillis,
description = description
) )
return startLiveLocationShareTask.execute(params) return startLiveLocationShareTask.execute(params)
} }

View File

@ -30,6 +30,7 @@ internal interface StartLiveLocationShareTask : Task<StartLiveLocationShareTask.
data class Params( data class Params(
val roomId: String, val roomId: String,
val timeoutMillis: Long, val timeoutMillis: Long,
val description: String,
) )
} }
@ -41,6 +42,7 @@ internal class DefaultStartLiveLocationShareTask @Inject constructor(
override suspend fun execute(params: StartLiveLocationShareTask.Params): UpdateLiveLocationShareResult { override suspend fun execute(params: StartLiveLocationShareTask.Params): UpdateLiveLocationShareResult {
val beaconContent = MessageBeaconInfoContent( val beaconContent = MessageBeaconInfoContent(
body = params.description,
timeout = params.timeoutMillis, timeout = params.timeoutMillis,
isLive = true, isLive = true,
unstableTimestampMillis = clock.epochMillis() unstableTimestampMillis = clock.epochMillis()

View File

@ -20,6 +20,7 @@ import android.content.Context
import android.graphics.Bitmap import android.graphics.Bitmap
import android.media.MediaMetadataRetriever import android.media.MediaMetadataRetriever
import androidx.exifinterface.media.ExifInterface import androidx.exifinterface.media.ExifInterface
import org.matrix.android.sdk.api.extensions.ensureNotEmpty
import org.matrix.android.sdk.api.session.content.ContentAttachmentData import org.matrix.android.sdk.api.session.content.ContentAttachmentData
import org.matrix.android.sdk.api.session.events.model.Content import org.matrix.android.sdk.api.session.events.model.Content
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
@ -700,6 +701,7 @@ internal class LocalEchoEventFactory @Inject constructor(
MessageType.MSGTYPE_AUDIO -> return TextContent("sent an audio file.") MessageType.MSGTYPE_AUDIO -> return TextContent("sent an audio file.")
MessageType.MSGTYPE_IMAGE -> return TextContent("sent an image.") MessageType.MSGTYPE_IMAGE -> return TextContent("sent an image.")
MessageType.MSGTYPE_VIDEO -> return TextContent("sent a video.") MessageType.MSGTYPE_VIDEO -> return TextContent("sent a video.")
MessageType.MSGTYPE_BEACON_INFO -> return TextContent(content.body.ensureNotEmpty() ?: "shared live location.")
MessageType.MSGTYPE_POLL_START -> { MessageType.MSGTYPE_POLL_START -> {
return TextContent((content as? MessagePollContent)?.getBestPollCreationInfo()?.question?.getBestQuestion() ?: "") return TextContent((content as? MessagePollContent)?.getBestPollCreationInfo()?.question?.getBestQuestion() ?: "")
} }

View File

@ -51,6 +51,7 @@ private const val A_LATITUDE = 1.4
private const val A_LONGITUDE = 40.0 private const val A_LONGITUDE = 40.0
private const val AN_UNCERTAINTY = 5.0 private const val AN_UNCERTAINTY = 5.0
private const val A_TIMEOUT = 15_000L private const val A_TIMEOUT = 15_000L
private const val A_DESCRIPTION = "description"
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
internal class DefaultLocationSharingServiceTest { internal class DefaultLocationSharingServiceTest {
@ -137,7 +138,7 @@ internal class DefaultLocationSharingServiceTest {
coEvery { stopLiveLocationShareTask.execute(any()) } returns UpdateLiveLocationShareResult.Success("stopped-event-id") coEvery { stopLiveLocationShareTask.execute(any()) } returns UpdateLiveLocationShareResult.Success("stopped-event-id")
coEvery { startLiveLocationShareTask.execute(any()) } returns UpdateLiveLocationShareResult.Success(AN_EVENT_ID) coEvery { startLiveLocationShareTask.execute(any()) } returns UpdateLiveLocationShareResult.Success(AN_EVENT_ID)
val result = defaultLocationSharingService.startLiveLocationShare(A_TIMEOUT) val result = defaultLocationSharingService.startLiveLocationShare(A_TIMEOUT, A_DESCRIPTION)
result shouldBeEqualTo UpdateLiveLocationShareResult.Success(AN_EVENT_ID) result shouldBeEqualTo UpdateLiveLocationShareResult.Success(AN_EVENT_ID)
val expectedCheckExistingParams = CheckIfExistingActiveLiveTask.Params( val expectedCheckExistingParams = CheckIfExistingActiveLiveTask.Params(
@ -150,7 +151,8 @@ internal class DefaultLocationSharingServiceTest {
coVerify { stopLiveLocationShareTask.execute(expectedStopParams) } coVerify { stopLiveLocationShareTask.execute(expectedStopParams) }
val expectedStartParams = StartLiveLocationShareTask.Params( val expectedStartParams = StartLiveLocationShareTask.Params(
roomId = A_ROOM_ID, roomId = A_ROOM_ID,
timeoutMillis = A_TIMEOUT timeoutMillis = A_TIMEOUT,
description = A_DESCRIPTION
) )
coVerify { startLiveLocationShareTask.execute(expectedStartParams) } coVerify { startLiveLocationShareTask.execute(expectedStartParams) }
} }

View File

@ -34,6 +34,7 @@ import org.matrix.android.sdk.test.fakes.FakeSendStateTask
private const val A_USER_ID = "user-id" private const val A_USER_ID = "user-id"
private const val A_ROOM_ID = "room-id" private const val A_ROOM_ID = "room-id"
private const val AN_EVENT_ID = "event-id" private const val AN_EVENT_ID = "event-id"
private const val A_DESCRIPTION = "description"
private const val A_TIMEOUT = 15_000L private const val A_TIMEOUT = 15_000L
private const val AN_EPOCH = 1655210176L private const val AN_EPOCH = 1655210176L
@ -58,7 +59,8 @@ internal class DefaultStartLiveLocationShareTaskTest {
fun `given parameters and no error when calling the task then result is success`() = runTest { fun `given parameters and no error when calling the task then result is success`() = runTest {
val params = StartLiveLocationShareTask.Params( val params = StartLiveLocationShareTask.Params(
roomId = A_ROOM_ID, roomId = A_ROOM_ID,
timeoutMillis = A_TIMEOUT timeoutMillis = A_TIMEOUT,
description = A_DESCRIPTION
) )
fakeClock.givenEpoch(AN_EPOCH) fakeClock.givenEpoch(AN_EPOCH)
fakeSendStateTask.givenExecuteRetryReturns(AN_EVENT_ID) fakeSendStateTask.givenExecuteRetryReturns(AN_EVENT_ID)
@ -67,6 +69,7 @@ internal class DefaultStartLiveLocationShareTaskTest {
result shouldBeEqualTo UpdateLiveLocationShareResult.Success(AN_EVENT_ID) result shouldBeEqualTo UpdateLiveLocationShareResult.Success(AN_EVENT_ID)
val expectedBeaconContent = MessageBeaconInfoContent( val expectedBeaconContent = MessageBeaconInfoContent(
body = A_DESCRIPTION,
timeout = params.timeoutMillis, timeout = params.timeoutMillis,
isLive = true, isLive = true,
unstableTimestampMillis = AN_EPOCH unstableTimestampMillis = AN_EPOCH
@ -87,7 +90,8 @@ internal class DefaultStartLiveLocationShareTaskTest {
fun `given parameters and an empty returned event id when calling the task then result is failure`() = runTest { fun `given parameters and an empty returned event id when calling the task then result is failure`() = runTest {
val params = StartLiveLocationShareTask.Params( val params = StartLiveLocationShareTask.Params(
roomId = A_ROOM_ID, roomId = A_ROOM_ID,
timeoutMillis = A_TIMEOUT timeoutMillis = A_TIMEOUT,
description = A_DESCRIPTION
) )
fakeClock.givenEpoch(AN_EPOCH) fakeClock.givenEpoch(AN_EPOCH)
fakeSendStateTask.givenExecuteRetryReturns("") fakeSendStateTask.givenExecuteRetryReturns("")
@ -101,7 +105,8 @@ internal class DefaultStartLiveLocationShareTaskTest {
fun `given parameters and error during event sending when calling the task then result is failure`() = runTest { fun `given parameters and error during event sending when calling the task then result is failure`() = runTest {
val params = StartLiveLocationShareTask.Params( val params = StartLiveLocationShareTask.Params(
roomId = A_ROOM_ID, roomId = A_ROOM_ID,
timeoutMillis = A_TIMEOUT timeoutMillis = A_TIMEOUT,
description = A_DESCRIPTION
) )
fakeClock.givenEpoch(AN_EPOCH) fakeClock.givenEpoch(AN_EPOCH)
val error = Throwable() val error = Throwable()

View File

@ -1259,6 +1259,7 @@ class TimelineFragment @Inject constructor(
val nonFormattedBody = when (messageContent) { val nonFormattedBody = when (messageContent) {
is MessageAudioContent -> getAudioContentBodyText(messageContent) is MessageAudioContent -> getAudioContentBodyText(messageContent)
is MessagePollContent -> messageContent.getBestPollCreationInfo()?.question?.getBestQuestion() is MessagePollContent -> messageContent.getBestPollCreationInfo()?.question?.getBestQuestion()
is MessageBeaconInfoContent -> getString(R.string.sent_live_location)
else -> messageContent?.body.orEmpty() else -> messageContent?.body.orEmpty()
} }
var formattedBody: CharSequence? = null var formattedBody: CharSequence? = null

View File

@ -21,6 +21,7 @@ import android.os.Binder
import android.os.IBinder import android.os.IBinder
import android.os.Parcelable import android.os.Parcelable
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.services.VectorService import im.vector.app.core.services.VectorService
import im.vector.app.features.location.live.GetLiveLocationShareSummaryUseCase import im.vector.app.features.location.live.GetLiveLocationShareSummaryUseCase
@ -112,7 +113,10 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
val updateLiveResult = session val updateLiveResult = session
.getRoom(roomArgs.roomId) .getRoom(roomArgs.roomId)
?.locationSharingService() ?.locationSharingService()
?.startLiveLocationShare(timeoutMillis = roomArgs.durationMillis) ?.startLiveLocationShare(
timeoutMillis = roomArgs.durationMillis,
description = getString(R.string.sent_live_location)
)
updateLiveResult updateLiveResult
?.let { result -> ?.let { result ->