-
-
Save jlongster/83b8d569a4e34e234747d5344f41a8c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function save(messages) { | |
let db = await getDatabase(); | |
let fileId = prefs.getPrefs().id; | |
let transaction = db.transaction(['messages'], 'readwrite'); | |
let objectStore = transaction.objectStore('messages'); | |
let promise = new Promise((resolve, reject) => { | |
transaction.onerror = e => reject(e); | |
transaction.oncomplete = e => resolve(); | |
}); | |
for (let message of messages) { | |
message = { | |
...message, | |
timestamp: message.timestamp.toString(), | |
fileId | |
}; | |
objectStore.put(message); | |
} | |
// Don't do anything if it fails | |
try { | |
await promise; | |
} catch (e) { | |
console.log('Error while saving web storage:', e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment