Commit 3a2ed5dc by Sebastián Katzer

Fixes #732 loop between update and trigger

parent fd647138
...@@ -5,6 +5,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo ...@@ -5,6 +5,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo
#### Version 0.8.3 (not yet released) #### Version 0.8.3 (not yet released)
- New "quarter" intervall for iOS & Android - New "quarter" intervall for iOS & Android
- Fixed #732 loop between update and trigger (Android)
- Fixed #710 crash due to >500 notifications (Android) - Fixed #710 crash due to >500 notifications (Android)
- Fixed crashing `get(ID)` if notification doesn't exist - Fixed crashing `get(ID)` if notification doesn't exist
......
...@@ -70,7 +70,7 @@ abstract public class AbstractTriggerReceiver extends BroadcastReceiver { ...@@ -70,7 +70,7 @@ abstract public class AbstractTriggerReceiver extends BroadcastReceiver {
Builder builder = new Builder(options); Builder builder = new Builder(options);
Notification notification = buildNotification(builder); Notification notification = buildNotification(builder);
boolean updated = notification.isUpdate(); boolean updated = notification.isUpdate(false);
onTrigger(notification, updated); onTrigger(notification, updated);
} }
......
...@@ -31,7 +31,6 @@ import org.json.JSONException; ...@@ -31,7 +31,6 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -121,7 +120,7 @@ public class Manager { ...@@ -121,7 +120,7 @@ public class Manager {
notification.getOptions().getDict(), updates); notification.getOptions().getDict(), updates);
try { try {
options.putOpt("updatedAt", new Date().getTime()); options.putOpt("updated", true);
} catch (JSONException ignore) {} } catch (JSONException ignore) {}
return schedule(options, receiver); return schedule(options, receiver);
......
...@@ -138,16 +138,18 @@ public class Notification { ...@@ -138,16 +138,18 @@ public class Notification {
/** /**
* If the notification is an update. * If the notification is an update.
*
* @param keepFlag
* Set to false to remove the flag from the option map
*/ */
protected boolean isUpdate () { protected boolean isUpdate (boolean keepFlag) {
boolean updated = options.getDict().optBoolean("updated", false);
if (!options.getDict().has("updatedAt"))
return false;
long now = new Date().getTime(); if (!keepFlag) {
long updatedAt = options.getDict().optLong("updatedAt", now); options.getDict().remove("updated");
}
return (now - updatedAt) < 1000; return updated;
} }
/** /**
...@@ -268,7 +270,7 @@ public class Notification { ...@@ -268,7 +270,7 @@ public class Notification {
} }
json.remove("firstAt"); json.remove("firstAt");
json.remove("updatedAt"); json.remove("updated");
json.remove("soundUri"); json.remove("soundUri");
json.remove("iconUri"); json.remove("iconUri");
......
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