Import and upgrade messages upon save

This commit is contained in:
Daniel Gasienica 2018-04-03 21:14:31 -04:00
parent cf7355bd2f
commit 0faaf52b71

View file

@ -1,3 +1,4 @@
/* global Signal: false */
/* global Whisper: false */ /* global Whisper: false */
/* global dcodeIO: false */ /* global dcodeIO: false */
/* global _: false */ /* global _: false */
@ -810,11 +811,17 @@ function saveMessage(db, message) {
return saveAllMessages(db, [message]); return saveAllMessages(db, [message]);
} }
function saveAllMessages(db, messages) { async function saveAllMessages(db, rawMessages) {
if (!messages.length) { if (rawMessages.length === 0) {
return Promise.resolve(); return Promise.resolve();
} }
const { importMessage, upgradeMessageSchema } = Signal.Migrations;
const importAndUpgrade = async message =>
upgradeMessageSchema(await importMessage(message));
const messages = await Promise.all(rawMessages.map(importAndUpgrade));
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let finished = false; let finished = false;
const finish = (via) => { const finish = (via) => {
@ -931,9 +938,7 @@ async function importConversation(db, dir, options) {
return true; return true;
}); });
if (messages.length > 0) {
await saveAllMessages(db, messages); await saveAllMessages(db, messages);
}
await promiseChain; await promiseChain;
console.log( console.log(