Browse Source

Before refactoring

home-view-notification-improvements
Matthew Raymer 12 months ago
parent
commit
36493920f3
  1. 71
      sw_scripts/safari-notifications.js

71
sw_scripts/safari-notifications.js

@ -387,6 +387,72 @@ async function getSettingById(id) {
}); });
} }
async function setMostRecentNotified(id) {
return new Promise((resolve, reject) => {
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
let request = indexedDB.open(dbName);
request.onerror = function(event) {
console.error("Database error: " + event.target.errorCode);
};
request.onsuccess = function(event) {
let db = event.target.result;
let transaction = db.transaction(storeName, "readwrite");
let store = transaction.objectStore(storeName);
let getRequest = store.get(key);
getRequest.onsuccess = function(event) {
let data = event.target.result;
// Only update if the object exists
if (data) {
// Update the specific property
data[propertyToUpdate] = newValue;
// Put the updated object back into the database
let putRequest = store.put(data);
putRequest.onsuccess = function() {
console.error("Record updated successfully");
};
putRequest.onerror = function(event) {
console.error("Error updating record: " + event.target.errorCode);
};
} else {
console.error("Record not found");
}
};
getRequest.onerror = function(event) {
console.error("Error fetching record: " + event.target.errorCode);
};
transaction.oncomplete = function() {
db.close();
};
};
request.onupgradeneeded = function(event) {
let db = event.target.result;
if (!db.objectStoreNames.contains(storeName)) {
db.createObjectStore(storeName);
}
};
});
}
async function fetchAllAccounts() { async function fetchAllAccounts() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let openRequest = indexedDB.open("TimeSafariAccounts"); let openRequest = indexedDB.open("TimeSafariAccounts");
@ -460,9 +526,10 @@ async function getNotificationCount() {
}, },
); );
console.error(did, response.status); console.error(did, response.status);
console.error(await response.json()); const claims = await response.json();
// first claim is the most recent (?)
const most_recent_notified = claims[0]['id']
result = decrypted;
break; break;
} }

Loading…
Cancel
Save