Remove remaining traces of localStorage

Add window.storage to the background page, which loads all data from the
'items' store in indexeddb, caching them in memory for synchronous
access, then override textsecure storage to use that in memory store.
pull/749/head
lilia 10 years ago
parent a3c5b0959f
commit 3f37cd21a9

@ -230,6 +230,7 @@
</script>
<script type="text/javascript" src="js/components.js"></script>
<script type="text/javascript" src="js/database.js"></script>
<script type="text/javascript" src="js/storage.js"></script>
<script type="text/javascript" src="js/axolotl_store.js"></script>
<script type="text/javascript" src="js/libtextsecure.js"></script>

@ -83,42 +83,6 @@
var IdentityKey = Model.extend({ storeName: 'identityKeys' });
var Group = Model.extend({ storeName: 'groups' });
var Item = Model.extend({ storeName: 'items' });
var ItemCollection = Backbone.Collection.extend({
model: Item,
storeName: 'items',
database: Whisper.Database,
});
var items = new ItemCollection();
window.textsecure = window.textsecure || {};
window.textsecure.storage = window.textsecure.storage || {};
window.textsecure.storage.impl = {
/*****************************
*** Base Storage Routines ***
*****************************/
put: function(key, value) {
if (value === undefined)
throw new Error("Tried to store undefined");
var item = items.add({id: key, value: value});
item.save();
},
get: function(key, defaultValue) {
var item = items.get("" + key);
if (!item)
return defaultValue;
return item.get('value');
},
remove: function(key) {
var item = items.get("" + key);
if (item) {
items.remove(item);
item.destroy();
}
}
};
items.fetch();
function AxolotlStore() {}

@ -16,10 +16,11 @@
;(function() {
'use strict';
storage.onready(function() {
var messageReceiver;
if (!localStorage.getItem('first_install_ran')) {
localStorage.setItem('first_install_ran', 1);
if (!storage.get('first_install_ran')) {
storage.put('first_install_ran', 1);
extension.navigator.tabs.create("options.html");
}
@ -72,8 +73,8 @@
type : 'incoming'
});
var newUnreadCount = textsecure.storage.get("unreadCount", 0) + 1;
textsecure.storage.put("unreadCount", newUnreadCount);
var newUnreadCount = storage.get("unreadCount", 0) + 1;
storage.put("unreadCount", newUnreadCount);
extension.navigator.setBadgeText(newUnreadCount);
conversation.save().then(function() {
@ -131,4 +132,5 @@
console.log('got delivery receipt for unknown message', pushMessage.source, timestamp);
});
}
});
})();

@ -98,12 +98,12 @@
window.textsecure = window.textsecure || {};
window.textsecure.registration = {
done: function () {
localStorage.setItem("chromiumRegistrationDone", "");
storage.put("chromiumRegistrationDone", "");
extension.trigger('registration_done');
},
isDone: function () {
return localStorage.getItem("chromiumRegistrationDone") !== null;
return storage.get("chromiumRegistrationDone") === "";
},
};

@ -33,9 +33,9 @@
inbox.on('change:unreadCount', function(model, count) {
var prev = model.previous('unreadCount') || 0;
if (count < prev) { // decreased
var newUnreadCount = textsecure.storage.get("unreadCount", 0) - (prev - count);
var newUnreadCount = storage.get("unreadCount", 0) - (prev - count);
setUnreadCount(newUnreadCount);
textsecure.storage.put("unreadCount", newUnreadCount);
storage.put("unreadCount", newUnreadCount);
}
});
@ -52,7 +52,7 @@
extension.on('message', fetch);
fetch();
setUnreadCount(textsecure.storage.get("unreadCount", 0));
setUnreadCount(storage.get("unreadCount", 0));
function setUnreadCount(count) {
if (count > 0) {

@ -20,16 +20,16 @@
Whisper.Notifications = {
isEnabled: function(callback) {
return Notification.permission === 'granted' &&
!localStorage.getItem('disable-notifications');
!storage.get('disable-notifications');
},
enable: function(callback) {
localStorage.removeItem('disable-notifications');
storage.remove('disable-notifications');
Notification.requestPermission(function(status) {
callback(status);
});
},
disable: function() {
localStorage.setItem('disable-notifications', true);
storage.put('disable-notifications', true);
}
};

@ -0,0 +1,70 @@
/* vim: ts=4:sw=4
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
;(function() {
'use strict';
window.Whisper = window.Whisper || {};
var Item = Backbone.Model.extend({
database: Whisper.Database,
storeName: 'items'
});
var ItemCollection = Backbone.Collection.extend({
model: Item,
storeName: 'items',
database: Whisper.Database,
});
var ready = false;
var items = new ItemCollection();
items.on('reset', function() { ready = true; });
items.fetch({reset: true});
window.storage = {
/*****************************
*** Base Storage Routines ***
*****************************/
put: function(key, value) {
if (value === undefined)
throw new Error("Tried to store undefined");
var item = items.add({id: key, value: value});
item.save();
},
get: function(key, defaultValue) {
var item = items.get("" + key);
if (!item)
return defaultValue;
return item.get('value');
},
remove: function(key) {
var item = items.get("" + key);
if (item) {
items.remove(item);
item.destroy();
}
},
onready: function(callback) {
if (ready) {
callback();
} else {
items.on('reset', callback);
}
}
};
window.textsecure = window.textsecure || {};
window.textsecure.storage = window.textsecure.storage || {};
window.textsecure.storage.impl = window.storage;
})();
Loading…
Cancel
Save