Browse Source

Integrate backbone.browserStorage. Fixes #176

Data is now by default cached in sessionStorage and not localStorage.
Can be configured via the "storage" option.
JC Brand 11 năm trước cách đây
mục cha
commit
8aedc3fcf7
7 tập tin đã thay đổi với 47 bổ sung24 xóa
  1. 3 3
      bower.json
  2. 19 15
      converse.js
  3. 19 0
      docs/source/index.rst
  4. 3 3
      index.html
  5. 1 1
      main.js
  6. 1 1
      src/deps-full.js
  7. 1 1
      src/deps-no-otr.js

+ 3 - 3
bower.json

@@ -14,7 +14,8 @@
     "tinysort": "git://github.com/Sjeiti/TinySort.git",
     "tinysort": "git://github.com/Sjeiti/TinySort.git",
     "underscore": "1.6.0",
     "underscore": "1.6.0",
     "backbone": "1.1.2",
     "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": "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.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",
     "strophe.vcard": "https://raw.github.com/strophe/strophejs-plugins/f5c9e16b463610d501591452cded0359f53aae48/vcard/strophe.vcard.js",
@@ -26,8 +27,7 @@
     "requirejs-text": "~2.0.12",
     "requirejs-text": "~2.0.12",
     "requirejs-tpl-jcbrand": "*",
     "requirejs-tpl-jcbrand": "*",
     "momentjs": "~2.6.0",
     "momentjs": "~2.6.0",
-    "jquery.browser": "~0.0.6",
-    "backbone.overview": "*"
+    "jquery.browser": "~0.0.6"
   },
   },
   "exportsOverride": {}
   "exportsOverride": {}
 }
 }

+ 19 - 15
converse.js

@@ -163,6 +163,7 @@
         this.show_controlbox_by_default = false;
         this.show_controlbox_by_default = false;
         this.show_only_online_users = false;
         this.show_only_online_users = false;
         this.show_toolbar = true;
         this.show_toolbar = true;
+        this.storage = 'session';
         this.use_otr_by_default = false;
         this.use_otr_by_default = false;
         this.use_vcards = true;
         this.use_vcards = true;
         this.visible_toolbar_buttons = {
         this.visible_toolbar_buttons = {
@@ -204,6 +205,7 @@
             'show_only_online_users',
             'show_only_online_users',
             'show_toolbar',
             'show_toolbar',
             'sid',
             'sid',
+            'storage',
             'use_otr_by_default',
             'use_otr_by_default',
             'use_vcards',
             'use_vcards',
             'xhr_custom_status',
             'xhr_custom_status',
@@ -453,9 +455,9 @@
 
 
         this.initStatus = function (callback) {
         this.initStatus = function (callback) {
             this.xmppstatus = new this.XMPPStatus();
             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});
             this.xmppstatus.fetch({success: callback, error: callback});
         };
         };
 
 
@@ -483,13 +485,13 @@
         this.initRoster = function () {
         this.initRoster = function () {
             // Set up the roster
             // Set up the roster
             this.roster = new this.RosterItems();
             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));
                 b64_sha1('converse.rosteritems-'+converse.bare_jid));
             this.registerRosterHandler();
             this.registerRosterHandler();
             this.registerRosterXHandler();
             this.registerRosterXHandler();
             this.registerPresenceHandler();
             this.registerPresenceHandler();
             // Now create the view which will fetch roster items from
             // Now create the view which will fetch roster items from
-            // localStorage
+            // browserStorage
             this.rosterview = new this.RosterView({'model':this.roster});
             this.rosterview = new this.RosterView({'model':this.roster});
         };
         };
 
 
@@ -569,7 +571,9 @@
                 this.connection.xmlInput = function (body) { console.log(body); };
                 this.connection.xmlInput = function (body) { console.log(body); };
                 this.connection.xmlOutput = function (body) { console.log(body); };
                 this.connection.xmlOutput = function (body) { console.log(body); };
                 Strophe.log = function (level, msg) { console.log(level+' '+msg); };
                 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.bare_jid = Strophe.getBareJidFromJid(this.connection.jid);
             this.domain = Strophe.getDomainFromJid(this.connection.jid);
             this.domain = Strophe.getDomainFromJid(this.connection.jid);
