From a3c5b0959fce9dd96a6dbef23b1ce5fb8bf8c0d2 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 11 May 2015 16:15:47 -0700 Subject: [PATCH] Port textsecure.storage.impl to indexeddb --- js/axolotl_store.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/js/axolotl_store.js b/js/axolotl_store.js index 7f23f3dd..04678081 100644 --- a/js/axolotl_store.js +++ b/js/axolotl_store.js @@ -83,6 +83,42 @@ 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() {}