Skip to content

Commit

Permalink
Merge pull request #7375 from ps2/fix-apns-expiration
Browse files Browse the repository at this point in the history
Fix expiration time on remote notifications for Loop
  • Loading branch information
bewest authored Apr 21, 2022
2 parents ad1bcbf + d080b95 commit d53f574
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/server/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ function init (env, ctx) {
payload["override-duration-minutes"] = parseInt(data.duration);
}
alert = data.reasonDisplay + " Temporary Override";
} else if (data.eventType === 'Remote Carbs Entry') {
} else if (data.eventType === 'Remote Carbs Entry') {
payload["carbs-entry"] = parseFloat(data.remoteCarbs);
if(payload["carbs-entry"] > 0.0 ) {
if(payload["carbs-entry"] > 0.0 ) {
payload["absorption-time"] = 3.0;
if (data.remoteAbsorption !== undefined && parseFloat(data.remoteAbsorption) > 0.0) {
payload["absorption-time"] = parseFloat(data.remoteAbsorption);
Expand All @@ -83,19 +83,19 @@ function init (env, ctx) {
}
alert = "Remote Carbs Entry: "+payload["carbs-entry"]+" grams\n";
alert += "Absorption Time: "+payload["absorption-time"]+" hours";
} else {
} else {
completion("Loop remote carbs failed. Incorrect carbs entry: ", data.remoteCarbs);
return;
}
} else if (data.eventType === 'Remote Bolus Entry') {

} else if (data.eventType === 'Remote Bolus Entry') {
payload["bolus-entry"] = parseFloat(data.remoteBolus);
if(payload["bolus-entry"] > 0.0 ) {
if(payload["bolus-entry"] > 0.0 ) {
alert = "Remote Bolus Entry: "+payload["bolus-entry"]+" U\n";
if (data.otp !== undefined && data.otp.length > 0) {
payload["otp"] = ""+data.otp
}
} else {
} else {
completion("Loop remote bolus failed. Incorrect bolus entry: ", data.remoteBolus);
return;
}
Expand All @@ -112,11 +112,18 @@ function init (env, ctx) {
alert += " - " + data.enteredBy
}

// Track time notification was sent
let now = new Date()
payload['sent-at'] = now.toISOString();

// Expire after 5 minutes.
let expiration = new Date(now.getTime() + 5 * 60 * 1000)
payload['expiration'] = expiration.toISOString();

let notification = new apn.Notification();
notification.alert = alert;
notification.topic = loopSettings.bundleIdentifier;
notification.contentAvailable = 1;
notification.expiry = Math.round((Date.now() / 1000)) + 60 * 5; // Allow this to enact within 5 minutes.
notification.payload = payload;

provider.send(notification, [loopSettings.deviceToken]).then( (response) => {
Expand Down

0 comments on commit d53f574

Please sign in to comment.