@@ -28,7 +28,6 @@ import im.vector.app.features.notifications.NotificationUtils
28
28
import im.vector.app.features.session.coroutineScope
29
29
import kotlinx.coroutines.launch
30
30
import kotlinx.parcelize.Parcelize
31
- import org.matrix.android.sdk.api.query.QueryStringValue
32
31
import org.matrix.android.sdk.api.session.Session
33
32
import org.matrix.android.sdk.api.session.events.model.EventType
34
33
import org.matrix.android.sdk.api.session.events.model.toContent
@@ -88,15 +87,15 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
88
87
.getSafeActiveSession()
89
88
?.let { session ->
90
89
session.coroutineScope.launch(session.coroutineDispatchers.io) {
91
- sendBeaconInfo (session, roomArgs)
90
+ sendLiveBeaconInfo (session, roomArgs)
92
91
}
93
92
}
94
93
}
95
94
96
95
return START_STICKY
97
96
}
98
97
99
- private suspend fun sendBeaconInfo (session : Session , roomArgs : RoomArgs ) {
98
+ private suspend fun sendLiveBeaconInfo (session : Session , roomArgs : RoomArgs ) {
100
99
val beaconContent = LiveLocationBeaconContent (
101
100
unstableBeaconInfo = BeaconInfo (
102
101
timeout = roomArgs.durationMillis,
@@ -134,7 +133,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
134
133
Timber .i(" ### LocationSharingService.stopSharingLocation for $roomId " )
135
134
136
135
// Send a new beacon info state by setting live field as false
137
- updateStoppedBeaconInfo (roomId)
136
+ sendStoppedBeaconInfo (roomId)
138
137
139
138
synchronized(roomArgsList) {
140
139
roomArgsList.removeAll { it.roomId == roomId }
@@ -145,38 +144,39 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
145
144
}
146
145
}
147
146
148
- private fun updateStoppedBeaconInfo (roomId : String ) {
147
+ private fun sendStoppedBeaconInfo (roomId : String ) {
149
148
activeSessionHolder
150
149
.getSafeActiveSession()
151
150
?.let { session ->
152
151
session.coroutineScope.launch(session.coroutineDispatchers.io) {
153
- val room = session.getRoom(roomId)
154
- EventType
155
- .STATE_ROOM_BEACON_INFO
156
- .mapNotNull {
157
- room?.getStateEvent(it, QueryStringValue .Equals (session.myUserId))
158
- }
159
- .firstOrNull()
160
- ?.let { beaconInfoEvent ->
161
- room?.stopLiveLocation(beaconInfoEvent)
162
- }
152
+ session.getRoom(roomId)?.stopLiveLocation(session.myUserId)
163
153
}
164
154
}
165
155
}
166
156
167
157
override fun onLocationUpdate (locationData : LocationData ) {
168
158
Timber .i(" ### LocationSharingService.onLocationUpdate. Uncertainty: ${locationData.uncertainty} " )
169
159
160
+ val session = activeSessionHolder.getSafeActiveSession()
170
161
// Emit location update to all rooms in which live location sharing is active
171
- roomArgsList.toList().forEach { roomArg ->
172
- sendLiveLocation(roomArg.roomId, locationData)
162
+ session?.coroutineScope?.launch(session.coroutineDispatchers.io) {
163
+ roomArgsList.toList().forEach { roomArg ->
164
+ sendLiveLocation(roomArg.roomId, locationData)
165
+ }
173
166
}
174
167
}
175
168
176
- private fun sendLiveLocation (roomId : String , locationData : LocationData ) {
177
- val room = activeSessionHolder.getSafeActiveSession()?.getRoom(roomId)
169
+ private suspend fun sendLiveLocation (roomId : String , locationData : LocationData ) {
170
+ val session = activeSessionHolder.getSafeActiveSession()
171
+ val room = session?.getRoom(roomId)
172
+ val userId = session?.myUserId
173
+
174
+ if (room == null || userId == null ) {
175
+ return
176
+ }
177
+
178
178
room
179
- ?.getStateEvent( EventType . STATE_ROOM_BEACON_INFO .first() )
179
+ .getLiveLocationBeaconInfo(userId, true )
180
180
?.eventId
181
181
?.let {
182
182
room.sendLiveLocation(
0 commit comments