Change context inside the get live summary use case

This commit is contained in:
Maxime NATUREL 2022-06-28 14:15:41 +02:00
parent 8476fba5ff
commit 70996655e1
2 changed files with 11 additions and 14 deletions

View File

@ -192,9 +192,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
}
private fun listenForLiveSummaryChanges(roomId: String, eventId: String) {
activeSessionHolder
.getSafeActiveSession()
?.let { session ->
launchWithActiveSession { session ->
val job = getLiveLocationShareSummaryUseCase.execute(roomId, eventId)
.distinctUntilChangedBy { it.isActive }
.filter { it.isActive == false }

View File

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