|
@ -461,10 +461,10 @@ function updateRecord(store, data) { |
|
|
|
|
|
|
|
|
async function fetchAllAccounts() { |
|
|
async function fetchAllAccounts() { |
|
|
return new Promise((resolve, reject) => { |
|
|
return new Promise((resolve, reject) => { |
|
|
let openRequest = indexedDB.open("TimeSafariAccounts"); |
|
|
const openRequest = indexedDB.open("TimeSafariAccounts"); |
|
|
|
|
|
|
|
|
openRequest.onupgradeneeded = function (event) { |
|
|
openRequest.onupgradeneeded = function (event) { |
|
|
let db = event.target.result; |
|
|
const db = event.target.result; |
|
|
if (!db.objectStoreNames.contains("accounts")) { |
|
|
if (!db.objectStoreNames.contains("accounts")) { |
|
|
db.createObjectStore("accounts", { keyPath: "id" }); |
|
|
db.createObjectStore("accounts", { keyPath: "id" }); |
|
|
} |
|
|
} |
|
@ -474,10 +474,10 @@ async function fetchAllAccounts() { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
openRequest.onsuccess = function (event) { |
|
|
openRequest.onsuccess = function (event) { |
|
|
let db = event.target.result; |
|
|
const db = event.target.result; |
|
|
let transaction = db.transaction("accounts", "readonly"); |
|
|
const transaction = db.transaction("accounts", "readonly"); |
|
|
let objectStore = transaction.objectStore("accounts"); |
|
|
const objectStore = transaction.objectStore("accounts"); |
|
|
let getAllRequest = objectStore.getAll(); |
|
|
const getAllRequest = objectStore.getAll(); |
|
|
|
|
|
|
|
|
getAllRequest.onsuccess = function () { |
|
|
getAllRequest.onsuccess = function () { |
|
|
resolve(getAllRequest.result); |
|
|
resolve(getAllRequest.result); |
|
@ -494,12 +494,8 @@ async function fetchAllAccounts() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function getNotificationCount() { |
|
|
async function getNotificationCount() { |
|
|
let secret = null; |
|
|
|
|
|
let accounts = []; |
|
|
let accounts = []; |
|
|
let result = null; |
|
|
let result = null; |
|
|
if ("secret" in self) { |
|
|
|
|
|
secret = self.secret; |
|
|
|
|
|
const secretUint8Array = self.decodeBase64(secret); |
|
|
|
|
|
// 1 is our master settings ID; see MASTER_SETTINGS_KEY
|
|
|
// 1 is our master settings ID; see MASTER_SETTINGS_KEY
|
|
|
const settings = await getSettingById(1); |
|
|
const settings = await getSettingById(1); |
|
|
let lastNotifiedClaimId = null; |
|
|
let lastNotifiedClaimId = null; |
|
@ -507,42 +503,51 @@ async function getNotificationCount() { |
|
|
lastNotifiedClaimId = settings["lastNotifiedClaimId"]; |
|
|
lastNotifiedClaimId = settings["lastNotifiedClaimId"]; |
|
|
} |
|
|
} |
|
|
const activeDid = settings["activeDid"]; |
|
|
const activeDid = settings["activeDid"]; |
|
|
|
|
|
console.log("safari-not getNotificationsCount last", lastNotifiedClaimId); |
|
|
accounts = await fetchAllAccounts(); |
|
|
accounts = await fetchAllAccounts(); |
|
|
let did = null; |
|
|
let activeAccount = null; |
|
|
for (var i = 0; i < accounts.length; i++) { |
|
|
for (let i = 0; i < accounts.length; i++) { |
|
|
let account = accounts[i]; |
|
|
if (accounts[i]["did"] == activeDid) { |
|
|
let did = account["did"]; |
|
|
activeAccount = accounts[i]; |
|
|
if (did == activeDid) { |
|
|
break; |
|
|
let publicKeyHex = account["publicKeyHex"]; |
|
|
} |
|
|
let identity = account["identity"]; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const headers = { |
|
|
|
|
|
"Content-Type": "application/json", |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const identity = activeAccount && activeAccount["identity"]; |
|
|
|
|
|
if (identity && "secret" in self) { |
|
|
|
|
|
const secret = self.secret; |
|
|
|
|
|
const secretUint8Array = self.decodeBase64(secret); |
|
|
const messageWithNonceAsUint8Array = self.decodeBase64(identity); |
|
|
const messageWithNonceAsUint8Array = self.decodeBase64(identity); |
|
|
const nonce = messageWithNonceAsUint8Array.slice(0, 24); |
|
|
const nonce = messageWithNonceAsUint8Array.slice(0, 24); |
|
|
const message = messageWithNonceAsUint8Array.slice(24, identity.length); |
|
|
const message = messageWithNonceAsUint8Array.slice(24, identity.length); |
|
|
const decoder = new TextDecoder("utf-8"); |
|
|
const decoder = new TextDecoder("utf-8"); |
|
|
const decrypted = self.secretbox.open(message, nonce, secretUint8Array); |
|
|
const decrypted = self.secretbox.open(message, nonce, secretUint8Array); |
|
|
|
|
|
|
|
|
const msg = decoder.decode(decrypted); |
|
|
const msg = decoder.decode(decrypted); |
|
|
const identifier = JSON.parse(JSON.parse(msg)); |
|
|
const identifier = JSON.parse(JSON.parse(msg)); |
|
|
|
|
|
|
|
|
const headers = { |
|
|
|
|
|
"Content-Type": "application/json", |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
headers["Authorization"] = "Bearer " + (await accessToken(identifier)); |
|
|
headers["Authorization"] = "Bearer " + (await accessToken(identifier)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let response = await fetch( |
|
|
console.log("safari-not getNotificationsCount fetch", headers); |
|
|
|
|
|
const response = await fetch( |
|
|
settings["apiServer"] + "/api/v2/report/claims", |
|
|
settings["apiServer"] + "/api/v2/report/claims", |
|
|
{ |
|
|
{ |
|
|
method: "GET", |
|
|
method: "GET", |
|
|
headers: headers, |
|
|
headers: headers, |
|
|
}, |
|
|
}, |
|
|
); |
|
|
); |
|
|
|
|
|
console.log("safari-not getNotificationsCount json", response); |
|
|
if (response.status == 200) { |
|
|
if (response.status == 200) { |
|
|
let json = await response.json(); |
|
|
const json = await response.json(); |
|
|
let claims = json["data"]; |
|
|
console.log("safari-not getNotificationsCount json", json); |
|
|
|
|
|
const claims = json["data"]; |
|
|
let newClaims = 0; |
|
|
let newClaims = 0; |
|
|
for (var i = 0; i < claims.length; i++) { |
|
|
for (let i = 0; i < claims.length; i++) { |
|
|
let claim = claims[i]; |
|
|
const claim = claims[i]; |
|
|
if (claim["id"] === lastNotifiedClaimId) { |
|
|
if (claim["id"] === lastNotifiedClaimId) { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
@ -560,10 +565,7 @@ async function getNotificationCount() { |
|
|
response, |
|
|
response, |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|