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;