@@ -649,7 +653,7 @@
                 var height = converse.applyHeightResistance(this.get('height'));
                 var height = converse.applyHeightResistance(this.get('height'));
                 if (this.get('box_id') !== 'controlbox') {
                 if (this.get('box_id') !== 'controlbox') {
                     this.messages = new converse.Messages();
                     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));
                         b64_sha1('converse.messages'+this.get('jid')+converse.bare_jid));
 
 
                     this.save({
                     this.save({
@@ -1168,7 +1172,7 @@
                 if (result === true) {
                 if (result === true) {
                     this.$el.find('.chat-content').empty();
                     this.$el.find('.chat-content').empty();
                     this.model.messages.reset();
                     this.model.messages.reset();
-                    this.model.messages.localStorage._clear();
+                    this.model.messages.browserStorage._clear();
                 }
                 }
                 return this;
                 return this;
             },
             },
@@ -2411,7 +2415,7 @@
             },
             },
 
 
             onConnected: function () {
             onConnected: function () {
-                this.localStorage = new Backbone.LocalStorage(
+                this.browserStorage = new Backbone.BrowserStorage[converse.storage](
                     b64_sha1('converse.chatboxes-'+converse.bare_jid));
                     b64_sha1('converse.chatboxes-'+converse.bare_jid));
                 if (!this.get('controlbox')) {
                 if (!this.get('controlbox')) {
                     this.add({
                     this.add({
@@ -2692,9 +2696,9 @@
                 this.toggleview = new converse.MinimizedChatsToggleView({
                 this.toggleview = new converse.MinimizedChatsToggleView({
                     model: new converse.MinimizedChatsToggle()
                     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();
                 this.toggleview.model.fetch();
             },
             },
 
 
@@ -3549,10 +3553,10 @@
             */
             */
             model: converse.Feature,
             model: converse.Feature,
             initialize: function () {
             initialize: function () {
-                this.localStorage = new Backbone.LocalStorage(
+                this.browserStorage = new Backbone.BrowserStorage[converse.storage](
                     b64_sha1('converse.features'+converse.bare_jid));
                     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
                     // domain for features yet
                     converse.connection.disco.info(converse.domain, null, $.proxy(this.onInfo, this));
                     converse.connection.disco.info(converse.domain, null, $.proxy(this.onInfo, this));
                     converse.connection.disco.items(converse.domain, null, $.proxy(this.onItems, this));
                     converse.connection.disco.items(converse.domain, null, $.proxy(this.onItems, this));

+ 19 - 0
docs/source/index.rst

@@ -1011,6 +1011,25 @@ Default:  ``false``
 If set to ``true``, only online users will be shown in the contacts roster.
 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.
 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
 use_otr_by_default
 ------------------
 ------------------
 
 

+ 3 - 3
index.html

@@ -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="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/theme.css" />
     <link type="text/css" rel="stylesheet" media="screen" href="css/converse.min.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 data-main="main" src="components/requirejs/require.js"></script>
-    -->
+    <!--
     <script src="builds/converse.min.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://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>
     <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
@@ -229,7 +229,7 @@
             allow_otr: true,
             allow_otr: true,
             auto_list_rooms: false,
             auto_list_rooms: false,
             auto_subscribe: 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 ,
             debug: true ,
             hide_muc_server: false,
             hide_muc_server: false,
             i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported
             i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported

+ 1 - 1
main.js

@@ -7,7 +7,7 @@ config = {
         "locales": "locale/locales",
         "locales": "locale/locales",
         "underscore": "components/underscore/underscore",
         "underscore": "components/underscore/underscore",
         "backbone": "components/backbone/backbone",
         "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",
         "backbone.overview": "components/backbone.overview/backbone.overview",
         "text": 'components/requirejs-text/text',
         "text": 'components/requirejs-text/text',
         "tpl": 'components/requirejs-tpl-jcbrand/tpl',
         "tpl": 'components/requirejs-tpl-jcbrand/tpl',

+ 1 - 1
src/deps-full.js

@@ -2,7 +2,7 @@ define("converse-dependencies", [
     "otr",
     "otr",
     "moment",
     "moment",
     "locales",
     "locales",
-    "backbone.localStorage",
+    "backbone.browserStorage",
     "backbone.overview",
     "backbone.overview",
     "jquery.tinysort",
     "jquery.tinysort",
     "jquery.browser",
     "jquery.browser",

+ 1 - 1
src/deps-no-otr.js

@@ -1,7 +1,7 @@
 define("converse-dependencies", [
 define("converse-dependencies", [
     "moment",
     "moment",
     "locales",
     "locales",
-    "backbone.localStorage",
+    "backbone.browserStorage",
     "backbone.overview",
     "backbone.overview",
     "jquery.tinysort",
     "jquery.tinysort",
     "jquery.browser",
     "jquery.browser",