Format updates to js/database.js

pull/1/head
Scott Nonnenberg 7 years ago committed by Scott Nonnenberg
parent 3a151393c5
commit 3527740598
No known key found for this signature in database
GPG Key ID: 5F82280C35134661

@ -23,5 +23,6 @@ test/views/*.js
!js/views/debug_log_view.js !js/views/debug_log_view.js
!js/views/file_input_view.js !js/views/file_input_view.js
!js/views/inbox_view.js !js/views/inbox_view.js
!js/database.js
!main.js !main.js
!prepare_build.js !prepare_build.js

@ -107,6 +107,7 @@ module.exports = function(grunt) {
'!js/modules/**/*.js', '!js/modules/**/*.js',
'!js/views/debug_log_view.js', '!js/views/debug_log_view.js',
'!js/signal_protocol_store.js', '!js/signal_protocol_store.js',
'!js/database.js',
'_locales/**/*' '_locales/**/*'
], ],
options: { jshintrc: '.jshintrc' }, options: { jshintrc: '.jshintrc' },

@ -1,9 +1,10 @@
/* /* global Whisper: false */
* vim: ts=4:sw=4:expandtab /* eslint-disable more/no-then */
*/
// eslint-disable-next-line func-names
(function () { (function () {
'use strict'; 'use strict';
window.Whisper = window.Whisper || {}; window.Whisper = window.Whisper || {};
window.Whisper.Database = window.Whisper.Database || {}; window.Whisper.Database = window.Whisper.Database || {};
window.Whisper.Database.id = window.Whisper.Database.id || 'signal'; window.Whisper.Database.id = window.Whisper.Database.id || 'signal';
@ -11,102 +12,113 @@
Whisper.Database.migrations = [ Whisper.Database.migrations = [
{ {
version: "12.0", version: '12.0',
migrate: function(transaction, next) { migrate(transaction, next) {
console.log('migration 1.0'); console.log('migration 1.0');
console.log('creating object stores'); console.log('creating object stores');
var messages = transaction.db.createObjectStore("messages"); const messages = transaction.db.createObjectStore('messages');
messages.createIndex("conversation", ["conversationId", "received_at"], { unique: false }); messages.createIndex('conversation', ['conversationId', 'received_at'], {
messages.createIndex("receipt", "sent_at", { unique: false }); unique: false,
});
messages.createIndex('receipt', 'sent_at', { unique: false });
messages.createIndex('unread', ['conversationId', 'unread'], { unique: false }); messages.createIndex('unread', ['conversationId', 'unread'], { unique: false });
messages.createIndex('expires_at', 'expires_at', { unique: false }); messages.createIndex('expires_at', 'expires_at', { unique: false });
var conversations = transaction.db.createObjectStore("conversations"); const conversations = transaction.db.createObjectStore('conversations');
conversations.createIndex("inbox", "active_at", { unique: false }); conversations.createIndex('inbox', 'active_at', { unique: false });
conversations.createIndex("group", "members", { unique: false, multiEntry: true }); conversations.createIndex('group', 'members', {
conversations.createIndex("type", "type", { unique: false }); unique: false,
conversations.createIndex("search", "tokens", { unique: false, multiEntry: true }); multiEntry: true,
});
conversations.createIndex('type', 'type', {
unique: false,
});
conversations.createIndex('search', 'tokens', {
unique: false,
multiEntry: true,
});
var groups = transaction.db.createObjectStore('groups'); transaction.db.createObjectStore('groups');
var sessions = transaction.db.createObjectStore('sessions'); transaction.db.createObjectStore('sessions');
var identityKeys = transaction.db.createObjectStore('identityKeys'); transaction.db.createObjectStore('identityKeys');
var preKeys = transaction.db.createObjectStore("preKeys"); transaction.db.createObjectStore('preKeys');
var signedPreKeys = transaction.db.createObjectStore("signedPreKeys"); transaction.db.createObjectStore('signedPreKeys');
var items = transaction.db.createObjectStore("items"); transaction.db.createObjectStore('items');
console.log('creating debug log'); console.log('creating debug log');
var debugLog = transaction.db.createObjectStore("debug"); transaction.db.createObjectStore('debug');
next(); next();
} },
}, },
{ {
version: "13.0", version: '13.0',
migrate: function(transaction, next) { migrate(transaction, next) {
console.log('migration 13.0'); console.log('migration 13.0');
console.log('Adding fields to identity keys'); console.log('Adding fields to identity keys');
var identityKeys = transaction.objectStore('identityKeys'); const identityKeys = transaction.objectStore('identityKeys');
var request = identityKeys.openCursor(); const request = identityKeys.openCursor();
var promises = []; const promises = [];
request.onsuccess = function(event) { request.onsuccess = (event) => {
var cursor = event.target.result; const cursor = event.target.result;
if (cursor) { if (cursor) {
var attributes = cursor.value; const attributes = cursor.value;
attributes.timestamp = 0; attributes.timestamp = 0;
attributes.firstUse = false; attributes.firstUse = false;
attributes.nonblockingApproval = false; attributes.nonblockingApproval = false;
attributes.verified = 0; attributes.verified = 0;
promises.push(new Promise(function(resolve, reject) { promises.push(new Promise(((resolve, reject) => {
var putRequest = identityKeys.put(attributes, attributes.id); const putRequest = identityKeys.put(attributes, attributes.id);
putRequest.onsuccess = resolve; putRequest.onsuccess = resolve;
putRequest.onerror = function(e) { putRequest.onerror = (e) => {
console.log(e); console.log(e);
reject(e); reject(e);
}; };
})); })));
cursor.continue(); cursor.continue();
} else { } else {
// no more results // no more results
Promise.all(promises).then(function() { Promise.all(promises).then(() => {
next(); next();
}); });
} }
}; };
request.onerror = function(event) { request.onerror = (event) => {
console.log(event); console.log(event);
}; };
} },
}, },
{ {
version: "14.0", version: '14.0',
migrate: function(transaction, next) { migrate(transaction, next) {
console.log('migration 14.0'); console.log('migration 14.0');
console.log('Adding unprocessed message store'); console.log('Adding unprocessed message store');
var unprocessed = transaction.db.createObjectStore('unprocessed'); const unprocessed = transaction.db.createObjectStore('unprocessed');
unprocessed.createIndex('received', 'timestamp', { unique: false }); unprocessed.createIndex('received', 'timestamp', { unique: false });
next(); next();
} },
}, },
{ {
version: "15.0", version: '15.0',
migrate: function(transaction, next) { migrate(transaction, next) {
console.log('migration 15.0'); console.log('migration 15.0');
console.log('Adding messages index for de-duplication'); console.log('Adding messages index for de-duplication');
var messages = transaction.objectStore('messages'); const messages = transaction.objectStore('messages');
messages.createIndex('unique', ['source', 'sourceDevice', 'sent_at'], { unique: true }); messages.createIndex('unique', ['source', 'sourceDevice', 'sent_at'], {
unique: true,
});
next(); next();
} },
}, },
{ {
version: "16.0", version: '16.0',
migrate: function(transaction, next) { migrate(transaction, next) {
console.log('migration 16.0'); console.log('migration 16.0');
console.log('Dropping log table, since we now log to disk'); console.log('Dropping log table, since we now log to disk');
var messages = transaction.db.deleteObjectStore('debug'); transaction.db.deleteObjectStore('debug');
next(); next();
} },
} },
]; ];
}()); }());

Loading…
Cancel
Save