Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/sendGCM.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ module.exports = (regIds, data, settings) => {
title_loc_key: data.titleLocKey, // Android, iOS
title_loc_args: data.titleLocArgs, // Android, iOS
};
let custom = typeof data.custom === 'string' ? { message: data.custom } : {};

let custom;
if (typeof data.custom === 'string') {
custom = {
message: data.custom,
Expand All @@ -81,7 +81,7 @@ module.exports = (regIds, data, settings) => {
custom.sound = custom.sound || data.sound || undefined;
custom.icon = custom.icon || data.icon || undefined;
custom.msgcnt = custom.msgcnt || data.badge || undefined;
if (opts.phonegap === true) {
if (opts.phonegap === true && data.contentAvailable) {
custom['content-available'] = 1;
}

Expand Down
16 changes: 10 additions & 6 deletions test/send/sendGCM.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const data = {
title: 'title',
body: 'body',
sound: 'mySound.aiff',
contentAvailable: true,
custom: {
sender: 'appfeel-test'
},
Expand Down Expand Up @@ -134,8 +135,10 @@ describe('push-notifications-gcm', () => {
});

describe('send push notifications in phonegap-push compatibility mode', () => {
const push = new PN({
phonegap: true
const pushPhoneGap = new PN({
gcm: {
phonegap: true
}
});

const test = (err, results, done) => {
Expand Down Expand Up @@ -166,11 +169,12 @@ describe('push-notifications-gcm', () => {
registrationTokens.forEach(regId => expect(regIds).to.include(regId));
expect(retries).to.be.a('number');
expect(message).to.be.instanceOf(gcm.Message);
expect(message).to.not.have.property('params.notification');
expect(message.notification).to.be.undefined;
expect(message).to.have.deep.property('params.data.sender', data.custom.sender);
expect(message).to.have.deep.property('params.data.title', data.title);
expect(message).to.have.deep.property('params.data.message', data.body);
expect(message).to.have.deep.property('params.data.sound', data.sound);
expect(message).to.have.deep.property('params.data.content-available', 1);
cb(null, {
multicast_id: 'abc',
success: registrationTokens.length,
Expand All @@ -189,15 +193,15 @@ describe('push-notifications-gcm', () => {
});

it('all responses should be successful (callback)', (done) => {
pn.send(regIds, data, (err, results) => test(err, results, done));
pushPhoneGap.send(regIds, data, (err, results) => test(err, results, done));
});

it('all responses should be successful (promise)', (done) => {
pn.send(regIds, data)
pushPhoneGap.send(regIds, data)
.then(results => test(null, results, done))
.catch(done);
});
})
});

{
const test = (err, results, done) => {
Expand Down