From b9b15604ef4befe02b5e67e04d92983e0d2bdf0d Mon Sep 17 00:00:00 2001 From: null Date: Fri, 26 Jun 2026 12:41:17 -0500 Subject: [PATCH] =?UTF-8?q?fix(games):=20notification=20deep-link=20lands?= =?UTF-8?q?=20in=20active=20game=20=E2=80=94=20singleTop=20+=20server-firs?= =?UTF-8?q?t=20read=20(E-GAME-001)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 1 + .../data/repository/QuestionSessionRepositoryImpl.kt | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4a8ef50d..e16c76f6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,6 +24,7 @@ diff --git a/app/src/main/java/app/closer/data/repository/QuestionSessionRepositoryImpl.kt b/app/src/main/java/app/closer/data/repository/QuestionSessionRepositoryImpl.kt index b10ff5d3..c4985bf2 100644 --- a/app/src/main/java/app/closer/data/repository/QuestionSessionRepositoryImpl.kt +++ b/app/src/main/java/app/closer/data/repository/QuestionSessionRepositoryImpl.kt @@ -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()