web: delete db on sign out
This commit is contained in:
parent
5d4e8e7ac4
commit
48ebf9c978
2 changed files with 28 additions and 2 deletions
|
@ -14,7 +14,7 @@ function contacts_process_event(contacts, our_pubkey, ev) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* contacts_push_relay sends your contact list to the desired relay.
|
/* contacts_push_relay sends your contact list to the desired relay.
|
||||||
*/
|
*/
|
||||||
function contacts_push_relay(contacts, relay) {
|
function contacts_push_relay(contacts, relay) {
|
||||||
|
@ -77,6 +77,8 @@ async function contacts_load(model) {
|
||||||
return dbcall(_contacts_load);
|
return dbcall(_contacts_load);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO move database methods to it's own file
|
||||||
|
|
||||||
async function dbcall(fn) {
|
async function dbcall(fn) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var open = indexedDB.open("damus", 4);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -158,9 +158,10 @@ function close_reply() {
|
||||||
modal.classList.add("closed");
|
modal.classList.add("closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
function press_logout() {
|
async function press_logout() {
|
||||||
if (confirm("Are you sure you want to sign out?")) {
|
if (confirm("Are you sure you want to sign out?")) {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
|
await dbclear();
|
||||||
window.location.href = url.toString()
|
window.location.href = url.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue