Skip to content

add support for "interruption-level" and "target-content-id" #87

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

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions doc/notification.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let notification = new apn.Notification({
alert: "Hello, world!",
sound: "chime.caf",
mutableContent: 1,
interruptionLevel: "time-sensitive",
payload: {
"sender": "node-apn",
},
Expand Down Expand Up @@ -102,6 +103,8 @@ This table shows the name of the setter, with the key-path of the underlying pro
| `sound` | `aps.sound` | `String` or `Object`|
| `contentAvailable` | `aps.content-available` | `1` |
| `mutableContent` | `aps.mutable-content` | `1` |
| `targetContentIdentifier` | `aps.target-content-id` | `String` |
| `interruptionLevel` | `aps.interruption-level` | `String` |
| `urlArgs` | `aps.url-args` | `Array` |
| `category` | `aps.category` | `String` |
| `threadId` | `aps.thread-id` | `String` |
Expand Down
10 changes: 9 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,17 @@ export class Notification {
*/
public contentAvailable: boolean;
/**
*
* Setting this to 1 will specify "mutable-content" in the payload when it is compiled.
*/
public mutableContent: boolean;
/**
* Specify interruption-level of a notification.
*/
public interruptionLevel: string;
/**
* Specify target-content-id of a notification.
*/
public targetContentIdentifier: string;
/**
* The value to specify for the `mdm` field where applicable.
*/
Expand Down
16 changes: 16 additions & 0 deletions lib/notification/apsProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ module.exports = {
}
},

set interruptionLevel(value) {
if (typeof value === "string") {
this.aps["interruption-level"] = value;
} else {
this.aps["interruption-level"] = undefined;
}
},

set targetContentIdentifier(value) {
if (typeof value === "string") {
this.aps["target-content-id"] = value;
} else {
this.aps["target-content-id"] = undefined;
}
},

set mdm(value) {
this._mdm = value;
},
Expand Down
1 change: 1 addition & 0 deletions lib/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Notification.prototype = require("./apsProperties");
["payload", "expiry", "priority", "alert", "body", "locKey",
"locArgs", "title", "subtitle", "titleLocKey", "titleLocArgs", "action",
"actionLocKey", "launchImage", "badge", "sound", "contentAvailable",
"targetContentIdentifier", "interruptionLevel",
"mutableContent", "mdm", "urlArgs", "category", "threadId"].forEach( propName => {
const methodName = "set" + propName[0].toUpperCase() + propName.slice(1);
Notification.prototype[methodName] = function (value) {
Expand Down
52 changes: 52 additions & 0 deletions test/notification/apsProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,58 @@ describe("Notification", function() {
});
});

describe("interruption-level", function() {
it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.deep.property("aps.interruption\-level");
});

it("can be set to a string value", function() {
note.interruptionLevel = "time-sensitive";

expect(compiledOutput()).to.have.deep.property("aps.interruption\-level", "time-sensitive");
});

it("can be set to undefined", function() {
note.interruptionLevel = "passive";
note.interruptionLevel = undefined;

expect(compiledOutput()).to.not.have.deep.property("aps.interruption\-level");
});

describe("setInterruptionLevel", function () {
it("is chainable", function () {
expect(note.setInterruptionLevel("active")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.interruption\-level", "active");
});
});
});

describe("target-content-id", function() {
it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.deep.property("aps.target\-content\-id");
});

it("can be set to a string value", function() {
note.interruptionLevel = "window1";

expect(compiledOutput()).to.have.deep.property("aps.target\-content\-id", "window1");
});

it("can be set to undefined", function() {
note.interruptionLevel = "window1";
note.interruptionLevel = undefined;

expect(compiledOutput()).to.not.have.deep.property("aps.target\-content\-id");
});

describe("setTargetContentIdentifier", function () {
it("is chainable", function () {
expect(note.setTargetContentIdentifier("example")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.target\-content\-id", "example");
});
});
});

describe("mdm", function() {
it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.deep.property("mdm");
Expand Down