diff --git a/app/src/main/java/app/closer/core/billing/FirestoreEntitlementChecker.kt b/app/src/main/java/app/closer/core/billing/FirestoreEntitlementChecker.kt index 7fe2f824..aaf5b16f 100644 --- a/app/src/main/java/app/closer/core/billing/FirestoreEntitlementChecker.kt +++ b/app/src/main/java/app/closer/core/billing/FirestoreEntitlementChecker.kt @@ -10,15 +10,13 @@ import com.revenuecat.purchases.EntitlementInfo import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.cancel import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow -import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf -import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import javax.inject.Inject import javax.inject.Singleton @@ -64,17 +62,7 @@ class FirestoreEntitlementChecker @Inject constructor( } .distinctUntilChanged() - override suspend fun hasPremium(): Boolean = isPremium() - .map { it } - .let { flow -> - // Safe one-shot collector; this is called from non-flow callers. - var value = false - val job = CoroutineScope(Dispatchers.IO).launch { - flow.collect { value = it } - } - job.cancel() - value - } + override suspend fun hasPremium(): Boolean = isPremium().first() override fun onCustomerInfoUpdated(customerInfo: CustomerInfo) { revenueCatFallback = customerInfo.entitlements.active diff --git a/app/src/main/java/app/closer/ui/settings/DeleteAccountScreen.kt b/app/src/main/java/app/closer/ui/settings/DeleteAccountScreen.kt index 0cac8df3..23678199 100644 --- a/app/src/main/java/app/closer/ui/settings/DeleteAccountScreen.kt +++ b/app/src/main/java/app/closer/ui/settings/DeleteAccountScreen.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import app.closer.core.navigation.AppRoute import app.closer.domain.repository.AuthRepository +import app.closer.domain.repository.CoupleRepository import app.closer.domain.repository.UserRepository import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject @@ -68,6 +69,7 @@ data class DeleteAccountUiState( @HiltViewModel class DeleteAccountViewModel @Inject constructor( private val authRepository: AuthRepository, + private val coupleRepository: CoupleRepository, private val userRepository: UserRepository ) : ViewModel() { @@ -84,6 +86,9 @@ class DeleteAccountViewModel @Inject constructor( viewModelScope.launch { _uiState.update { it.copy(showConfirm = false, isDeleting = true, error = null) } if (uid != null) { + // Leave couple first so the partner is notified and the couple doc + // is cleaned up before the auth account disappears. + runCatching { coupleRepository.leaveCouple(uid) } runCatching { userRepository.deleteUserData(uid) } } authRepository.deleteAccount()