Refactor code to avoid force unwrapping.
This commit is contained in:
parent
db45ebd012
commit
dbb43fe046
@ -142,19 +142,28 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
|||||||
|
|
||||||
override fun onLocationUpdate(locationData: LocationData) {
|
override fun onLocationUpdate(locationData: LocationData) {
|
||||||
Timber.i("### LocationSharingService.onLocationUpdate. Uncertainty: ${locationData.uncertainty}")
|
Timber.i("### LocationSharingService.onLocationUpdate. Uncertainty: ${locationData.uncertainty}")
|
||||||
|
|
||||||
|
// Emit location update to all rooms in which live location sharing is active
|
||||||
roomArgsList.forEach { roomArg ->
|
roomArgsList.forEach { roomArg ->
|
||||||
val room = activeSessionHolder.getSafeActiveSession()?.getRoom(roomArg.roomId)
|
sendLiveLocation(roomArg.roomId, locationData)
|
||||||
room?.getStateEvent(EventType.STATE_ROOM_BEACON_INFO.first())?.let { beaconInfoEvent ->
|
|
||||||
room.sendLiveLocation(
|
|
||||||
beaconInfoEventId = beaconInfoEvent.eventId!!,
|
|
||||||
latitude = locationData.latitude,
|
|
||||||
longitude = locationData.longitude,
|
|
||||||
uncertainty = locationData.uncertainty
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun sendLiveLocation(roomId: String, locationData: LocationData) {
|
||||||
|
val room = activeSessionHolder.getSafeActiveSession()?.getRoom(roomId)
|
||||||
|
room
|
||||||
|
?.getStateEvent(EventType.STATE_ROOM_BEACON_INFO.first())
|
||||||
|
?.eventId
|
||||||
|
?.let {
|
||||||
|
room.sendLiveLocation(
|
||||||
|
beaconInfoEventId = it,
|
||||||
|
latitude = locationData.latitude,
|
||||||
|
longitude = locationData.longitude,
|
||||||
|
uncertainty = locationData.uncertainty
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onLocationProviderIsNotAvailable() {
|
override fun onLocationProviderIsNotAvailable() {
|
||||||
stopForeground(true)
|
stopForeground(true)
|
||||||
stopSelf()
|
stopSelf()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user