Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/PushController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('PushController', () => {
}
const payload = {data:{
alert: "Hello World!",
badge: "IncrementBy3",
badge: {increment: 3},
}}
const installations = [];
while(installations.length != 10) {
Expand Down
9 changes: 3 additions & 6 deletions src/Controllers/PushController.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,15 @@ export class PushController {

if (body.data && body.data.badge) {
const badge = body.data.badge;
const incrementby = 'incrementby'; // make a variable to reduce likelihood of a typo below
let restUpdate = {};
if (typeof badge == 'string' && badge.toLowerCase() === 'increment') {
restUpdate = { badge: { __op: 'Increment', amount: 1 } }
} else if (typeof badge == 'string' && badge.toLowerCase().startsWith(incrementby) &&
parseInt(badge.substring(incrementby.length), 10) == badge.substring(incrementby.length) &&
parseInt(badge.substring(incrementby.length), 10) > 0) {
restUpdate = { badge: { __op: 'Increment', amount: parseInt(badge.substring(incrementby.length), 10) } }
} else if (typeof badge == 'object' && 'increment' in badge && Number(badge.increment)) {
restUpdate = { badge: { __op: 'Increment', amount: badge.increment } }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rdbayer @dplewis what do you think if we use the __op form instead of the one I just suggested? This is more consistent with the rest of the API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're talking about using it but only supporting the "increment" case, I'm happy to make the changes.

If you mean more broadly supporting all the same operations, I don't understand all the ramifications well enough myself to be confident in implementing that (I'm fairly new to the code base and likely don't have the time right now to get up to speed on all those different flows)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, for now that would be just for the increment. Sorry for the back and forths. I believe if we use the same JSON based objects as the rest of the API we’ll be happier on the long term

} else if (Number(badge)) {
restUpdate = { badge: badge }
} else {
throw "Invalid value for badge, expected number or 'Increment' or 'IncrementByN' (where N is a +ve integer)";
throw "Invalid value for badge, expected number or 'Increment' or {increment: number}";
}

// Force filtering on only valid device tokens
Expand Down
9 changes: 3 additions & 6 deletions src/Push/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import Parse from 'parse/node';
import deepcopy from 'deepcopy';

export function isPushIncrementing(body) {
if (!body.data || !body.data.badge || typeof body.data.badge != 'string') {
if (!body.data || !body.data.badge) {
return false;
}

const badge = body.data.badge;
if (badge.toLowerCase() == "increment") {
if (typeof badge == 'string' && badge.toLowerCase() == "increment") {
return true;
}

const incrementby = 'incrementby'; // make a variable to reduce likelihood of a typo below
return badge.toLowerCase().startsWith(incrementby) &&
parseInt(badge.substring(incrementby.length), 10) == badge.substring(incrementby.length) &&
parseInt(badge.substring(incrementby.length), 10) > 0;
return typeof badge == 'object' && 'increment' in badge && Number(badge.increment);
}

const localizableKeys = ['alert', 'title'];
Expand Down