|
|
@@ -55,52 +55,74 @@ exports.setDefaults = function (newDefaults) {
|
|
|
/**
|
|
|
* Schedule a new local notification.
|
|
|
*
|
|
|
- * @param {Object} opts
|
|
|
+ * @param {Object} msgs
|
|
|
* The notification properties
|
|
|
* @param {Function} callback
|
|
|
* A function to be called after the notification has been canceled
|
|
|
* @param {Object?} scope
|
|
|
* The scope for the callback function
|
|
|
+ * @param {Object?} args
|
|
|
+ * skipPermission:true schedules the notifications immediatly without
|
|
|
+ * registering or checking for permission
|
|
|
*/
|
|
|
-exports.schedule = function (opts, callback, scope) {
|
|
|
- this.registerPermission(function(granted) {
|
|
|
+exports.schedule = function (msgs, callback, scope, args) {
|
|
|
+ var fn = function(granted) {
|
|
|
|
|
|
- if (!granted)
|
|
|
- return;
|
|
|
+ if (!granted) return;
|
|
|
|
|
|
- var notifications = Array.isArray(opts) ? opts : [opts];
|
|
|
+ var notifications = Array.isArray(msgs) ? msgs : [msgs];
|
|
|
|
|
|
for (var i = 0; i < notifications.length; i++) {
|
|
|
- var properties = notifications[i];
|
|
|
+ var notification = notifications[i];
|
|
|
|
|
|
- this.mergeWithDefaults(properties);
|
|
|
- this.convertProperties(properties);
|
|
|
+ this.mergeWithDefaults(notification);
|
|
|
+ this.convertProperties(notification);
|
|
|
}
|
|
|
|
|
|
this.exec('schedule', notifications, callback, scope);
|
|
|
- }, this);
|
|
|
+ };
|
|
|
+
|
|
|
+ if (args && args.skipPermission) {
|
|
|
+ fn.call(this, true);
|
|
|
+ } else {
|
|
|
+ this.registerPermission(fn, this);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* Update existing notifications specified by IDs in options.
|
|
|
*
|
|
|
- * @param {Object} options
|
|
|
+ * @param {Object} notifications
|
|
|
* The notification properties to update
|
|
|
* @param {Function} callback
|
|
|
* A function to be called after the notification has been updated
|
|
|
* @param {Object?} scope
|
|
|
* The scope for the callback function
|
|
|
+ * @param {Object?} args
|
|
|
+ * skipPermission:true schedules the notifications immediatly without
|
|
|
+ * registering or checking for permission
|
|
|
*/
|
|
|
-exports.update = function (opts, callback, scope) {
|
|
|
- var notifications = Array.isArray(opts) ? opts : [opts];
|
|
|
+exports.update = function (msgs, callback, scope, args) {
|
|
|
+ var fn = function(granted) {
|
|
|
|
|
|
- for (var i = 0; i < notifications.length; i++) {
|
|
|
- var properties = notifications[i];
|
|
|
+ if (!granted) return;
|
|
|
|
|
|
- this.convertProperties(properties);
|
|
|
- }
|
|
|
+ var notifications = Array.isArray(msgs) ? msgs : [msgs];
|
|
|
+
|
|
|
+ for (var i = 0; i < notifications.length; i++) {
|
|
|
+ var notification = notifications[i];
|
|
|
|
|
|
- this.exec('update', notifications, callback, scope);
|
|
|
+ this.convertProperties(notification);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.exec('update', notifications, callback, scope);
|
|
|
+ };
|
|
|
+
|
|
|
+ if (args && args.skipPermission) {
|
|
|
+ fn.call(this, true);
|
|
|
+ } else {
|
|
|
+ this.registerPermission(fn, this);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
/**
|