Skip to content

Fixed error when sending pushes to one pushType #6

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

Merged
merged 2 commits into from
Mar 30, 2016
Merged
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
29 changes: 16 additions & 13 deletions src/ParsePushAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,22 @@ export class ParsePushAdapter {
for (let pushType in deviceMap) {
let sender = this.senderMap[pushType];
let devices = deviceMap[pushType];
if (!sender) {
log.verbose(LOG_PREFIX, `Can not find sender for push type ${pushType}, ${data}`)
let results = devices.map((device) => {
return Promise.resolve({
device,
transmitted: false,
response: {'error': `Can not find sender for push type ${pushType}, ${data}`}
})
});
sendPromises.push(Promise.all(results));
} else {
sendPromises.push(sender.send(data, devices));
}
if(devices.length > 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you use Array.isArray(devices) && devices.length > 0 instead? This way we'll completely eliminate any possible problems,

{
if (!sender) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you use spaces instead of tabs and length 2 instead of 4?

log.verbose(LOG_PREFIX, `Can not find sender for push type ${pushType}, ${data}`)
let results = devices.map((device) => {
return Promise.resolve({
device,
transmitted: false,
response: {'error': `Can not find sender for push type ${pushType}, ${data}`}
})
});
sendPromises.push(Promise.all(results));
} else {
sendPromises.push(sender.send(data, devices));
}
}
}
return Promise.all(sendPromises).then((promises) => {
// flatten all
Expand Down