From abc4a93b34acf23932c39b0f5f845edf8d93dd4a Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Sun, 26 Nov 2023 07:54:57 -0500 Subject: [PATCH] Added counting of pending notifications --- sw_scripts/safari-notifications.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/sw_scripts/safari-notifications.js b/sw_scripts/safari-notifications.js index b9fa4e0..f8c5369 100644 --- a/sw_scripts/safari-notifications.js +++ b/sw_scripts/safari-notifications.js @@ -392,9 +392,9 @@ async function setMostRecentNotified(id) { const dbName = "TimeSafari"; const storeName = "settings"; - const key = 1; // The ID of the record you want to update - const propertyToUpdate = "lastNotifiedClaimId"; // The property you want to update - const newValue = id; // The new value for the property + const key = 1; + const propertyToUpdate = "lastNotifiedClaimId"; + const newValue = id; let request = indexedDB.open(dbName); @@ -527,8 +527,25 @@ async function getNotificationCount() { ); console.error(did, response.status); const claims = await response.json(); + // formulate a message back for notifications + let lastNotifiedClaimId = null; + if ('lastNotifiedClaimId' in settings) { + lastNotifiedClaimId = settings['lastNotifiedClaimId']; + } + let newClaims = 0; + // search for id recent notified -- if it exists if not return everything count + for (var i=0; i< response.json()['data'].length; i++) { + let claim = response.json()['data']; + if (claim['id'] == lastNotifiedClaimId) { + break; + } + newClaims++; + } + // make the notification message here + // first claim is the most recent (?) - const most_recent_notified = claims[0]['id'] + const most_recent_notified = claims[0]['id']; + await setMostRecentNotified(most_recent_notified); break;