Set live as false when live location sharing is times up.

This commit is contained in:
Onuray Sahin 2022-04-13 20:10:24 +03:00
parent 33e735cbdd
commit 137d5e4093
2 changed files with 25 additions and 14 deletions

View File

@ -1095,21 +1095,8 @@ class TimelineViewModel @AssistedInject constructor(
} }
private fun handleStopLiveLocationSharing() { 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() { private fun observeRoomSummary() {
room.flow().liveRoomSummary() room.flow().liveRoomSummary()

View File

@ -28,6 +28,7 @@ import im.vector.app.features.notifications.NotificationUtils
import im.vector.app.features.session.coroutineScope import im.vector.app.features.session.coroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.parcelize.Parcelize 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.Session
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toContent
@ -131,6 +132,10 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
fun stopSharingLocation(roomId: String) { fun stopSharingLocation(roomId: String) {
Timber.i("### LocationSharingService.stopSharingLocation for $roomId") Timber.i("### LocationSharingService.stopSharingLocation for $roomId")
// Send a new beacon info state by setting live field as false
updateStoppedBeaconInfo(roomId)
synchronized(roomArgsList) { synchronized(roomArgsList) {
roomArgsList.removeAll { it.roomId == roomId } roomArgsList.removeAll { it.roomId == roomId }
if (roomArgsList.isEmpty()) { 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) { override fun onLocationUpdate(locationData: LocationData) {
Timber.i("### LocationSharingService.onLocationUpdate. Uncertainty: ${locationData.uncertainty}") Timber.i("### LocationSharingService.onLocationUpdate. Uncertainty: ${locationData.uncertainty}")