When updating message schema pre-SQLCipher, use legacy save

pull/1/head
Scott Nonnenberg 7 years ago
parent 3b7ee3e2ce
commit b1c6a5fe19

@ -230,7 +230,7 @@
upgradeMessageSchema, upgradeMessageSchema,
maxVersion: MINIMUM_VERSION, maxVersion: MINIMUM_VERSION,
BackboneMessage: Whisper.Message, BackboneMessage: Whisper.Message,
saveMessage: window.Signal.Data.saveMessage, saveMessage: window.Signal.Data.saveLegacyMessage,
} }
); );
window.log.info( window.log.info(
@ -251,7 +251,7 @@
upgradeMessageSchema, upgradeMessageSchema,
getMessagesNeedingUpgrade: getMessagesNeedingUpgrade:
window.Signal.Data.getLegacyMessagesNeedingUpgrade, window.Signal.Data.getLegacyMessagesNeedingUpgrade,
saveMessage: window.Signal.Data.saveMessage, saveMessage: window.Signal.Data.saveLegacyMessage,
maxVersion: MINIMUM_VERSION, maxVersion: MINIMUM_VERSION,
}); });
window.log.info('upgradeMessages: upgrade with index', batchWithIndex); window.log.info('upgradeMessages: upgrade with index', batchWithIndex);
@ -264,6 +264,16 @@
await upgradeMessages(); await upgradeMessages();
const db = await Whisper.Database.open();
await window.Signal.migrateToSQL({
db,
clearStores: Whisper.Database.clearStores,
handleDOMException: Whisper.Database.handleDOMException,
});
// Note: We are not invoking the second set of IndexedDB migrations because it is
// likely that any future migrations will simply extracting things from IndexedDB.
idleDetector = new IdleDetector(); idleDetector = new IdleDetector();
let isMigrationWithIndexComplete = false; let isMigrationWithIndexComplete = false;
window.log.info( window.log.info(
@ -296,16 +306,6 @@
} }
}); });
const db = await Whisper.Database.open();
await window.Signal.migrateToSQL({
db,
clearStores: Whisper.Database.clearStores,
handleDOMException: Whisper.Database.handleDOMException,
});
// Note: We are not invoking the second set of IndexedDB migrations because it is
// likely that any future migrations will simply extracting things from IndexedDB.
// These make key operations available to IPC handlers created in preload.js // These make key operations available to IPC handlers created in preload.js
window.Events = { window.Events = {
getDeviceName: () => textsecure.storage.user.getDeviceName(), getDeviceName: () => textsecure.storage.user.getDeviceName(),

@ -56,6 +56,9 @@
window.hasSignalAccount = number => window.AccountCache[number]; window.hasSignalAccount = number => window.AccountCache[number];
window.Whisper.Message = Backbone.Model.extend({ window.Whisper.Message = Backbone.Model.extend({
// Keeping this for legacy upgrade pre-migrate to SQLCipher
database: Whisper.Database,
storeName: 'messages',
initialize(attributes) { initialize(attributes) {
if (_.isObject(attributes)) { if (_.isObject(attributes)) {
this.set( this.set(

@ -35,6 +35,7 @@ module.exports = {
removeDB, removeDB,
saveMessage, saveMessage,
saveLegacyMessage,
saveMessages, saveMessages,
removeMessage, removeMessage,
_removeMessages, _removeMessages,
@ -205,6 +206,12 @@ async function saveMessage(data, { forceSave } = {}) {
return id; return id;
} }
async function saveLegacyMessage(data, { Message }) {
const message = new Message(data);
await deferredToPromise(message.save());
return message.id;
}
async function saveMessages(arrayOfMessages, { forceSave } = {}) { async function saveMessages(arrayOfMessages, { forceSave } = {}) {
await channels.saveMessages(_cleanData(arrayOfMessages), { forceSave }); await channels.saveMessages(_cleanData(arrayOfMessages), { forceSave });
} }

Loading…
Cancel
Save