diff --git a/index.html b/index.html index 86496cc..a506ac9 100644 --- a/index.html +++ b/index.html @@ -23,11 +23,12 @@ }, //Required for Supernode operations - SNStorageID: "FEzk75EGMPEQMrCuPosGiwuK162hcEu49E", + SNStorageID: "FNaN9McoBAEFUjkRmNQRYLmBF8SpS7Tgfk", supernodes: {}, //each supnernode must be stored as floID : {uri:,pubKey:} //for app - application: "messenger", + application: "messenger", + adminID: "FMRsefPydWznGWneLqi4ABeQAJeFvtS3aQ", pubKeys: {}, contacts: {}, appendix: {} @@ -78,30 +79,33 @@ } }) }) - + //invoke the startup functions floDapps.launchStartUp().then(result => { console.log(result) document.getElementById("greet_tag").textContent = myFloID - //load messages from IDB and render them - reactor.dispatchEvent("startUpSuccessLog", `Loading Data! Please Wait...`) - messenger.loadDataFromIDB().then(data => { - floGlobals.pubKeys = data.pubKeys; - floGlobals.contacts = data.contacts; - floGlobals.settings = data.settings; + //load messages from IDB and render them + console.log(`Loading Data! Please Wait...`) + messenger.initUserDB().then(result => { + console.log(result) + messenger.loadDataFromIDB().then(data => { + console.log(data) floGlobals.appendix = data.appendix; renderContactList(floGlobals.contacts) renderMailContactList(floGlobals.contacts) renderMessages(data.messages, false) renderMailList(data.mails, false) renderMarked(data.marked) - reactor.dispatchEvent("startUpSuccessLog", `Load Successful!`) + messenger.refreshInbox(renderLiveUI) + .then(rqID => console.log("reqID:", rqID)) + .catch(e => console.error("request error:", e)) + console.log(`Load Successful!`) //hide loading screen loadingPage.classList.add("hide-completely") mainPage.classList.remove('hide-completely') chatSection.classList.add('hide-completely') mailSection.classList.add('hide-completely') - refreshAgain() + //refreshAgain() document.getElementById('chat_page_button').click() if(privKeyNotSecured){ notify("Private key is not secured with password. Remember to secure the private key in settings", "warn", '') @@ -111,9 +115,11 @@ document.getElementById("secure_key").textContent = 'Change password' } }).catch(error => { - reactor.dispatchEvent("startUpErrorLog", `Failed to load data`) + //console.error(`Failed to load data`) notify(error, "error") }) + }) + }).catch(error => notify(error, "error")) } @@ -776,6 +782,20 @@ let currentDate, currentFloID + function renderLiveUI(data) { + console.log(data) + renderMessages(data.messages); + renderMailList(data.mails) + if(Object.keys(data.messages).length && activePage.button !== chatPageButton){ + chatPageButton.setAttribute('data-notifications', Object.keys(data.messages).length) + notify(`${Object.keys(data.messages).length} new message(s)`) + } + if(Object.keys(data.mails).length && activePage.button !== mailPageButton){ + mailPageButton.setAttribute('data-notifications', Object.keys(data.mails).length) + notify(`${Object.keys(data.mails).length} new mail(s)`) + } + } + function randomHsl(saturation = 90, lightness = 50) { let hue = Math.random() * 360 let color = { @@ -1192,6 +1212,7 @@ let refreshing = false function refresh(){ + return if(refreshing) return; refreshing = true messenger.refreshInbox().then(data => { @@ -1405,7 +1426,6 @@ function renderMessages(data, markUnread = true) { let floID - console.log(data) for (m in data) { floID = data[m].floID render.messageBubble(data[m].floID, data[m].message, data[m].time, data[m].category) @@ -1549,85 +1569,9289 @@ } - + + + + + + + +