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

View File

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