Przeglądaj źródła

Don't verride `model`

Instead, just let `converse-chatboxes` handle chat creation.

If the relevant plugin isn't loaded, it'll just fail, whereas before a
chat box would be created instead.
JC Brand 5 lat temu
rodzic
commit
32ad70563c

+ 0 - 11
src/converse-controlbox.js

@@ -83,17 +83,6 @@ converse.plugins.add('converse-controlbox', {
         //
         // New functions which don't exist yet can also be added.
 
-        ChatBoxes: {
-            model (attrs, options) {
-                const { _converse } = this.__super__;
-                if (attrs && attrs.id == 'controlbox') {
-                    return new _converse.ControlBox(attrs, options);
-                } else {
-                    return this.__super__.model.apply(this, arguments);
-                }
-            }
-        },
-
         ChatBoxViews: {
             closeAllChatBoxes () {
                 const { _converse } = this.__super__;

+ 0 - 12
src/converse-roomslist.js

@@ -19,18 +19,6 @@ const u = converse.env.utils;
 
 converse.plugins.add('converse-roomslist', {
 
-    /* Optional dependencies are other plugins which might be
-     * overridden or relied upon, and therefore need to be loaded before
-     * this plugin. They are called "optional" because they might not be
-     * available, in which case any overrides applicable to them will be
-     * ignored.
-     *
-     * It's possible however to make optional dependencies non-optional.
-     * If the setting "strict_plugin_dependencies" is set to true,
-     * an error will be raised if the plugin is not found.
-     *
-     * NB: These plugins need to have already been loaded via require.js.
-     */
     dependencies: ["converse-singleton", "converse-controlbox", "converse-muc", "converse-bookmarks"],
 
     initialize () {

+ 13 - 2
src/headless/converse-chatboxes.js

@@ -65,8 +65,19 @@ converse.plugins.add('converse-chatboxes', {
         _converse.ChatBoxes = _converse.Collection.extend({
             comparator: 'time_opened',
 
-            model (attrs, options) {
-                return new _converse.ChatBox(attrs, options);
+            // XXX: setting function to `model` attribute in order to work
+            // around a backbone bug which expects `model` to have a prototype
+            // attribute, which isn't the case with the newer syntax.
+            model: function (attrs, options) {
+                if (attrs && attrs.type == _converse.CHATROOMS_TYPE) {
+                    return new _converse.ChatRoom(attrs, options);
+                } else if (attrs.type == _converse.HEADLINES_TYPE) {
+                    return new _converse.HeadlinesBox(attrs, options);
+                } else if (attrs && attrs.id == 'controlbox') {
+                    return new _converse.ControlBox(attrs, options);
+                } else {
+                    return new _converse.ChatBox(attrs, options);
+                }
             },
 
             onChatBoxesFetched (collection) {

+ 1 - 19
src/headless/converse-headlines.js

@@ -26,25 +26,6 @@ converse.plugins.add('converse-headlines', {
      */
     dependencies: ["converse-chat"],
 
-    overrides: {
-        // Overrides mentioned here will be picked up by converse.js's
-        // plugin architecture they will replace existing methods on the
-        // relevant objects or classes.
-        //
-        // New functions which don't exist yet can also be added.
-
-        ChatBoxes: {
-            model (attrs, options) {
-                const { _converse } = this.__super__;
-                if (attrs.type == _converse.HEADLINES_TYPE) {
-                    return new _converse.HeadlinesBox(attrs, options);
-                } else {
-                    return this.__super__.model.apply(this, arguments);
-                }
-            },
-        }
-    },
-
 
     initialize () {
         /* The initialize function gets called as soon as the plugin is
@@ -52,6 +33,7 @@ converse.plugins.add('converse-headlines', {
          */
         const { _converse } = this;
 
+
         _converse.HeadlinesBox = _converse.ChatBox.extend({
             defaults () {
                 return {

+ 0 - 4
src/headless/converse-mam.js

@@ -164,10 +164,6 @@ converse.plugins.add('converse-mam', {
         Object.assign(_converse.ChatBox.prototype, MAMEnabledChat);
 
 
-        Object.assign(_converse.ChatRoom.prototype, {
-        });
-
-
         _converse.onMAMError = function (iq) {
             if (iq && iq.querySelectorAll('feature-not-implemented').length) {
                 log.warn("Message Archive Management (XEP-0313) not supported by this server");

+ 1 - 23
src/headless/converse-muc.js

@@ -73,18 +73,7 @@ converse.ROOMSTATUS = {
 
 
 converse.plugins.add('converse-muc', {
-    /* Optional dependencies are other plugins which might be
-     * overridden or relied upon, and therefore need to be loaded before
-     * this plugin. They are called "optional" because they might not be
-     * available, in which case any overrides applicable to them will be
-     * ignored.
-     *
-     * It's possible however to make optional dependencies non-optional.
-     * If the setting "strict_plugin_dependencies" is set to true,
-     * an error will be raised if the plugin is not found.
-     *
-     * NB: These plugins need to have already been loaded via require.js.
-     */
+
     dependencies: ["converse-chatboxes", "converse-chat", "converse-disco", "converse-controlbox"],
 
     overrides: {
@@ -93,17 +82,6 @@ converse.plugins.add('converse-muc', {
             const groupchats = this.chatboxes.where({'type': _converse.CHATROOMS_TYPE});
             groupchats.forEach(gc => u.safeSave(gc, {'connection_status': converse.ROOMSTATUS.DISCONNECTED}));
             this.__super__.tearDown.call(this, arguments);
-        },
-
-        ChatBoxes: {
-            model (attrs, options) {
-                const { _converse } = this.__super__;
-                if (attrs && attrs.type == _converse.CHATROOMS_TYPE) {
-                    return new _converse.ChatRoom(attrs, options);
-                } else {
-                    return this.__super__.model.apply(this, arguments);
-                }
-            },
         }
     },