fix: simplify finishGame to not require userId — first caller wins

This commit is contained in:
null 2026-06-18 02:47:57 -05:00
parent 21df900bc7
commit c894dd8c67
2 changed files with 9 additions and 13 deletions

View File

@ -94,23 +94,20 @@ class GameSessionManager @Inject constructor(
}
/**
* Finish the session referenced by [handle] for the current user.
* Finish the session referenced by [handle].
*/
suspend fun finishGameForCurrentUser(handle: GameHandle): Result<Unit> {
val userId = authRepository.currentUserId
?: return Result.failure(Exception("Not signed in"))
return finishGame(handle.sessionId, handle.coupleId, userId)
}
suspend fun finishGameForCurrentUser(handle: GameHandle): Result<Unit> =
finishGame(handle.sessionId, handle.coupleId)
/**
* Finish the current session for a user.
* Marks the session as completed by this user.
* Notifies partner when both users have completed.
* Mark the session as completed for the couple.
* The first caller wins the whole session flips to "completed" immediately.
* This is correct for pass-the-phone games; async partner-sync games would
* need per-user completion fields instead.
*/
suspend fun finishGame(
sessionId: String,
coupleId: String,
userId: String
coupleId: String
): Result<Unit> = runCatching {
val currentSession = sessionRepository.getActiveSessionForCouple(coupleId)
?: throw Exception("No active session found")

View File

@ -69,8 +69,7 @@ class WheelCompleteViewModel @Inject constructor(
val couple = coupleRepository.getCoupleForUser(uid) ?: return@launch
gameSessionManager.finishGame(
sessionId = sessionId,
coupleId = couple.id,
userId = uid
coupleId = couple.id
)
}
}