diff --git a/web/js/contacts.js b/web/js/contacts.js index b3164d3..09f4e6e 100644 --- a/web/js/contacts.js +++ b/web/js/contacts.js @@ -14,7 +14,7 @@ function contacts_process_event(contacts, our_pubkey, ev) { } } } - + /* contacts_push_relay sends your contact list to the desired relay. */ function contacts_push_relay(contacts, relay) { @@ -77,6 +77,8 @@ async function contacts_load(model) { return dbcall(_contacts_load); } +// TODO move database methods to it's own file + async function dbcall(fn) { return new Promise((resolve, reject) => { var open = indexedDB.open("damus", 4); @@ -95,3 +97,26 @@ async function dbcall(fn) { }; }); } + +async function dbclear() { + function _dbclear(ev, resolve, reject) { + const stores = ["friends", "events"]; + const db = ev.target.result; + const tx = db.transaction(stores, "readwrite"); + tx.oncomplete = (ev) => { + db.close(); + resolve(); + log_debug("cleared database"); + } + tx.onerror = (ev) => { + db.close(); + log_error(`tx errorCode: ${ev.request.errorCode}`); + reject(ev); + }; + for (const store of stores) { + tx.objectStore(store).clear(); + tx.objectStore(store).clear(); + } + } + return dbcall(_dbclear); +} diff --git a/web/js/ui/util.js b/web/js/ui/util.js index 4297a95..986d2d0 100644 --- a/web/js/ui/util.js +++ b/web/js/ui/util.js @@ -158,9 +158,10 @@ function close_reply() { modal.classList.add("closed"); } -function press_logout() { +async function press_logout() { if (confirm("Are you sure you want to sign out?")) { localStorage.clear(); + await dbclear(); window.location.href = url.toString() } }