Browse Source

Rip out the controlbox code and put it in src/converse-controlbox.js

Also fixed an issue w.r.t the plugin architecture. Previously infinite
recursion would happen when more than one plugin was overriding a method.

Resolved now by using a wrapper function that lazily sets the correct super
method.
JC Brand 9 years ago
parent
commit
dcd090ff31
9 changed files with 812 additions and 452 deletions
  1. 2 1
      main.js
  2. 2 0
      spec/converse.js
  3. 3 0
      spec/register.js
  4. 692 3
      src/converse-controlbox.js
  5. 85 427
      src/converse-core.js
  6. 20 15
      src/converse-muc.js
  7. 1 1
      src/converse-otr.js
  8. 2 4
      src/converse-ping.js
  9. 5 1
      src/converse-register.js

+ 2 - 1
main.js

@@ -44,8 +44,9 @@ require.config({
         "polyfill":                 "src/polyfill",
         
         // Converse
-        "converse-core":            "src/converse-core",
         "converse-api":             "src/converse-api",
+        "converse-controlbox":      "src/converse-controlbox",
+        "converse-core":            "src/converse-core",
         "converse-muc":             "src/converse-muc",
         "converse-otr":             "src/converse-otr",
         "converse-ping":            "src/converse-ping",

+ 2 - 0
spec/converse.js

@@ -16,8 +16,10 @@
 
         describe("Authentication", function () {
             it("needs either a bosh_service_url a websocket_url or both", function () {
+                converse.connection.connected = false;
                 expect(converse.initConnection.bind({})).toThrow(
                     new Error("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both."));
+                converse.connection.connected = true;
             });
 
             describe("with prebind", function () {

+ 3 - 0
spec/register.js

@@ -18,6 +18,7 @@
             var connection = mock.mock_connection;
             connection.connected = false;
             converse._tearDown();
+            converse.initialized_plugins = [];
             converse.initialize({
                 i18n: window.locales.en,
                 bosh_service_url: 'localhost',
@@ -42,6 +43,7 @@
             var connection = mock.mock_connection;
             connection.connected = false;
             converse._tearDown();
+            converse.initialized_plugins = [];
             converse.initialize({
                 i18n: window.locales.en,
                 animate: false,
@@ -59,6 +61,7 @@
             connection = mock.mock_connection;
             connection.connected = false;
             converse._tearDown();
+            converse.initialized_plugins = [];
             converse.initialize({
                 i18n: window.locales.en,
                 bosh_service_url: 'localhost',

File diff suppressed because it is too large
+ 692 - 3
src/converse-controlbox.js


File diff suppressed because it is too large
+ 85 - 427
src/converse-core.js


+ 20 - 15
src/converse-muc.js

@@ -10,7 +10,11 @@
  * specified in XEP-0045 Multi-user chat.
  */
 (function (root, factory) {
-    define("converse-muc", ["converse-core", "converse-api"], factory);
+    define("converse-muc", [
+            "converse-core",
+            "converse-api",
+            "converse-controlbox"
+    ], factory);
 }(this, function (converse, converse_api) {
     "use strict";
     // Strophe methods for building stanzas
@@ -48,10 +52,9 @@
 
             Features: {
                 addClientFeatures: function () {
-                    var converse = this._super.converse;
                     this._super.addClientFeatures.apply(this, arguments);
-                    if (converse.allow_muc) {
-                        converse.connection.disco.addFeature(Strophe.NS.MUC);
+                    if (this.allow_muc) {
+                        this.connection.disco.addFeature(Strophe.NS.MUC);
                     }
                 }
             },
@@ -123,17 +126,6 @@
             },
 
             ChatBoxes: {
-                onChatBoxAdded: function (item) {
-                    var view = this.get(item.get('id'));
-                    if (!view && item.get('chatroom')) {
-                        view = new converse.ChatRoomView({'model': item});
-                        this.add(item.get('id'), view);
-                        this.trimChats(view);
-                    } else {
-                        this._super.onChatBoxAdded.apply(this, arguments);
-                    }
-                },
-
                 registerMessageHandler: function () {
                     /* Override so that we can register a handler
                      * for chat room invites.
@@ -190,6 +182,19 @@
                     }
                 }
             },
+
+            ChatBoxViews: {
+                onChatBoxAdded: function (item) {
+                    var view = this.get(item.get('id'));
+                    if (!view && item.get('chatroom')) {
+                        view = new converse.ChatRoomView({'model': item});
+                        this.add(item.get('id'), view);
+                        this.trimChats(view);
+                    } else {
+                        this._super.onChatBoxAdded.apply(this, arguments);
+                    }
+                }
+            }
         },
 
         initialize: function () {

+ 1 - 1
src/converse-otr.js

@@ -57,7 +57,7 @@
  
             _initialize: function () {
                 this._super._initialize.apply(this, arguments);
-                this._super.converse.otr = new this._super.converse.OTR();
+                this.otr = new this.OTR();
             },
 
             registerGlobalEventHandlers: function () {

+ 2 - 4
src/converse-ping.js

@@ -32,14 +32,12 @@
             // New functions which don't exist yet can also be added.
 
             onConnected: function () {
-                var converse = this._super.converse;
-                this._super.onConnected().done(converse.registerPingHandler);
+                this._super.onConnected().done(this.registerPingHandler);
             },
             onReconnected: function () {
                 // We need to re-register the ping event handler on the newly
                 // created connection.
-                var converse = this._super.converse;
-                this._super.onReconnected().done(converse.registerPingHandler);
+                this._super.onReconnected().done(this.registerPingHandler);
             }
         },
 

+ 5 - 1
src/converse-register.js

@@ -10,7 +10,11 @@
  * as specified in XEP-0077.
  */
 (function (root, factory) {
-    define("converse-register", ["converse-core", "converse-api"], factory);
+    define("converse-register", [
+            "converse-core",
+            "converse-api",
+            "converse-controlbox"
+    ], factory);
 }(this, function (converse, converse_api) {
     "use strict";
     // Strophe methods for building stanzas

Some files were not shown because too many files changed in this diff