Skip to content

Commit

Permalink
WIP: Get notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
dertieran committed Oct 5, 2020
1 parent 8bdc013 commit 220ff08
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/android/com/adobe/phonegap/push/PushConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@ public interface PushConstants {
public static final String ONGOING = "ongoing";
public static final String LIST_CHANNELS = "listChannels";
public static final String CLEAR_NOTIFICATION = "clearNotification";
public static final String GET_NOTIFICATIONS = "getNotifications";
public static final String MESSAGE_ID = "google.message_id";
}
13 changes: 13 additions & 0 deletions src/android/com/adobe/phonegap/push/PushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,13 @@ public void run () {
}
}
});
} else if (GET_NOTIFICATIONS.equals(action)) {
cordova.getThreadPool().execute(new Runnable() {
public void run () {
Log.v(LOG_TAG, "getNotifications");
callbackContext.success(getNotifications(getApplicationContext()));
}
});
} else {
Log.e(LOG_TAG, "Invalid action : " + action);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
Expand Down Expand Up @@ -573,6 +580,12 @@ private void clearNotification (int id) {
notificationManager.cancel(appName, id);
}

private StatusBarNotification[] getNotifications () {
final NotificationManager notificationManager = (NotificationManager) cordova.getActivity()
.getSystemService(Context.NOTIFICATION_SERVICE);
return notificationManager.getActiveNotifications();
}

private void subscribeToTopics (JSONArray topics, String registrationToken) {
if (topics != null) {
String topic = null;
Expand Down
10 changes: 10 additions & 0 deletions src/ios/PushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,16 @@ - (void)clearNotification:(CDVInvokedUrlCommand *)command
}];
}

- (void)getNotifications:(CDVInvokedUrlCommand *)command
{
[[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {
NSMutableDictionary* message = [NSMutableDictionary dictionaryWithCapacity:1];
[message setObject:notifications forKey:@"notifications"];
CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:message];
[self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId];
}];
}

- (void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command
{
NSMutableDictionary* options = [command.arguments objectAtIndex:0];
Expand Down
19 changes: 19 additions & 0 deletions src/js/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,25 @@ class PushNotification {
[idNumber]);
}

getNotifications (successCallback = () => {}, errorCallback = () => {}) {
if (typeof errorCallback !== 'function') {
console.log(
'PushNotification.getNotifications failure: failure parameter not a function'
);
return;
}

if (typeof successCallback !== 'function') {
console.log(
'PushNotification.getNotifications failure: success callback ' +
'parameter must be a function'
);
return;
}

exec(successCallback, errorCallback, 'PushNotification', 'getNotifications', []);
}

/**
* Listen for an event.
*
Expand Down
18 changes: 18 additions & 0 deletions www/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,24 @@ var PushNotification = /*#__PURE__*/function () {

exec(successCallback, errorCallback, 'PushNotification', 'clearNotification', [idNumber]);
}
}, {
key: "getNotifications",
value: function getNotifications() {
var successCallback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
var errorCallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};

if (typeof errorCallback !== 'function') {
console.log('PushNotification.getNotifications failure: failure parameter not a function');
return;
}

if (typeof successCallback !== 'function') {
console.log('PushNotification.getNotifications failure: success callback ' + 'parameter must be a function');
return;
}

exec(successCallback, errorCallback, 'PushNotification', 'getNotifications', []);
}
/**
* Listen for an event.
*
Expand Down

0 comments on commit 220ff08

Please sign in to comment.