Skip to content

Add check for invalid use of multiple scheduler types #2293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,15 @@ private void triggerScheduledNotification(Notification notification, LocalNotifi
}
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, request.getId(), notificationIntent, flags);

// Schedule at specific time (with repeating support)
Date at = schedule.getAt();
String every = schedule.getEvery();
DateMatch on = schedule.getOn();
if ((at != null ? 0 : 1) + (every != null ? 0 : 1) + (on != null ? 0 : 1) <= 1) {
Logger.error(Logger.tags("LN"), "You cannot use multiple scheduler types. Use either 'at', 'every' or 'on' in the schedule object.", null);
return;
}

// Schedule at specific time (with repeating support)
if (at != null) {
if (at.getTime() < new Date().getTime()) {
Logger.error(Logger.tags("LN"), "Scheduled time must be *after* current time", null);
Expand All @@ -349,7 +356,6 @@ private void triggerScheduledNotification(Notification notification, LocalNotifi
}

// Schedule at specific intervals
String every = schedule.getEvery();
if (every != null) {
Long everyInterval = schedule.getEveryInterval();
if (everyInterval != null) {
Expand All @@ -360,7 +366,6 @@ private void triggerScheduledNotification(Notification notification, LocalNotifi
}

// Cron like scheduler
DateMatch on = schedule.getOn();
if (on != null) {
long trigger = on.nextTrigger(new Date());
notificationIntent.putExtra(TimedNotificationPublisher.CRON_KEY, on.toMatchString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ public class LocalNotificationsPlugin: CAPPlugin, CAPBridgedPlugin {
let on = schedule["on"] as? JSObject
let repeats = schedule["repeats"] as? Bool ?? false

if (at != nil ? 1 : 0) + (on != nil ? 1 : 0) + (every != nil ? 1 : 0) <= 1 {
call.reject("You cannot use multiple scheduler types. Use either 'at', 'every' or 'on' in the schedule object.")
return nil
}

// If there's a specific date for this notificiation
if let at = at {
let dateInfo = Calendar.current.dateComponents(in: TimeZone.current, from: at)
Expand Down