Skip to content

Commit

Permalink
Inline subscribeToSurveyUpdates in MakeSurveyAvailableOfflineUseCase
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 committed Jan 19, 2025
1 parent 9d2c164 commit 10b297a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.google.android.ground.domain.usecases.survey

import com.google.android.ground.model.Survey
import com.google.android.ground.repository.SurveyRepository
import com.google.android.ground.persistence.remote.RemoteDataStore
import javax.inject.Inject

/**
Expand All @@ -28,9 +28,9 @@ import javax.inject.Inject
class MakeSurveyAvailableOfflineUseCase
@Inject
constructor(
private val surveyRepository: SurveyRepository,
private val remoteDataStore: RemoteDataStore,
private val syncSurvey: SyncSurveyUseCase,
) {
suspend operator fun invoke(surveyId: String): Survey? =
syncSurvey(surveyId)?.also { surveyRepository.subscribeToSurveyUpdates(surveyId) }
syncSurvey(surveyId)?.also { remoteDataStore.subscribeToSurveyUpdates(surveyId) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import com.google.android.ground.persistence.local.stores.LocalSurveyStore
import com.google.android.ground.persistence.remote.RemoteDataStore
import com.google.android.ground.system.NetworkManager
import com.google.android.ground.system.NetworkStatus
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
Expand All @@ -43,6 +41,8 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import javax.inject.Inject
import javax.inject.Singleton

private const val LOAD_REMOTE_SURVEY_TIMEOUT_MILLS: Long = 15 * 1000

Expand Down Expand Up @@ -91,10 +91,6 @@ constructor(
activeSurveyFlow.filterNotNull().onEach { lastActiveSurveyId = it.id }.launchIn(externalScope)
}

/** Listens for remote changes to the survey with the specified id. */
suspend fun subscribeToSurveyUpdates(surveyId: String) =
remoteDataStore.subscribeToSurveyUpdates(surveyId)

/**
* Returns the survey with the specified id from the local db, or `null` if not available offline.
*/
Expand Down

0 comments on commit 10b297a

Please sign in to comment.