From a75a5f0963039fa162b2cc830c477be89fb3458a Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Thu, 9 Sep 2021 20:52:49 -0700 Subject: [PATCH] Add support for target-content-id notification property --- doc/notification.markdown | 41 +++++++++++++++--------------- lib/notification/apsProperties.js | 6 +++++ lib/notification/index.js | 3 ++- test/notification/apsProperties.js | 29 +++++++++++++++++++++ 4 files changed, 58 insertions(+), 21 deletions(-) diff --git a/doc/notification.markdown b/doc/notification.markdown index a94b228a..d0ed1c09 100644 --- a/doc/notification.markdown +++ b/doc/notification.markdown @@ -86,26 +86,27 @@ The setters below provide a cleaner way to set properties defined by the Apple P This table shows the name of the setter, with the key-path of the underlying property it maps to and the expected value type. -| Setter Name | Target Property | Type | -|---------------------|-----------------------------|---------------------| -| `alert` | `aps.alert` | `String` or `Object`| -| `body` | `aps.alert.body` | `String` | -| `locKey` | `aps.alert.loc-key` | `String` | -| `locArgs` | `aps.alert.loc-args` | `Array` | -| `title` | `aps.alert.title` | `String` | -| `titleLocKey` | `aps.alert.title-loc-key` | `String` | -| `titleLocArgs` | `aps.alert.title-loc-args` | `Array` | -| `action` | `aps.alert.action` | `String` | -| `actionLocKey` | `aps.alert.action-loc-key` | `String` | -| `launchImage` | `aps.launch-image` | `String` | -| `badge` | `aps.badge` | `Number` | -| `sound` | `aps.sound` | `String` or `Object`| -| `contentAvailable` | `aps.content-available` | `1` | -| `mutableContent` | `aps.mutable-content` | `1` | -| `urlArgs` | `aps.url-args` | `Array` | -| `category` | `aps.category` | `String` | -| `threadId` | `aps.thread-id` | `String` | -| `mdm` | `mdm` | `String` | +| Setter Name | Target Property | Type | +|----------------------------|-----------------------------|---------------------| +| `alert` | `aps.alert` | `String` or `Object`| +| `body` | `aps.alert.body` | `String` | +| `locKey` | `aps.alert.loc-key` | `String` | +| `locArgs` | `aps.alert.loc-args` | `Array` | +| `title` | `aps.alert.title` | `String` | +| `titleLocKey` | `aps.alert.title-loc-key` | `String` | +| `titleLocArgs` | `aps.alert.title-loc-args` | `Array` | +| `action` | `aps.alert.action` | `String` | +| `actionLocKey` | `aps.alert.action-loc-key` | `String` | +| `launchImage` | `aps.launch-image` | `String` | +| `badge` | `aps.badge` | `Number` | +| `sound` | `aps.sound` | `String` or `Object`| +| `contentAvailable` | `aps.content-available` | `1` | +| `mutableContent` | `aps.mutable-content` | `1` | +| `urlArgs` | `aps.url-args` | `Array` | +| `category` | `aps.category` | `String` | +| `targetContentIdentifier` | `aps.target-content-id` | `String` | +| `threadId` | `aps.thread-id` | `String` | +| `mdm` | `mdm` | `String` | When the notification is transmitted these properties will be added to the output before encoding. diff --git a/lib/notification/apsProperties.js b/lib/notification/apsProperties.js index 7d67b6e9..90fb53f7 100644 --- a/lib/notification/apsProperties.js +++ b/lib/notification/apsProperties.js @@ -116,6 +116,12 @@ module.exports = { } }, + set targetContentIdentifier(value) { + if(typeof value === "string" || value === undefined) { + this.aps["target-content-id"] = value; + } + }, + set threadId(value) { if(typeof value === "string" || value === undefined) { this.aps["thread-id"] = value; diff --git a/lib/notification/index.js b/lib/notification/index.js index 8abd0b41..39d2a3ff 100644 --- a/lib/notification/index.js +++ b/lib/notification/index.js @@ -27,7 +27,8 @@ Notification.prototype = require("./apsProperties"); ["payload", "expiry", "priority", "alert", "body", "locKey", "locArgs", "title", "subtitle", "titleLocKey", "titleLocArgs", "action", "actionLocKey", "launchImage", "badge", "sound", "contentAvailable", -"mutableContent", "mdm", "urlArgs", "category", "threadId"].forEach( propName => { +"mutableContent", "mdm", "urlArgs", "category", "targetContentIdentifier", +"threadId"].forEach( propName => { const methodName = "set" + propName[0].toUpperCase() + propName.slice(1); Notification.prototype[methodName] = function (value) { this[propName] = value; diff --git a/test/notification/apsProperties.js b/test/notification/apsProperties.js index 7ab4fbfc..d0ac02b1 100644 --- a/test/notification/apsProperties.js +++ b/test/notification/apsProperties.js @@ -685,6 +685,35 @@ describe("Notification", function() { }); }); + describe("target-content-id", function() { + it("defaults to undefined", function() { + expect(compiledOutput()) + .to.not.have.nested.property("aps.target\-content\-id"); + }); + + it("can be set to a string", function() { + note.targetContentIdentifier = "the-target-content-id"; + + expect(compiledOutput()).to.have.nested.property("aps.target\-content\-id", + "the-target-content-id"); + }); + + it("can be set to undefined", function() { + note.targetContentIdentifier = "the-target-content-identifier"; + note.targetContentIdentifier = undefined; + + expect(compiledOutput()).to.not.have.nested.property("aps.target\-content\-id"); + }); + + describe("setTargetContentIdentifier", function () { + it("is chainable", function () { + expect(note.setTargetContentIdentifier("the-target-content-id")).to.equal(note); + expect(compiledOutput()).to.have.nested.property("aps.target\-content\-id", + "the-target-content-id"); + }); + }); + }); + describe("thread-id", function() { it("defaults to undefined", function() { expect(compiledOutput()).to.not.have.deep.property("aps.thread\-id");