fix(games): notification deep-link lands in active game — singleTop + server-first read (E-GAME-001)

This commit is contained in:
null 2026-06-26 12:41:17 -05:00
parent e5c9c43317
commit b9b15604ef
2 changed files with 11 additions and 1 deletions

View File

@ -24,6 +24,7 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.Closer.Splash">
<intent-filter>

View File

@ -7,6 +7,7 @@ import app.closer.domain.model.QuestionSession
import app.closer.domain.repository.QuestionSessionRepository
import app.closer.domain.repository.SessionStartOutcome
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.Source
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
@ -156,14 +157,22 @@ class QuestionSessionRepositoryImpl @Inject constructor(
}
}
// Prefer a SERVER read so a session a partner JUST created — e.g. when we arrive from a
// "partner started a game" notification before our local cache has synced — is seen and
// joined, instead of dropping the user on the game's setup screen (or letting them start a
// duplicate). Fall back to CACHE when the server is unreachable (offline).
override suspend fun getActiveSessionForCouple(coupleId: String): QuestionSession? =
fetchActiveSessionForCouple(coupleId, Source.SERVER)
?: fetchActiveSessionForCouple(coupleId, Source.CACHE)
private suspend fun fetchActiveSessionForCouple(coupleId: String, source: Source): QuestionSession? =
runCatching {
firestore.collection(FirestoreCollections.COUPLES)
.document(coupleId)
.collection(FirestoreCollections.Couples.SESSIONS)
.whereEqualTo("status", "active")
.limit(1)
.get()
.get(source)
.await()
.documents
.firstOrNull()