Skip to content
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

feat: Add dismissal-date property to Live Activity notifications #152

Merged
merged 6 commits into from
Sep 16, 2024
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
1 change: 1 addition & 0 deletions doc/notification.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ This table shows the name of the setter, with the key-path of the underlying pro
| `staleDate` | `aps.staleDate` | `Number` |
| `event` | `aps.event` | `String` |
| `contentState` | `aps.content-state` | `Object` |
| `dismissalDate` | `aps.dismissal-date` | `Number` |
| `mdm` | `mdm` | `String` |

When the notification is transmitted these properties will be added to the output before encoding.
Expand Down
6 changes: 6 additions & 0 deletions lib/notification/apsProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ module.exports = {
}
},

set dismissalDate(value) {
if (typeof value === 'number' || value === undefined) {
this.aps['dismissal-date'] = value;
}
},

set contentAvailable(value) {
if (value === true || value === 1) {
this.aps['content-available'] = 1;
Expand Down
1 change: 1 addition & 0 deletions lib/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Notification.prototype = require('./apsProperties');
'staleDate',
'event',
'contentState',
'dismissalDate'
].forEach(propName => {
const methodName = 'set' + propName[0].toUpperCase() + propName.slice(1);
Notification.prototype[methodName] = function (value) {
Expand Down
26 changes: 26 additions & 0 deletions test/notification/apsProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,32 @@ describe('Notification', function () {
});
});

describe('dismissal-date', function () {
it('defaults to undefined', function () {
expect(compiledOutput()).to.not.have.nested.property('aps.dismissal-date');
});

it('can be set to a number', function () {
note.dismissalDate = 123456;

expect(compiledOutput()).to.have.nested.property('aps.dismissal-date', 123456);
});

it('can be set to undefined', function () {
note.dismissalDate = 123456;
note.dismissalDate = undefined;

expect(compiledOutput()).to.not.have.nested.property('aps.dismissal-date');
});

describe('setDismissalDate', function () {
it('is chainable', function () {
expect(note.setDismissalDate(123456)).to.equal(note);
expect(compiledOutput()).to.have.nested.property('aps.dismissal-date', 123456);
});
});
});

describe('timestamp', function () {
it('defaults to undefined', function () {
expect(compiledOutput()).to.not.have.nested.property('aps.timestamp');
Expand Down
Loading