Skip to content
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

fix(push-notifications): use id and tag for canceling active notification #1041

Merged
merged 11 commits into from
Jun 16, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void getDeliveredNotifications(PluginCall call) {
JSObject jsNotif = new JSObject();

jsNotif.put("id", notif.getId());
jsNotif.put("tag", notif.getTag());

Notification notification = notif.getNotification();
if (notification != null) {
Expand Down Expand Up @@ -128,13 +129,13 @@ public void getDeliveredNotifications(PluginCall call) {
public void removeDeliveredNotifications(PluginCall call) {
JSArray notifications = call.getArray("notifications");

List<Integer> ids = new ArrayList<>();
List<String> tags = new ArrayList<>();
try {
for (Object o : notifications.toList()) {
if (o instanceof JSONObject) {
JSObject notif = JSObject.fromJSONObject((JSONObject) o);
Integer id = notif.getInteger("id");
ids.add(id);
String tag = notif.getString("tag");
jcesarmobile marked this conversation as resolved.
Show resolved Hide resolved
tags.add(tag);
} else {
call.reject("Expected notifications to be a list of notification objects");
}
Expand All @@ -143,8 +144,8 @@ public void removeDeliveredNotifications(PluginCall call) {
call.reject(e.getMessage());
}

for (int id : ids) {
notificationManager.cancel(id);
for (String tag : tags) {
notificationManager.cancel(tag, 0);
}

call.resolve();
Expand Down