diff --git a/bower.json b/bower.json index 890d70029..d646d6f38 100644 --- a/bower.json +++ b/bower.json @@ -14,7 +14,8 @@ "tinysort": "git://github.com/Sjeiti/TinySort.git", "underscore": "1.6.0", "backbone": "1.1.2", - "backbone.localStorage": "1.1.7", + "backbone.browserStorage": "*", + "backbone.overview": "*", "strophe": "git@github.com:strophe/strophejs-bower.git#v1.1.3", "strophe.roster": "https://raw.github.com/strophe/strophejs-plugins/b1f364eb6e854ffe844c57add38e885cfeb9b498/roster/strophe.roster.js", "strophe.vcard": "https://raw.github.com/strophe/strophejs-plugins/f5c9e16b463610d501591452cded0359f53aae48/vcard/strophe.vcard.js", @@ -26,8 +27,7 @@ "requirejs-text": "~2.0.12", "requirejs-tpl-jcbrand": "*", "momentjs": "~2.6.0", - "jquery.browser": "~0.0.6", - "backbone.overview": "*" + "jquery.browser": "~0.0.6" }, "exportsOverride": {} } diff --git a/converse.js b/converse.js index 36c21a325..c50e850d3 100644 --- a/converse.js +++ b/converse.js @@ -163,6 +163,7 @@ this.show_controlbox_by_default = false; this.show_only_online_users = false; this.show_toolbar = true; + this.storage = 'session'; this.use_otr_by_default = false; this.use_vcards = true; this.visible_toolbar_buttons = { @@ -204,6 +205,7 @@ 'show_only_online_users', 'show_toolbar', 'sid', + 'storage', 'use_otr_by_default', 'use_vcards', 'xhr_custom_status', @@ -453,9 +455,9 @@ this.initStatus = function (callback) { this.xmppstatus = new this.XMPPStatus(); - var id = b64_sha1('converse.xmppstatus-'+this.bare_jid); - this.xmppstatus.id = id; // Appears to be necessary for backbone.localStorage - this.xmppstatus.localStorage = new Backbone.LocalStorage(id); + var id = b64_sha1('converse.xmppstatus-'+converse.bare_jid); + this.xmppstatus.id = id; // Appears to be necessary for backbone.browserStorage + this.xmppstatus.browserStorage = new Backbone.BrowserStorage[converse.storage](id); this.xmppstatus.fetch({success: callback, error: callback}); }; @@ -483,13 +485,13 @@ this.initRoster = function () { // Set up the roster this.roster = new this.RosterItems(); - this.roster.localStorage = new Backbone.LocalStorage( + this.roster.browserStorage = new Backbone.BrowserStorage[converse.storage]( b64_sha1('converse.rosteritems-'+converse.bare_jid)); this.registerRosterHandler(); this.registerRosterXHandler(); this.registerPresenceHandler(); // Now create the view which will fetch roster items from - // localStorage + // browserStorage this.rosterview = new this.RosterView({'model':this.roster}); }; @@ -569,7 +571,9 @@ this.connection.xmlInput = function (body) { console.log(body); }; this.connection.xmlOutput = function (body) { console.log(body); }; Strophe.log = function (level, msg) { console.log(level+' '+msg); }; - Strophe.error = function (msg) { console.log('ERROR: '+msg); }; + Strophe.error = function (msg) { + console.log('ERROR: '+msg); + }; } this.bare_jid = Strophe.getBareJidFromJid(this.connection.jid); this.domain = Strophe.getDomainFromJid(this.connection.jid); @@ -649,7 +653,7 @@ var height = converse.applyHeightResistance(this.get('height')); if (this.get('box_id') !== 'controlbox') { this.messages = new converse.Messages(); - this.messages.localStorage = new Backbone.LocalStorage( + this.messages.browserStorage = new Backbone.BrowserStorage[converse.storage]( b64_sha1('converse.messages'+this.get('jid')+converse.bare_jid)); this.save({ @@ -1168,7 +1172,7 @@ if (result === true) { this.$el.find('.chat-content').empty(); this.model.messages.reset(); - this.model.messages.localStorage._clear(); + this.model.messages.browserStorage._clear(); } return this; }, @@ -2411,7 +2415,7 @@ }, onConnected: function () { - this.localStorage = new Backbone.LocalStorage( + this.browserStorage = new Backbone.BrowserStorage[converse.storage]( b64_sha1('converse.chatboxes-'+converse.bare_jid)); if (!this.get('controlbox')) { this.add({ @@ -2692,9 +2696,9 @@ this.toggleview = new converse.MinimizedChatsToggleView({ model: new converse.MinimizedChatsToggle() }); - var id = b64_sha1('converse.minchatstoggle'+this.bare_jid); - this.toggleview.model.id = id; // Appears to be necessary for backbone.localStorage - this.toggleview.model.localStorage = new Backbone.LocalStorage(id); + var id = b64_sha1('converse.minchatstoggle'+converse.bare_jid); + this.toggleview.model.id = id; // Appears to be necessary for backbone.browserStorage + this.toggleview.model.browserStorage = new Backbone.BrowserStorage[converse.storage](id); this.toggleview.model.fetch(); }, @@ -3549,10 +3553,10 @@ */ model: converse.Feature, initialize: function () { - this.localStorage = new Backbone.LocalStorage( + this.browserStorage = new Backbone.BrowserStorage[converse.storage]( b64_sha1('converse.features'+converse.bare_jid)); - if (this.localStorage.records.length === 0) { - // localStorage is empty, so we've likely never queried this + if (this.browserStorage.records.length === 0) { + // browserStorage is empty, so we've likely never queried this // domain for features yet converse.connection.disco.info(converse.domain, null, $.proxy(this.onInfo, this)); converse.connection.disco.items(converse.domain, null, $.proxy(this.onItems, this)); diff --git a/docs/source/index.rst b/docs/source/index.rst index 6589960b8..67fc1bfe6 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -1011,6 +1011,25 @@ Default: ``false`` If set to ``true``, only online users will be shown in the contacts roster. Users with any other status (e.g. away, busy etc.) will not be shown. +storage +------- + +Default: ``session`` + +Valid options: ``session``, ``local``. + +This option determines the type of `storage `_ +(``localStorage`` or ``sessionStorage``) used by converse.js to cache user data. + +Originally converse.js used only localStorage, however sessionStorage is from a +privacy perspective a better choice. + +The main difference between the two is that sessionStorage only persists while +the current tab or window containing a converse.js instance is open. As soon as +it's closed, the data is cleared. + +Data in localStorage on the other hand is kept indefinitely. + use_otr_by_default ------------------ diff --git a/index.html b/index.html index 0d6cab8c8..d41409f76 100644 --- a/index.html +++ b/index.html @@ -12,10 +12,10 @@ - + @@ -229,7 +229,7 @@ allow_otr: true, auto_list_rooms: false, auto_subscribe: false, - bosh_service_url: 'https://bind.conversejs.org', // Please use this connection manager only for testing purposes + bosh_service_url: 'http://devbox:8890/http-bind', // Please use this connection manager only for testing purposes debug: true , hide_muc_server: false, i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported diff --git a/main.js b/main.js index c7db44bd5..738a48eaf 100644 --- a/main.js +++ b/main.js @@ -7,7 +7,7 @@ config = { "locales": "locale/locales", "underscore": "components/underscore/underscore", "backbone": "components/backbone/backbone", - "backbone.localStorage": "components/backbone.localStorage/backbone.localStorage", + "backbone.browserStorage": "components/backbone.browserStorage/backbone.browserStorage", "backbone.overview": "components/backbone.overview/backbone.overview", "text": 'components/requirejs-text/text', "tpl": 'components/requirejs-tpl-jcbrand/tpl', diff --git a/src/deps-full.js b/src/deps-full.js index b1d733f86..2ea5df633 100644 --- a/src/deps-full.js +++ b/src/deps-full.js @@ -2,7 +2,7 @@ define("converse-dependencies", [ "otr", "moment", "locales", - "backbone.localStorage", + "backbone.browserStorage", "backbone.overview", "jquery.tinysort", "jquery.browser", diff --git a/src/deps-no-otr.js b/src/deps-no-otr.js index b84da6007..67f455c40 100644 --- a/src/deps-no-otr.js +++ b/src/deps-no-otr.js @@ -1,7 +1,7 @@ define("converse-dependencies", [ "moment", "locales", - "backbone.localStorage", + "backbone.browserStorage", "backbone.overview", "jquery.tinysort", "jquery.browser",