Use base64 strings for incoming message cache instead of binary

This commit is contained in:
Scott Nonnenberg 2018-08-09 17:28:51 -07:00
parent 9eefc0c29b
commit 7983300f4a
7 changed files with 62 additions and 28 deletions

View file

@ -338,7 +338,8 @@
db,
clearStores: Whisper.Database.clearStores,
handleDOMException: Whisper.Database.handleDOMException,
arrayBufferToString: textsecure.MessageReceiver.arrayBufferToString,
arrayBufferToString:
textsecure.MessageReceiver.arrayBufferToStringBase64,
countCallback: count => {
window.log.info(`Migration: ${count} messages complete`);
showMigrationStatus(count);

View file

@ -59,7 +59,6 @@ module.exports = {
getUnprocessedById,
saveUnprocessed,
saveUnprocesseds,
updateUnprocessed,
removeUnprocessed,
removeAllUnprocessed,
@ -374,19 +373,6 @@ async function saveUnprocesseds(arrayOfUnprocessed, { forceSave } = {}) {
});
}
async function updateUnprocessed(id, updates) {
const existing = await channels.getUnprocessedById(id);
if (!existing) {
throw new Error(`Unprocessed id ${id} does not exist in the database!`);
}
const toSave = {
...existing,
...updates,
};
await saveUnprocessed(toSave);
}
async function removeUnprocessed(id) {
await channels.removeUnprocessed(id);
}

View file

@ -86,6 +86,11 @@ async function migrateToSQL({
forEach(array, item => {
// In the new database, we can't store ArrayBuffers, so we turn these two fields
// into strings like MessageReceiver now does before save.
// Need to set it to version two, since we're using Base64 strings now
// eslint-disable-next-line no-param-reassign
item.version = 2;
if (item.envelope) {
// eslint-disable-next-line no-param-reassign
item.envelope = arrayBufferToString(item.envelope);

View file

@ -942,6 +942,9 @@
getAllUnprocessed() {
return window.Signal.Data.getAllUnprocessed();
},
getUnprocessedById(id) {
return window.Signal.Data.getUnprocessedById(id, { Unprocessed });
},
addUnprocessed(data) {
// We need to pass forceSave because the data has an id already, which will cause
// an update instead of an insert.
@ -950,8 +953,8 @@
Unprocessed,
});
},
updateUnprocessed(id, updates) {
return window.Signal.Data.updateUnprocessed(id, updates, { Unprocessed });
saveUnprocessed(data) {
return window.Signal.Data.saveUnprocessed(data, { Unprocessed });
},
removeUnprocessed(id) {
return window.Signal.Data.removeUnprocessed(id, { Unprocessed });