Refactor code to avoid force unwrapping.

This commit is contained in:
Onuray Sahin 2022-04-05 15:42:01 +03:00
parent db45ebd012
commit dbb43fe046
1 changed files with 18 additions and 9 deletions

View File

@ -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()