From 137d5e40936cd34654b61ffd2f2a6698bf959b4f Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Wed, 13 Apr 2022 20:10:24 +0300 Subject: [PATCH] Set live as false when live location sharing is times up. --- .../home/room/detail/TimelineViewModel.kt | 15 +----------- .../location/LocationSharingService.kt | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt index a07afaa74b..76c6ecc86d 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt @@ -1095,20 +1095,7 @@ class TimelineViewModel @AssistedInject constructor( } private fun handleStopLiveLocationSharing() { - viewModelScope.launch { - EventType - .STATE_ROOM_BEACON_INFO - .mapNotNull { - room.getStateEvent(it, QueryStringValue.Equals(session.myUserId)) - } - .firstOrNull() - ?.let { beaconInfoEvent -> - room.stopLiveLocation(beaconInfoEvent) - } - ?.also { - locationSharingServiceConnection.stopLiveLocationSharing(room.roomId) - } - } + locationSharingServiceConnection.stopLiveLocationSharing(room.roomId) } private fun observeRoomSummary() { diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingService.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingService.kt index 3256844bba..f215a82c71 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingService.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingService.kt @@ -28,6 +28,7 @@ import im.vector.app.features.notifications.NotificationUtils import im.vector.app.features.session.coroutineScope import kotlinx.coroutines.launch import kotlinx.parcelize.Parcelize +import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toContent @@ -131,6 +132,10 @@ class LocationSharingService : VectorService(), LocationTracker.Callback { fun stopSharingLocation(roomId: String) { Timber.i("### LocationSharingService.stopSharingLocation for $roomId") + + // Send a new beacon info state by setting live field as false + updateStoppedBeaconInfo(roomId) + synchronized(roomArgsList) { roomArgsList.removeAll { it.roomId == roomId } if (roomArgsList.isEmpty()) { @@ -140,6 +145,25 @@ class LocationSharingService : VectorService(), LocationTracker.Callback { } } + private fun updateStoppedBeaconInfo(roomId: String) { + activeSessionHolder + .getSafeActiveSession() + ?.let { session -> + session.coroutineScope.launch(session.coroutineDispatchers.io) { + val room = session.getRoom(roomId) + EventType + .STATE_ROOM_BEACON_INFO + .mapNotNull { + room?.getStateEvent(it, QueryStringValue.Equals(session.myUserId)) + } + .firstOrNull() + ?.let { beaconInfoEvent -> + room?.stopLiveLocation(beaconInfoEvent) + } + } + } + } + override fun onLocationUpdate(locationData: LocationData) { Timber.i("### LocationSharingService.onLocationUpdate. Uncertainty: ${locationData.uncertainty}")