fix(daily-question): wire reconcileLocalAnswerFromFirestore into DailyQuestionViewModel

This commit is contained in:
null 2026-06-30 19:06:01 -05:00
parent a6d3062585
commit 6dd1451095
1 changed files with 20 additions and 1 deletions

View File

@ -75,7 +75,26 @@ class DailyQuestionViewModel @Inject constructor(
val today = resolved.date val today = resolved.date
val coupleId = resolved.coupleId val coupleId = resolved.coupleId
val question = resolved.question val question = resolved.question
val answer = question?.let { localAnswerRepository.getAnswer(it.id) } // Room-first, but if Room has none while Firestore already holds this user's answer
// (fresh device / cleared DB), reconcile it back so we don't offer a re-answer that
// the immutable secure/payload rule would silently reject — R23 data-loss guard.
val userId = authRepository.currentUserId
val answer = question?.let { q ->
if (coupleId != null && userId != null) {
runCatching {
reconcileLocalAnswerFromFirestore(
question = q,
coupleId = coupleId,
date = today,
userId = userId,
firestore = firestoreAnswerDataSource,
localAnswers = localAnswerRepository
)
}.getOrNull()
} else {
localAnswerRepository.getAnswer(q.id)
}
}
val partnerHasAnswered = coupleId?.let { val partnerHasAnswered = coupleId?.let {
runCatching { checkPartnerAnswered(it, today) }.getOrDefault(false) runCatching { checkPartnerAnswered(it, today) }.getOrDefault(false)
} ?: false } ?: false