mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 11:26:01 +03:00
Change context inside the get live summary use case
This commit is contained in:
parent
8476fba5ff
commit
70996655e1
2 changed files with 11 additions and 14 deletions
|
@ -192,16 +192,14 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
|||
}
|
||||
|
||||
private fun listenForLiveSummaryChanges(roomId: String, eventId: String) {
|
||||
activeSessionHolder
|
||||
.getSafeActiveSession()
|
||||
?.let { session ->
|
||||
val job = getLiveLocationShareSummaryUseCase.execute(roomId, eventId)
|
||||
.distinctUntilChangedBy { it.isActive }
|
||||
.filter { it.isActive == false }
|
||||
.onEach { stopSharingLocation(roomId) }
|
||||
.launchIn(session.coroutineScope)
|
||||
jobs.add(job)
|
||||
}
|
||||
launchWithActiveSession { session ->
|
||||
val job = getLiveLocationShareSummaryUseCase.execute(roomId, eventId)
|
||||
.distinctUntilChangedBy { it.isActive }
|
||||
.filter { it.isActive == false }
|
||||
.onEach { stopSharingLocation(roomId) }
|
||||
.launchIn(session.coroutineScope)
|
||||
jobs.add(job)
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchWithActiveSession(block: suspend CoroutineScope.(Session) -> Unit) =
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
package im.vector.app.features.location.live
|
||||
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.lifecycle.asFlow
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import kotlinx.coroutines.flow.mapNotNull
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.getRoom
|
||||
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationShareAggregatedSummary
|
||||
|
@ -31,10 +31,9 @@ class GetLiveLocationShareSummaryUseCase @Inject constructor(
|
|||
private val session: Session,
|
||||
) {
|
||||
|
||||
@MainThread
|
||||
fun execute(roomId: String, eventId: String): Flow<LiveLocationShareAggregatedSummary> {
|
||||
suspend fun execute(roomId: String, eventId: String): Flow<LiveLocationShareAggregatedSummary> = withContext(session.coroutineDispatchers.main) {
|
||||
Timber.d("getting flow for roomId=$roomId and eventId=$eventId")
|
||||
return session.getRoom(roomId)
|
||||
session.getRoom(roomId)
|
||||
?.locationSharingService()
|
||||
?.getLiveLocationShareSummary(eventId)
|
||||
?.asFlow()
|
||||
|
|
Loading…
Reference in a new issue