mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-02 12:16:55 +01:00
Code review fixes.
This commit is contained in:
parent
023a00d160
commit
f49e7d9619
@ -68,9 +68,16 @@ interface StateService {
|
||||
|
||||
/**
|
||||
* Stops sharing live location in the room
|
||||
* @param beaconInfoStateEvent Initial beacon info state event
|
||||
* @param userId user id
|
||||
*/
|
||||
suspend fun stopLiveLocation(beaconInfoStateEvent: Event)
|
||||
suspend fun stopLiveLocation(userId: String)
|
||||
|
||||
/**
|
||||
* Returns beacon info state event of a user
|
||||
* @param userId user id who is sharing location
|
||||
* @param filterOnlyLive filters only ongoing live location sharing beacons if true else ended event is included
|
||||
*/
|
||||
suspend fun getLiveLocationBeaconInfo(userId: String, filterOnlyLive: Boolean): Event?
|
||||
|
||||
/**
|
||||
* Send a state event to the room
|
||||
|
@ -21,6 +21,7 @@ import androidx.lifecycle.LiveData
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
@ -190,24 +191,41 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
|
||||
updateJoinRule(RoomJoinRules.RESTRICTED, null, allowEntries)
|
||||
}
|
||||
|
||||
override suspend fun stopLiveLocation(beaconInfoStateEvent: Event) {
|
||||
beaconInfoStateEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.let { content ->
|
||||
val beaconContent = LiveLocationBeaconContent(
|
||||
unstableBeaconInfo = BeaconInfo(
|
||||
description = content.getBestBeaconInfo()?.description,
|
||||
timeout = content.getBestBeaconInfo()?.timeout,
|
||||
isLive = false,
|
||||
),
|
||||
unstableTimestampAsMilliseconds = System.currentTimeMillis()
|
||||
).toContent()
|
||||
override suspend fun stopLiveLocation(userId: String) {
|
||||
getLiveLocationBeaconInfo(userId, true)?.let { beaconInfoStateEvent ->
|
||||
beaconInfoStateEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.let { content ->
|
||||
val beaconContent = LiveLocationBeaconContent(
|
||||
unstableBeaconInfo = BeaconInfo(
|
||||
description = content.getBestBeaconInfo()?.description,
|
||||
timeout = content.getBestBeaconInfo()?.timeout,
|
||||
isLive = false,
|
||||
),
|
||||
unstableTimestampAsMilliseconds = System.currentTimeMillis()
|
||||
).toContent()
|
||||
|
||||
beaconInfoStateEvent.stateKey?.let {
|
||||
sendStateEvent(
|
||||
eventType = EventType.STATE_ROOM_BEACON_INFO.first(),
|
||||
body = beaconContent,
|
||||
stateKey = it
|
||||
)
|
||||
beaconInfoStateEvent.stateKey?.let {
|
||||
sendStateEvent(
|
||||
eventType = EventType.STATE_ROOM_BEACON_INFO.first(),
|
||||
body = beaconContent,
|
||||
stateKey = it
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getLiveLocationBeaconInfo(userId: String, filterOnlyLive: Boolean): Event? {
|
||||
return EventType.STATE_ROOM_BEACON_INFO
|
||||
.mapNotNull {
|
||||
stateEventDataSource.getStateEvent(
|
||||
roomId = roomId,
|
||||
eventType = it,
|
||||
stateKey = QueryStringValue.Equals(userId)
|
||||
)
|
||||
}
|
||||
.firstOrNull { beaconInfoEvent ->
|
||||
!filterOnlyLive ||
|
||||
beaconInfoEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.getBestBeaconInfo()?.isLive.orFalse()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ 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
|
||||
@ -88,7 +87,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
||||
.getSafeActiveSession()
|
||||
?.let { session ->
|
||||
session.coroutineScope.launch(session.coroutineDispatchers.io) {
|
||||
sendBeaconInfo(session, roomArgs)
|
||||
sendLiveBeaconInfo(session, roomArgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -96,7 +95,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
private suspend fun sendBeaconInfo(session: Session, roomArgs: RoomArgs) {
|
||||
private suspend fun sendLiveBeaconInfo(session: Session, roomArgs: RoomArgs) {
|
||||
val beaconContent = LiveLocationBeaconContent(
|
||||
unstableBeaconInfo = BeaconInfo(
|
||||
timeout = roomArgs.durationMillis,
|
||||
@ -134,7 +133,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
||||
Timber.i("### LocationSharingService.stopSharingLocation for $roomId")
|
||||
|
||||
// Send a new beacon info state by setting live field as false
|
||||
updateStoppedBeaconInfo(roomId)
|
||||
sendStoppedBeaconInfo(roomId)
|
||||
|
||||
synchronized(roomArgsList) {
|
||||
roomArgsList.removeAll { it.roomId == roomId }
|
||||
@ -145,21 +144,12 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateStoppedBeaconInfo(roomId: String) {
|
||||
private fun sendStoppedBeaconInfo(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)
|
||||
}
|
||||
session.getRoom(roomId)?.stopLiveLocation(session.myUserId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,16 +157,26 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
||||
override fun onLocationUpdate(locationData: LocationData) {
|
||||
Timber.i("### LocationSharingService.onLocationUpdate. Uncertainty: ${locationData.uncertainty}")
|
||||
|
||||
val session = activeSessionHolder.getSafeActiveSession()
|
||||
// Emit location update to all rooms in which live location sharing is active
|
||||
roomArgsList.toList().forEach { roomArg ->
|
||||
sendLiveLocation(roomArg.roomId, locationData)
|
||||
session?.coroutineScope?.launch(session.coroutineDispatchers.io) {
|
||||
roomArgsList.toList().forEach { roomArg ->
|
||||
sendLiveLocation(roomArg.roomId, locationData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendLiveLocation(roomId: String, locationData: LocationData) {
|
||||
val room = activeSessionHolder.getSafeActiveSession()?.getRoom(roomId)
|
||||
private suspend fun sendLiveLocation(roomId: String, locationData: LocationData) {
|
||||
val session = activeSessionHolder.getSafeActiveSession()
|
||||
val room = session?.getRoom(roomId)
|
||||
val userId = session?.myUserId
|
||||
|
||||
if (room == null || userId == null) {
|
||||
return
|
||||
}
|
||||
|
||||
room
|
||||
?.getStateEvent(EventType.STATE_ROOM_BEACON_INFO.first())
|
||||
.getLiveLocationBeaconInfo(userId, true)
|
||||
?.eventId
|
||||
?.let {
|
||||
room.sendLiveLocation(
|
||||
|
@ -64,6 +64,7 @@ class LocationSharingServiceConnection @Inject constructor(
|
||||
|
||||
override fun onServiceDisconnected(className: ComponentName) {
|
||||
isBound = false
|
||||
locationSharingService = null
|
||||
callback?.onLocationServiceStopped()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user