@@ -21,14 +21,19 @@ import android.content.Context
2121import android.content.Intent
2222import android.content.ServiceConnection
2323import android.os.IBinder
24+ import im.vector.app.core.di.ActiveSessionHolder
25+ import im.vector.app.features.session.coroutineScope
26+ import kotlinx.coroutines.CoroutineScope
27+ import kotlinx.coroutines.flow.launchIn
28+ import kotlinx.coroutines.flow.onEach
2429import javax.inject.Inject
2530import javax.inject.Singleton
2631
2732@Singleton
2833class LocationSharingServiceConnection @Inject constructor(
29- private val context : Context
30- ) : ServiceConnection,
31- LocationSharingAndroidService .Callback {
34+ private val context : Context ,
35+ private val activeSessionHolder : ActiveSessionHolder
36+ ) : ServiceConnection, LocationSharingAndroidService.Callback {
3237
3338 interface Callback {
3439 fun onLocationServiceRunning (roomIds : Set <String >)
@@ -61,20 +66,29 @@ class LocationSharingServiceConnection @Inject constructor(
6166 }
6267
6368 override fun onServiceConnected (className : ComponentName , binder : IBinder ) {
64- locationSharingAndroidService = (binder as LocationSharingAndroidService .LocalBinder ).getService().also {
65- it.callback = this
69+ locationSharingAndroidService = (binder as LocationSharingAndroidService .LocalBinder ).getService().also { service ->
70+ service.callback = this
71+ getActiveSessionCoroutineScope()?.let { scope ->
72+ service.roomIdsOfActiveLives
73+ .onEach(::onRoomIdsUpdate)
74+ .launchIn(scope)
75+ }
6676 }
6777 isBound = true
6878 }
6979
80+ private fun getActiveSessionCoroutineScope (): CoroutineScope ? {
81+ return activeSessionHolder.getSafeActiveSession()?.coroutineScope
82+ }
83+
7084 override fun onServiceDisconnected (className : ComponentName ) {
7185 isBound = false
7286 locationSharingAndroidService?.callback = null
7387 locationSharingAndroidService = null
7488 onCallbackActionNoArg(Callback ::onLocationServiceStopped)
7589 }
7690
77- override fun onRoomIdsUpdate (roomIds : Set <String >) {
91+ private fun onRoomIdsUpdate (roomIds : Set <String >) {
7892 forwardRoomIdsToCallbacks(roomIds)
7993 }
8094
0 commit comments