Skip to content

Commit 6679c2c

Browse files
author
Marvel Mathew
committed
Add support for expiration_interval in Push
1 parent 770aba1 commit 6679c2c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Controllers/PushController.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@ export class PushController {
1212
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
1313
'Missing push configuration');
1414
}
15+
1516
// Replace the expiration_time and push_time with a valid Unix epoch milliseconds time
1617
body.expiration_time = PushController.getExpirationTime(body);
18+
body.expiration_interval = PushController.getExpirationInterval(body);
19+
20+
if (body.expiration_time && body.expiration_interval) {
21+
throw new Parse.Error(
22+
Parse.Error.PUSH_MISCONFIGURED,
23+
'Both expiration_time and expiration_interval cannot be set');
24+
}
25+
1726
const pushTime = PushController.getPushTime(body);
1827
if (pushTime && pushTime.date !== 'undefined') {
1928
body['push_time'] = PushController.formatPushTime(pushTime);
@@ -108,6 +117,19 @@ export class PushController {
108117
return expirationTime.valueOf();
109118
}
110119

120+
static getExpirationInterval(body = {}) {
121+
const hasExpirationInterval = body.hasOwnProperty('expiration_interval');
122+
if (!hasExpirationInterval) {
123+
return;
124+
}
125+
126+
var expirationIntervalParam = body['expiration_interval'];
127+
if (typeof expirationIntervalParam !== 'number' || expirationIntervalParam <= 0) {
128+
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
129+
`expiration_interval must be a number greater than 0`);
130+
}
131+
}
132+
111133
/**
112134
* Get push time from the request body.
113135
* @param {Object} request A request object

0 commit comments

Comments
 (0)