Skip to content

Commit a3bcbcb

Browse files
authored
feat: Add support for notification push type widgets (#194)
1 parent 4cea94b commit a3bcbcb

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

index.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ interface Aps {
120120
badge?: number
121121
sound?: string | ApsSound
122122
"content-available"?: undefined | 1
123+
"content-changed"?: undefined | true
123124
"mutable-content"?: undefined | 1
124125
"url-args"?: string[]
125126
category?: string
@@ -267,7 +268,7 @@ export class MultiProvider extends EventEmitter {
267268
shutdown(callback?: () => void): Promise<void>;
268269
}
269270

270-
export type NotificationPushType = 'background' | 'alert' | 'voip' | 'pushtotalk' | 'liveactivity' | 'location' | 'complication' | 'fileprovider' | 'mdm';
271+
export type NotificationPushType = 'background' | 'alert' | 'voip' | 'pushtotalk' | 'liveactivity' | 'location' | 'complication' | 'fileprovider' | 'mdm' | 'widgets';
271272

272273
export type ChannelAction = 'create' | 'read' | 'readAll' | 'delete';
273274

@@ -366,6 +367,10 @@ export class Notification {
366367
*
367368
*/
368369
public mutableContent: boolean;
370+
/**
371+
* Setting this to true will specify "content-changed" in the payload when it is compiled
372+
*/
373+
public contentChanged: boolean;
369374
/**
370375
* The value to specify for the `mdm` field where applicable.
371376
*/

lib/notification/apsProperties.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ module.exports = {
145145
}
146146
},
147147

148+
set contentChanged(value) {
149+
if (value === true || value === 1) {
150+
this.aps['content-changed'] = true;
151+
} else {
152+
this.aps['content-changed'] = undefined;
153+
}
154+
},
155+
148156
set mdm(value) {
149157
this._mdm = value;
150158
},

lib/notification/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Notification.prototype = require('./apsProperties');
4545
'sound',
4646
'contentAvailable',
4747
'mutableContent',
48+
'contentChanged',
4849
'mdm',
4950
'urlArgs',
5051
'category',

test/notification/apsProperties.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,38 @@ describe('Notification', function () {
761761
});
762762
});
763763

764+
describe('content-changed', function () {
765+
it('defaults to undefined', function () {
766+
expect(compiledOutput()).to.not.have.nested.deep.property('aps.content-changed');
767+
});
768+
769+
it('can be set to a boolean value', function () {
770+
note.contentChanged = true;
771+
772+
expect(compiledOutput()).to.have.nested.deep.property('aps.content-changed', true);
773+
});
774+
775+
it('can be set to `1`', function () {
776+
note.contentChanged = 1;
777+
778+
expect(compiledOutput()).to.have.nested.deep.property('aps.content-changed', true);
779+
});
780+
781+
it('can be set to undefined', function () {
782+
note.contentChanged = true;
783+
note.contentChanged = undefined;
784+
785+
expect(compiledOutput()).to.not.have.nested.deep.property('aps.content-changed');
786+
});
787+
788+
describe('setContentChanged', function () {
789+
it('is chainable', function () {
790+
expect(note.setContentChanged(true)).to.equal(note);
791+
expect(compiledOutput()).to.have.nested.deep.property('aps.content-changed', true);
792+
});
793+
});
794+
});
795+
764796
describe('mdm', function () {
765797
it('defaults to undefined', function () {
766798
expect(compiledOutput()).to.not.have.nested.deep.property('mdm');

0 commit comments

Comments
 (0)