Integrate backbone.browserStorage. Fixes #176
Data is now by default cached in sessionStorage and not localStorage. Can be configured via the "storage" option.
This commit is contained in:
parent
1e0e524e0a
commit
8aedc3fcf7
@ -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": {}
|
||||
}
|
||||
|
34
converse.js
34
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));
|
||||
|
@ -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 <https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/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
|
||||
------------------
|
||||
|
||||
|
@ -12,10 +12,10 @@
|
||||
<link type="text/css" rel="stylesheet" media="screen" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" />
|
||||
<link type="text/css" rel="stylesheet" media="screen" href="css/theme.css" />
|
||||
<link type="text/css" rel="stylesheet" media="screen" href="css/converse.min.css" />
|
||||
<!--
|
||||
<script data-main="main" src="components/requirejs/require.js"></script>
|
||||
-->
|
||||
<!--
|
||||
<script src="builds/converse.min.js"></script>
|
||||
-->
|
||||
|
||||
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
|
||||
@ -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
|
||||
|
2
main.js
2
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',
|
||||
|
@ -2,7 +2,7 @@ define("converse-dependencies", [
|
||||
"otr",
|
||||
"moment",
|
||||
"locales",
|
||||
"backbone.localStorage",
|
||||
"backbone.browserStorage",
|
||||
"backbone.overview",
|
||||
"jquery.tinysort",
|
||||
"jquery.browser",
|
||||
|
@ -1,7 +1,7 @@
|
||||
define("converse-dependencies", [
|
||||
"moment",
|
||||
"locales",
|
||||
"backbone.localStorage",
|
||||
"backbone.browserStorage",
|
||||
"backbone.overview",
|
||||
"jquery.tinysort",
|
||||
"jquery.browser",
|
||||
|
Loading…
Reference in New Issue
Block a user