bugfix: retry notification should now only show up if you did NOT yet

take the supplement on that day.
This commit is contained in:
2025-08-28 11:44:39 +02:00
parent 142359bf94
commit 6524e625d8

View File

@@ -173,21 +173,36 @@ class NotificationService {
// Call the callback to record the intake // Call the callback to record the intake
if (_onTakeSupplementCallback != null) { if (_onTakeSupplementCallback != null) {
print('SupplementsLog: 📱 Calling supplement callback...'); print('SupplementsLog: 📱 Calling supplement callback...');
_onTakeSupplementCallback!(supplementId, supplementName, units, unitType); _onTakeSupplementCallback!(
supplementId, supplementName, units, unitType);
print('SupplementsLog: 📱 Callback completed'); print('SupplementsLog: 📱 Callback completed');
} else { } else {
print('SupplementsLog: 📱 ERROR: No callback registered!'); print('SupplementsLog: 📱 ERROR: No callback registered!');
} }
// Mark notification as taken in database (this will cancel any pending retries) // For retry notifications, the original notification ID is in the payload
if (notificationId != null) { int originalNotificationId;
print('SupplementsLog: 📱 Marking notification $notificationId as taken'); if (parts.length > 4 && int.tryParse(parts[4]) != null) {
await DatabaseHelper.instance.markNotificationTaken(notificationId); originalNotificationId = int.parse(parts[4]);
print(
// Cancel any pending retry notifications for this notification 'SupplementsLog: 📱 Retry notification detected. Original ID: $originalNotificationId');
_cancelRetryNotifications(notificationId); } else if (notificationId != null) {
originalNotificationId = notificationId;
} else {
print(
'SupplementsLog: 📱 ERROR: Could not determine notification ID to cancel.');
return;
} }
// Mark notification as taken in database (this will cancel any pending retries)
print(
'SupplementsLog: 📱 Marking notification $originalNotificationId as taken');
await DatabaseHelper.instance
.markNotificationTaken(originalNotificationId);
// Cancel any pending retry notifications for this notification
_cancelRetryNotifications(originalNotificationId);
// Show a confirmation notification // Show a confirmation notification
print('SupplementsLog: 📱 Showing confirmation notification...'); print('SupplementsLog: 📱 Showing confirmation notification...');
showInstantNotification( showInstantNotification(
@@ -195,7 +210,8 @@ class NotificationService {
'$supplementName has been recorded at ${DateTime.now().hour.toString().padLeft(2, '0')}:${DateTime.now().minute.toString().padLeft(2, '0')}', '$supplementName has been recorded at ${DateTime.now().hour.toString().padLeft(2, '0')}:${DateTime.now().minute.toString().padLeft(2, '0')}',
); );
} else { } else {
print('SupplementsLog: 📱 ERROR: Invalid payload format - not enough parts'); print(
'SupplementsLog: 📱 ERROR: Invalid payload format - not enough parts');
} }
} catch (e) { } catch (e) {
print('SupplementsLog: 📱 ERROR in _handleTakeAction: $e'); print('SupplementsLog: 📱 ERROR in _handleTakeAction: $e');