fix(daily-question): wire reconcileLocalAnswerFromFirestore into DailyQuestionViewModel
This commit is contained in:
parent
a6d3062585
commit
6dd1451095
|
|
@ -75,7 +75,26 @@ class DailyQuestionViewModel @Inject constructor(
|
|||
val today = resolved.date
|
||||
val coupleId = resolved.coupleId
|
||||
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 {
|
||||
runCatching { checkPartnerAnswered(it, today) }.getOrDefault(false)
|
||||
} ?: false
|
||||
|
|
|
|||
Loading…
Reference in New Issue