From 58b61471b5adbef5d87b9964febd0a0fd84a2411 Mon Sep 17 00:00:00 2001 From: Jose Olarte III Date: Mon, 8 Jun 2026 19:42:48 +0800 Subject: [PATCH] fix(notifications): use clearPredictiveNotifications on refresh Avoid cancelAllNotifications during schedule replacement so Daily Reminder schedules are not cleared. --- .../NativeNotificationService.ts | 21 +++++++++---------- src/types/daily-notification-plugin.d.ts | 7 +++++++ 2 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 src/types/daily-notification-plugin.d.ts diff --git a/src/services/notifications/NativeNotificationService.ts b/src/services/notifications/NativeNotificationService.ts index cc3e561c..31d78daa 100644 --- a/src/services/notifications/NativeNotificationService.ts +++ b/src/services/notifications/NativeNotificationService.ts @@ -709,29 +709,28 @@ export async function applyNotificationRefreshPayload( logScheduleReplacement(timestamps.length); const plugin = DailyNotification as unknown as { - clearAllNotifications?: () => Promise; + clearPredictiveNotifications?: () => Promise; scheduleNotifications?: (options: { timestamps: number[]; }) => Promise; - cancelAllNotifications?: () => Promise; }; - if (typeof plugin.clearAllNotifications === "function") { - logNotificationClearing("clearAllNotifications"); - await plugin.clearAllNotifications(); - } else if (typeof plugin.cancelAllNotifications === "function") { - logNotificationClearing("cancelAllNotifications"); - await plugin.cancelAllNotifications(); - } else { + if (typeof plugin.clearPredictiveNotifications !== "function") { logger.warn( - "[NativeNotificationService] No clearAllNotifications/cancelAllNotifications on plugin; cannot replace schedule", + "[NativeNotificationService] No clearPredictiveNotifications on plugin; cannot replace schedule", ); logNotification( - "Schedule replacement aborted (clear method unavailable on plugin)", + "Schedule replacement aborted (clearPredictiveNotifications unavailable on plugin)", ); return; } + console.log( + "[Notifications] Clearing predictive notifications before refresh", + ); + logNotificationClearing("clearPredictiveNotifications"); + await plugin.clearPredictiveNotifications(); + if (typeof plugin.scheduleNotifications !== "function") { logger.warn( "[NativeNotificationService] scheduleNotifications not available on plugin; cannot apply timestamps", diff --git a/src/types/daily-notification-plugin.d.ts b/src/types/daily-notification-plugin.d.ts new file mode 100644 index 00000000..e6a9bd58 --- /dev/null +++ b/src/types/daily-notification-plugin.d.ts @@ -0,0 +1,7 @@ +import type {} from "@timesafari/daily-notification-plugin"; + +declare module "@timesafari/daily-notification-plugin" { + interface DailyNotificationPlugin { + clearPredictiveNotifications(): Promise; + } +}