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) {
|
||||
Timber.i("### LocationSharingService.onLocationUpdate. Uncertainty: ${locationData.uncertainty}")
|
||||
|
||||
// Emit location update to all rooms in which live location sharing is active
|
||||
roomArgsList.forEach { roomArg ->
|
||||
val room = activeSessionHolder.getSafeActiveSession()?.getRoom(roomArg.roomId)
|
||||
room?.getStateEvent(EventType.STATE_ROOM_BEACON_INFO.first())?.let { beaconInfoEvent ->
|
||||
room.sendLiveLocation(
|
||||
beaconInfoEventId = beaconInfoEvent.eventId!!,
|
||||
latitude = locationData.latitude,
|
||||
longitude = locationData.longitude,
|
||||
uncertainty = locationData.uncertainty
|
||||
)
|
||||
}
|
||||
sendLiveLocation(roomArg.roomId, locationData)
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
stopForeground(true)
|
||||
stopSelf()
|
||||
|
Loading…
x
Reference in New Issue
Block a user