Skip to content

Commit 6cba009

Browse files
author
Marvel Mathew
committed
Support expiration_interval for immediate pushes
1 parent 6679c2c commit 6cba009

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Controllers/PushController.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { applyDeviceTokenExists } from '../Push/utils';
77

88
export class PushController {
99

10-
sendPush(body = {}, where = {}, config, auth, onPushStatusSaved = () => {}) {
10+
sendPush(body = {}, where = {}, config, auth, onPushStatusSaved = () => {}, now = new Date()) {
1111
if (!config.hasPushSupport) {
1212
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
1313
'Missing push configuration');
@@ -16,13 +16,17 @@ export class PushController {
1616
// Replace the expiration_time and push_time with a valid Unix epoch milliseconds time
1717
body.expiration_time = PushController.getExpirationTime(body);
1818
body.expiration_interval = PushController.getExpirationInterval(body);
19-
2019
if (body.expiration_time && body.expiration_interval) {
2120
throw new Parse.Error(
2221
Parse.Error.PUSH_MISCONFIGURED,
2322
'Both expiration_time and expiration_interval cannot be set');
2423
}
2524

25+
// Immediate push
26+
if (body.expiration_interval && !body.hasOwnProperty('push_time')) {
27+
body.expiration_time = new Date(now.valueOf() + body.expiration_interval);
28+
}
29+
2630
const pushTime = PushController.getPushTime(body);
2731
if (pushTime && pushTime.date !== 'undefined') {
2832
body['push_time'] = PushController.formatPushTime(pushTime);

0 commit comments

Comments
 (0)