fix(notifications): use clearPredictiveNotifications on refresh

Avoid cancelAllNotifications during schedule replacement so Daily
Reminder schedules are not cleared.
This commit is contained in:
Jose Olarte III
2026-06-08 19:42:48 +08:00
parent 55ef36be06
commit 58b61471b5
2 changed files with 17 additions and 11 deletions

View File

@@ -709,29 +709,28 @@ export async function applyNotificationRefreshPayload(
logScheduleReplacement(timestamps.length); logScheduleReplacement(timestamps.length);
const plugin = DailyNotification as unknown as { const plugin = DailyNotification as unknown as {
clearAllNotifications?: () => Promise<void>; clearPredictiveNotifications?: () => Promise<void>;
scheduleNotifications?: (options: { scheduleNotifications?: (options: {
timestamps: number[]; timestamps: number[];
}) => Promise<void>; }) => Promise<void>;
cancelAllNotifications?: () => Promise<void>;
}; };
if (typeof plugin.clearAllNotifications === "function") { if (typeof plugin.clearPredictiveNotifications !== "function") {
logNotificationClearing("clearAllNotifications");
await plugin.clearAllNotifications();
} else if (typeof plugin.cancelAllNotifications === "function") {
logNotificationClearing("cancelAllNotifications");
await plugin.cancelAllNotifications();
} else {
logger.warn( logger.warn(
"[NativeNotificationService] No clearAllNotifications/cancelAllNotifications on plugin; cannot replace schedule", "[NativeNotificationService] No clearPredictiveNotifications on plugin; cannot replace schedule",
); );
logNotification( logNotification(
"Schedule replacement aborted (clear method unavailable on plugin)", "Schedule replacement aborted (clearPredictiveNotifications unavailable on plugin)",
); );
return; return;
} }
console.log(
"[Notifications] Clearing predictive notifications before refresh",
);
logNotificationClearing("clearPredictiveNotifications");
await plugin.clearPredictiveNotifications();
if (typeof plugin.scheduleNotifications !== "function") { if (typeof plugin.scheduleNotifications !== "function") {
logger.warn( logger.warn(
"[NativeNotificationService] scheduleNotifications not available on plugin; cannot apply timestamps", "[NativeNotificationService] scheduleNotifications not available on plugin; cannot apply timestamps",

View File

@@ -0,0 +1,7 @@
import type {} from "@timesafari/daily-notification-plugin";
declare module "@timesafari/daily-notification-plugin" {
interface DailyNotificationPlugin {
clearPredictiveNotifications(): Promise<void>;
}
}