refill hearts like Duolingo: one every 5 hours, all of them after 24
Each heart used to take 24 hours, so a student who lost all five waited up to five days. Now one heart returns every 5 hours, and 24 hours after the first heart was lost they all come back at once (the owner's call). /api/user/hearts reports both times (nextRefillAt, fullRefillAt); an existing timer longer than 5 hours is shortened the first time it is read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -166,13 +166,14 @@ class UserHeartsView(APIView):
|
||||
user = request.user
|
||||
hearts, _ = UserHearts.objects.get_or_create(user_id=user.id)
|
||||
if hearts.apply_regen():
|
||||
hearts.save(update_fields=['current_hearts', 'next_refill_at'])
|
||||
hearts.save(update_fields=UserHearts.REGEN_FIELDS)
|
||||
|
||||
unlimited = has_unlimited_hearts(user.id)
|
||||
data = {
|
||||
'currentHearts': hearts.max_hearts if unlimited else hearts.current_hearts,
|
||||
'maxHearts': hearts.max_hearts,
|
||||
'nextRefillAt': None if unlimited else hearts.next_refill_at,
|
||||
'fullRefillAt': None if unlimited else hearts.full_refill_at,
|
||||
'isUnlimited': unlimited,
|
||||
}
|
||||
return Response(UserHeartsResponseSerializer(data).data)
|
||||
|
||||
Reference in New Issue
Block a user