omemo keyring
This commit is contained in:
@@ -65,6 +65,41 @@ var ChatOmemoDB = {
|
||||
return promise;
|
||||
},
|
||||
|
||||
// All the decrypted bodies, for the key backup (Account.omemoBackup)
|
||||
getAllMessages: async function() {
|
||||
return new Promise(resolve => {
|
||||
var tx = ChatOmemoDB.db.result.transaction(ChatOmemoDB.storeName, 'readonly');
|
||||
var request = tx.objectStore(ChatOmemoDB.storeName).getAll();
|
||||
request.onsuccess = function(event) {
|
||||
resolve(event.target.result.filter(m => typeof m.body == 'string'));
|
||||
}
|
||||
request.onerror = function() {
|
||||
resolve([]);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Restore them without overwriting what this browser already decrypted
|
||||
putMissingMessages: async function(messages) {
|
||||
return new Promise(resolve => {
|
||||
var tx = ChatOmemoDB.db.result.transaction(ChatOmemoDB.storeName, 'readwrite');
|
||||
var os = tx.objectStore(ChatOmemoDB.storeName);
|
||||
|
||||
messages.forEach(m => {
|
||||
if (typeof m.id != 'string' || typeof m.body != 'string') return;
|
||||
|
||||
os.get(m.id).onsuccess = function(event) {
|
||||
if (!event.target.result || typeof event.target.result.body != 'string') {
|
||||
os.put({"id" : m.id, "body" : m.body});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tx.oncomplete = () => resolve();
|
||||
tx.onerror = () => resolve();
|
||||
});
|
||||
},
|
||||
|
||||
getMessage: async function(id) {
|
||||
let promise = new Promise(resolve => {
|
||||
if (id in ChatOmemoDB.cachedMessages) {
|
||||
|
||||
Reference in New Issue
Block a user