Commit 04e5ef63 by Sebastián Katzer

Added new getType() method and implemented isPresent, isScheduled, isTriggered for Windows

parent 0224f67c
...@@ -51,12 +51,8 @@ ...@@ -51,12 +51,8 @@
// Cancel all notifications // Cancel all notifications
- (void) cancelAll:(CDVInvokedUrlCommand*)command; - (void) cancelAll:(CDVInvokedUrlCommand*)command;
// If a notification with an ID is present // Notification type
- (void) isPresent:(CDVInvokedUrlCommand*)command; - (void) type:(CDVInvokedUrlCommand*)command;
// If a notification with an ID is scheduled
- (void) isScheduled:(CDVInvokedUrlCommand*)command;
// If a notification with an ID is triggered
- (void) isTriggered:(CDVInvokedUrlCommand*)command;
// List of all notification IDs // List of all notification IDs
- (void) ids:(CDVInvokedUrlCommand*)command; - (void) ids:(CDVInvokedUrlCommand*)command;
...@@ -67,10 +63,6 @@ ...@@ -67,10 +63,6 @@
// Notification by id // Notification by id
- (void) notification:(CDVInvokedUrlCommand*)command; - (void) notification:(CDVInvokedUrlCommand*)command;
// Scheduled notification by id
- (void) scheduledNotification:(CDVInvokedUrlCommand*)command;
// Triggered notification by id
- (void) triggeredNotification:(CDVInvokedUrlCommand*)command;
// List of notifications by id // List of notifications by id
- (void) notifications:(CDVInvokedUrlCommand*)command; - (void) notifications:(CDVInvokedUrlCommand*)command;
......
...@@ -242,58 +242,32 @@ ...@@ -242,58 +242,32 @@
} }
/** /**
* If a notification by ID is present. * Get type of notification.
* *
* @param [ Number ]id The ID of the notification. * @param [ Int ] id The ID of the notification.
* *
* @return [ Void ] * @return [ Void ]
*/ */
- (void) isPresent:(CDVInvokedUrlCommand *)command - (void) type:(CDVInvokedUrlCommand*)command
{
[self exist:command byType:NotifcationTypeAll];
}
/**
* If a notification by ID is scheduled.
*
* @param [ Number ]id The ID of the notification.
*
* @return [ Void ]
*/
- (void) isScheduled:(CDVInvokedUrlCommand*)command
{
[self exist:command byType:NotifcationTypeScheduled];
}
/**
* Check if a notification with an ID is triggered.
*
* @param [ Number ]id The ID of the notification.
*
* @return [ Void ]
*/
- (void) isTriggered:(CDVInvokedUrlCommand*)command
{
[self exist:command byType:NotifcationTypeTriggered];
}
/**
* Check if a notification exists by ID and type.
*
* @param [ APPNotificationType ] type The type of notifications to look for.
*
* @return [ Void ]
*/
- (void) exist:(CDVInvokedUrlCommand*)command
byType:(APPNotificationType)type;
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
NSNumber* id = [command argumentAtIndex:0]; NSNumber* id = [command argumentAtIndex:0];
BOOL exist = [_center notificationExist:id type:type]; NSString* type;
switch ([_center getTypeOfNotificationWithId:id]) {
case NotifcationTypeScheduled:
type = @"scheduled";
break;
case NotifcationTypeTriggered:
type = @"triggered";
break;
default:
type = @"unknown";
}
CDVPluginResult* result; CDVPluginResult* result;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsBool:exist]; messageAsString:type];
[self.commandDelegate sendPluginResult:result [self.commandDelegate sendPluginResult:result
callbackId:command.callbackId]; callbackId:command.callbackId];
...@@ -361,48 +335,11 @@ ...@@ -361,48 +335,11 @@
*/ */
- (void) notification:(CDVInvokedUrlCommand*)command - (void) notification:(CDVInvokedUrlCommand*)command
{ {
[self notification:command byType:NotifcationTypeAll];
}
/**
* Scheduled notification by id.
*
* @param [ Number ] id The id of the notification to return.
*
* @return [ Void ]
*/
- (void) scheduledNotification:(CDVInvokedUrlCommand*)command
{
[self notification:command byType:NotifcationTypeScheduled];
}
/**
* Triggered notification by id.
*
* @param [ Number ] id The id of the notification to return.
*
* @return [ Void ]
*/
- (void) triggeredNotification:(CDVInvokedUrlCommand*)command
{
[self notification:command byType:NotifcationTypeTriggered];
}
/**
* Notification by type and id.
*
* @param [ APPNotificationType ] type The type of notifications to look for.
*
* @return [ Void ]
*/
- (void) notification:(CDVInvokedUrlCommand*)command
byType:(APPNotificationType)type;
{
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
NSArray* ids = command.arguments; NSArray* ids = command.arguments;
NSArray* notifications; NSArray* notifications;
notifications = [_center getNotificationOptionsByType:type andId:ids]; notifications = [_center getNotificationOptionsById:ids];
CDVPluginResult* result; CDVPluginResult* result;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
...@@ -450,7 +387,7 @@ ...@@ -450,7 +387,7 @@
} }
/** /**
* List of notifications by type and id. * List of notifications by type or id.
* *
* @param [ APPNotificationType ] type The type of notifications to look for. * @param [ APPNotificationType ] type The type of notifications to look for.
* *
...@@ -463,18 +400,11 @@ ...@@ -463,18 +400,11 @@
NSArray* ids = command.arguments; NSArray* ids = command.arguments;
NSArray* notifications; NSArray* notifications;
if (type == NotifcationTypeAll && ids.count == 0) { if (ids.count > 0) {
notifications = [_center getNotificationOptions];
}
else if (type == NotifcationTypeAll) {
notifications = [_center getNotificationOptionsById:ids]; notifications = [_center getNotificationOptionsById:ids];
} }
else if (ids.count == 0) {
notifications = [_center getNotificationOptionsByType:type];
}
else { else {
notifications = [_center getNotificationOptionsByType:type notifications = [_center getNotificationOptionsByType:type];
andId:ids];
} }
CDVPluginResult* result; CDVPluginResult* result;
......
...@@ -28,7 +28,8 @@ extern NSString * const kAPPGeneralCategory; ...@@ -28,7 +28,8 @@ extern NSString * const kAPPGeneralCategory;
typedef NS_ENUM(NSUInteger, APPNotificationType) { typedef NS_ENUM(NSUInteger, APPNotificationType) {
NotifcationTypeAll = 0, NotifcationTypeAll = 0,
NotifcationTypeScheduled = 1, NotifcationTypeScheduled = 1,
NotifcationTypeTriggered = 2 NotifcationTypeTriggered = 2,
NotifcationTypeUnknown = 3
}; };
#define APPNotificationType_DEFINED #define APPNotificationType_DEFINED
...@@ -44,15 +45,10 @@ typedef NS_ENUM(NSUInteger, APPNotificationType) { ...@@ -44,15 +45,10 @@ typedef NS_ENUM(NSUInteger, APPNotificationType) {
// List of all notification IDs from given type // List of all notification IDs from given type
- (NSArray*) getNotificationIdsByType:(APPNotificationType)type; - (NSArray*) getNotificationIdsByType:(APPNotificationType)type;
// Find out if notification with ID exists
- (BOOL) notificationExist:(NSNumber*)id;
// Find out if notification with ID and type exists
- (BOOL) notificationExist:(NSNumber*)id type:(APPNotificationType)type;
// Find notification by ID // Find notification by ID
- (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id; - (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id;
// Find notification by ID and type // Find notification type by ID
- (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id andType:(APPNotificationType)type; - (APPNotificationType) getTypeOfNotificationWithId:(NSNumber*)id;
// Property list from all local notifications // Property list from all local notifications
- (NSArray*) getNotificationOptions; - (NSArray*) getNotificationOptions;
...@@ -60,8 +56,6 @@ typedef NS_ENUM(NSUInteger, APPNotificationType) { ...@@ -60,8 +56,6 @@ typedef NS_ENUM(NSUInteger, APPNotificationType) {
- (NSArray*) getNotificationOptionsById:(NSArray*)ids; - (NSArray*) getNotificationOptionsById:(NSArray*)ids;
// Property list from all local notifications with type constraint // Property list from all local notifications with type constraint
- (NSArray*) getNotificationOptionsByType:(APPNotificationType)type; - (NSArray*) getNotificationOptionsByType:(APPNotificationType)type;
// Property list from given local notifications with type constraint
- (NSArray*) getNotificationOptionsByType:(APPNotificationType)type andId:(NSArray*)ids;
// Clear specified notfication // Clear specified notfication
- (void) clearNotification:(UNNotificationRequest*)notification; - (void) clearNotification:(UNNotificationRequest*)notification;
......
...@@ -185,29 +185,6 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -185,29 +185,6 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
return ids; return ids;
} }
/*
* If the notification with the specified ID does exists.
*
* @param id
* Notification ID
*/
- (BOOL) notificationExist:(NSNumber*)id
{
return [self getNotificationWithId:id] != NULL;
}
/* If the notification with specified ID and type exists.
*
* @param id
* Notification ID
* @param type
* Notification life cycle type
*/
- (BOOL) notificationExist:(NSNumber*)id type:(APPNotificationType)type
{
return [self getNotificationWithId:id andType:type] != NULL;
}
/** /**
* Find notification by ID. * Find notification by ID.
* *
...@@ -216,20 +193,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -216,20 +193,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
*/ */
- (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id - (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id
{ {
return [self getNotificationWithId:id andType:NotifcationTypeAll]; NSArray* notifications = [self getNotifications];
}
/*
* Find notification by ID and type.
*
* @param id
* Notification ID
* @param type
* Notification life cycle type
*/
- (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id andType:(APPNotificationType)type
{
NSArray* notifications = [self getNotificationsByType:type];
for (UNNotificationRequest* notification in notifications) for (UNNotificationRequest* notification in notifications)
{ {
...@@ -244,6 +208,24 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -244,6 +208,24 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
} }
/** /**
* Find notification type by ID
*/
- (APPNotificationType) getTypeOfNotificationWithId:(NSNumber*)id
{
NSArray* ids = [self getNotificationIdsByType:NotifcationTypeTriggered];
if ([ids containsObject:id])
return NotifcationTypeTriggered;
ids = [self getNotificationIdsByType:NotifcationTypeScheduled];
if ([ids containsObject:id])
return NotifcationTypeScheduled;
return NotifcationTypeUnknown;
}
/**
* List of properties from all notifications. * List of properties from all notifications.
*/ */
- (NSArray*) getNotificationOptions - (NSArray*) getNotificationOptions
...@@ -278,20 +260,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -278,20 +260,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
*/ */
- (NSArray*) getNotificationOptionsById:(NSArray*)ids - (NSArray*) getNotificationOptionsById:(NSArray*)ids
{ {
return [self getNotificationOptionsByType:NotifcationTypeAll andId:ids]; NSArray* notifications = [self getNotifications];
}
/**
* List of properties from given local notifications.
*
* @param type
* Notification life cycle type
* @param ids
* Notification IDs
*/
- (NSArray*) getNotificationOptionsByType:(APPNotificationType)type andId:(NSArray*)ids
{
NSArray* notifications = [self getNotificationsByType:type];
NSMutableArray* options = [[NSMutableArray alloc] init]; NSMutableArray* options = [[NSMutableArray alloc] init];
for (UNNotificationRequest* notification in notifications) for (UNNotificationRequest* notification in notifications)
......
...@@ -98,6 +98,21 @@ exports.schedule = function (success, error, args) { ...@@ -98,6 +98,21 @@ exports.schedule = function (success, error, args) {
}; };
/** /**
* Get the type of notification.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
* @param [ Array ] args Interface arguments
*
* @return [ Void ]
*/
exports.type = function (success, error, args) {
var type = impl.type(args[0]);
success(type);
};
/**
* List of all notification ids. * List of all notification ids.
* *
* @param [ Function ] success Success callback * @param [ Function ] success Success callback
......
...@@ -238,5 +238,35 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -238,5 +238,35 @@ namespace LocalNotificationProxy.LocalNotification
return null; return null;
} }
/// <summary>
/// Gets the type (scheduled, triggered or unknown).
/// </summary>
/// <param name="id">The ID of the notification to find for.</param>
/// <returns>The type of the notification or unknown type.</returns>
public Notification.Type GetType(string id)
{
var scheduled = ToastNotifier.GetScheduledToastNotifications();
foreach (var toast in scheduled)
{
if (toast.Tag == id)
{
return Notification.Type.Scheduled;
}
}
var triggered = ToastNotificationManager.History.GetHistory();
foreach (var toast in triggered)
{
if (toast.Tag == id)
{
return Notification.Type.Triggered;
}
}
return Notification.Type.Unknown;
}
} }
} }
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
public enum Type public enum Type
{ {
All, Scheduled, Triggered All, Scheduled, Triggered, Unknown
} }
public Options Options { get; private set; } public Options Options { get; private set; }
......
...@@ -50,6 +50,16 @@ namespace LocalNotificationProxy ...@@ -50,6 +50,16 @@ namespace LocalNotificationProxy
} }
/// <summary> /// <summary>
/// Gets the type of the notification specified by ID.
/// </summary>
/// <param name="id">The ID of the notification to find for.</param>
/// <returns>The type (scheduled, triggered or unknown).</returns>
public string Type(int id)
{
return this.manager.GetType(id.ToString()).ToString().ToLower();
}
/// <summary>
/// List of all notifiation by id. /// List of all notifiation by id.
/// </summary> /// </summary>
/// <returns>List of numbers</returns> /// <returns>List of numbers</returns>
......
...@@ -185,24 +185,33 @@ exports.cancelAll = function (callback, scope) { ...@@ -185,24 +185,33 @@ exports.cancelAll = function (callback, scope) {
* @return [ Void ] * @return [ Void ]
*/ */
exports.isPresent = function (id, callback, scope) { exports.isPresent = function (id, callback, scope) {
this.exec('isPresent', id, callback, scope); var fn = this.createCallbackFn(callback, scope);
this.getType(id, function (type) {
fn(type != 'unknown');
});
}; };
/** /**
* Check if a notification is scheduled. * Check if a notification has a given type.
* *
* @param [ Int ] id The ID of the notification. * @param [ Int ] id The ID of the notification.
* @param [ String ] type The type of the notification.
* @param [ Function ] callback The function to be exec as the callback. * @param [ Function ] callback The function to be exec as the callback.
* @param [ Object ] scope The callback function's scope. * @param [ Object ] scope The callback function's scope.
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.isScheduled = function (id, callback, scope) { exports.hasType = function (id, type, callback, scope) {
this.exec('isScheduled', id, callback, scope); var fn = this.createCallbackFn(callback, scope);
this.getType(id, function (type2) {
fn(type == type2);
});
}; };
/** /**
* Check if a notification was triggered. * Get the type (triggered, scheduled) for the notification.
* *
* @param [ Int ] id The ID of the notification. * @param [ Int ] id The ID of the notification.
* @param [ Function ] callback The function to be exec as the callback. * @param [ Function ] callback The function to be exec as the callback.
...@@ -210,8 +219,8 @@ exports.isScheduled = function (id, callback, scope) { ...@@ -210,8 +219,8 @@ exports.isScheduled = function (id, callback, scope) {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.isTriggered = function (id, callback, scope) { exports.getType = function (id, callback, scope) {
this.exec('isTriggered', id, callback, scope); this.exec('type', id, callback, scope);
}; };
/** /**
......
...@@ -147,7 +147,7 @@ exports.isPresent = function (id, callback, scope) { ...@@ -147,7 +147,7 @@ exports.isPresent = function (id, callback, scope) {
* @return [ Void ] * @return [ Void ]
*/ */
exports.isScheduled = function (id, callback, scope) { exports.isScheduled = function (id, callback, scope) {
this.core.isScheduled(id, callback, scope); this.core.hasType(id, 'scheduled', callback, scope);
}; };
/** /**
...@@ -160,7 +160,20 @@ exports.isScheduled = function (id, callback, scope) { ...@@ -160,7 +160,20 @@ exports.isScheduled = function (id, callback, scope) {
* @return [ Void ] * @return [ Void ]
*/ */
exports.isTriggered = function (id, callback, scope) { exports.isTriggered = function (id, callback, scope) {
this.core.isTriggered(id, callback, scope); this.core.hasType(id, 'triggered', callback, scope);
};
/**
* Get the type (triggered, scheduled) for the notification.
*
* @param [ Int ] id The ID of the notification.
* @param [ Function ] callback The function to be exec as the callback.
* @param [ Object ] scope The callback function's scope.
*
* @return [ Void ]
*/
exports.getType = function (id, callback, scope) {
this.core.getType(id, callback, scope);
}; };
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment