fix(scene): isolate scheduled automation execution
This commit is contained in:
@@ -3,6 +3,7 @@ package com.flagship.abox.manager.domain
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
|
||||
@@ -173,7 +174,23 @@ class SessionCoordinator(
|
||||
suspend fun validateActiveSession(): DomainResult<SessionValidity> = storeOperation {
|
||||
val profile = profileStore.activeProfile()
|
||||
?: return@storeOperation DomainResult.Success(SessionValidity.INVALID)
|
||||
profile.gateway().validateSession(profile.id)
|
||||
validateSession(profile.id)
|
||||
}
|
||||
|
||||
suspend fun validateSession(profileId: ProviderProfileId): DomainResult<SessionValidity> = storeOperation {
|
||||
val profile = profileStore.activeProfile()
|
||||
if (profile?.id != profileId) return@storeOperation DomainResult.Success(SessionValidity.INVALID)
|
||||
val session = profile.gateway().observeSession(profileId).first()
|
||||
if (session?.profileId != profileId) return@storeOperation DomainResult.Success(SessionValidity.INVALID)
|
||||
when (val validity = profile.gateway().validateSession(profileId)) {
|
||||
is DomainResult.Failure -> validity
|
||||
is DomainResult.Success -> {
|
||||
val stillActive = profileStore.activeProfile()?.id == profileId
|
||||
val currentSession = profile.gateway().observeSession(profileId).first()
|
||||
if (stillActive && currentSession?.profileId == profileId) validity
|
||||
else DomainResult.Success(SessionValidity.INVALID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun logout(): DomainResult<Unit> = storeOperation {
|
||||
|
||||
Reference in New Issue
Block a user