Support incrementing push badge value by more than 1 (#4889)

* Support 'IncrementByN' badge value for higher push badge increments

* Fix test

* Rely on object for badge incrementation (i.e. {increment: 3}) rather than string (IncrementBy3)

* For badge incrementation, utilize format similar to other operation notation
This commit is contained in:
Ross Bayer
2018-07-12 11:34:08 -07:00
committed by Florent Vilmart
parent c99cbbf530
commit faa04f7209
3 changed files with 93 additions and 5 deletions

View File

@@ -44,10 +44,13 @@ export class PushController {
let restUpdate = {};
if (typeof badge == 'string' && badge.toLowerCase() === 'increment') {
restUpdate = { badge: { __op: 'Increment', amount: 1 } }
} else if (typeof badge == 'object' && typeof badge.__op == 'string' &&
badge.__op.toLowerCase() == 'increment' && Number(badge.amount)) {
restUpdate = { badge: { __op: 'Increment', amount: badge.amount } }
} else if (Number(badge)) {
restUpdate = { badge: badge }
} else {
throw "Invalid value for badge, expected number or 'Increment'";
throw "Invalid value for badge, expected number or 'Increment' or {increment: number}";
}
// Force filtering on only valid device tokens

View File

@@ -2,10 +2,17 @@ import Parse from 'parse/node';
import deepcopy from 'deepcopy';
export function isPushIncrementing(body) {
return body.data &&
body.data.badge &&
typeof body.data.badge == 'string' &&
body.data.badge.toLowerCase() == "increment"
if (!body.data || !body.data.badge) {
return false;
}
const badge = body.data.badge;
if (typeof badge == 'string' && badge.toLowerCase() == "increment") {
return true;
}
return typeof badge == 'object' && typeof badge.__op == 'string' &&
badge.__op.toLowerCase() == "increment" && Number(badge.amount);
}
const localizableKeys = ['alert', 'title'];