From 087981bb9c034adcda3755457c3e624c73e77eec Mon Sep 17 00:00:00 2001 From: Martin Man Date: Fri, 12 Nov 2021 12:31:43 +0100 Subject: [PATCH 1/2] add support for "interruption-level" and "target-content-id" --- doc/notification.markdown | 3 ++ index.d.ts | 10 +++++- lib/notification/apsProperties.js | 16 +++++++++ test/notification/apsProperties.js | 52 ++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/doc/notification.markdown b/doc/notification.markdown index a94b228a..91b00fce 100644 --- a/doc/notification.markdown +++ b/doc/notification.markdown @@ -11,6 +11,7 @@ let notification = new apn.Notification({ alert: "Hello, world!", sound: "chime.caf", mutableContent: 1, + interruptionLevel: "time-sensitive", payload: { "sender": "node-apn", }, @@ -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` | diff --git a/index.d.ts b/index.d.ts index 331b8f2d..37a48c21 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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. */ diff --git a/lib/notification/apsProperties.js b/lib/notification/apsProperties.js index 7d67b6e9..7fa7d81e 100644 --- a/lib/notification/apsProperties.js +++ b/lib/notification/apsProperties.js @@ -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; }, diff --git a/test/notification/apsProperties.js b/test/notification/apsProperties.js index 7ab4fbfc..6d2d2f9a 100644 --- a/test/notification/apsProperties.js +++ b/test/notification/apsProperties.js @@ -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"); From 7599e7bf1edd11274a4d17cb78e8717a62115e57 Mon Sep 17 00:00:00 2001 From: Martin Man Date: Fri, 12 Nov 2021 12:58:32 +0100 Subject: [PATCH 2/2] generate setter for targetContentIdentifier and interruptionLevel --- lib/notification/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/notification/index.js b/lib/notification/index.js index 8abd0b41..eaff32be 100644 --- a/lib/notification/index.js +++ b/lib/notification/index.js @@ -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) {