Selaa lähdekoodia

Use 'type' = 'chatroom' instead of 'chatroom' boolean.

JC Brand 9 vuotta sitten
vanhempi
commit
2d846961c2
3 muutettua tiedostoa jossa 13 lisäystä ja 14 poistoa
  1. 5 6
      src/converse-chatview.js
  2. 2 2
      src/converse-controlbox.js
  3. 6 6
      src/converse-muc.js

+ 5 - 6
src/converse-chatview.js

@@ -36,10 +36,7 @@
             ChatBoxViews: {
                 onChatBoxAdded: function (item) {
                     var view = this.get(item.get('id'));
-                    // FIXME: leaky abstraction from chatroom here, need to
-                    // come up with a nicer solution for this.
-                    // Perhaps change 'chatroom' to more generic non-boolean
-                    if (!view && !item.get('chatroom')) {
+                    if (!view) {
                         view = new converse.ChatBoxView({model: item});
                         this.add(item.get('id'), view);
                         return view;
@@ -600,7 +597,8 @@
                         message = $textarea.val();
                         $textarea.val('').focus();
                         if (message !== '') {
-                            if (this.model.get('chatroom')) {
+                            // XXX: leaky abstraction from MUC
+                            if (this.model.get('type') === 'chatroom') {
                                 this.onChatRoomMessageSubmitted(message);
                             } else {
                                 this.onMessageSubmitted(message);
@@ -608,7 +606,8 @@
                             converse.emit('messageSend', message);
                         }
                         this.setChatState(converse.ACTIVE);
-                    } else if (!this.model.get('chatroom')) { // chat state data is currently only for single user chat
+                    // XXX: leaky abstraction from MUC
+                    } else if (this.model.get('type') !== 'chatroom') { // chat state data is currently only for single user chat
                         // Set chat state to composing if keyCode is not a forward-slash
                         // (which would imply an internal command and not a message).
                         this.setChatState(converse.COMPOSING, ev.keyCode === KEY.FORWARD_SLASH);

+ 2 - 2
src/converse-controlbox.js

@@ -88,9 +88,9 @@
                     var view = this.get(item.get('id'));
                     if (!view && item.get('box_id') === 'controlbox') {
                         view = new converse.ControlBoxView({model: item});
-                        this.add(item.get('id'), view);
+                        return this.add(item.get('id'), view);
                     } else {
-                        this._super.onChatBoxAdded.apply(this, arguments);
+                        return this._super.onChatBoxAdded.apply(this, arguments);
                     }
                 },
 

+ 6 - 6
src/converse-muc.js

@@ -171,7 +171,7 @@
                             'jid': room_jid,
                             'name': Strophe.unescapeNode(Strophe.getNodeFromJid(room_jid)),
                             'nick': Strophe.unescapeNode(Strophe.getNodeFromJid(converse.connection.jid)),
-                            'chatroom': true,
+                            'type': 'chatroom',
                             'box_id': b64_sha1(room_jid),
                             'password': $x.attr('password')
                         });
@@ -188,11 +188,11 @@
             ChatBoxViews: {
                 onChatBoxAdded: function (item) {
                     var view = this.get(item.get('id'));
-                    if (!view && item.get('chatroom')) {
+                    if (!view && item.get('type') === 'chatroom') {
                         view = new converse.ChatRoomView({'model': item});
-                        this.add(item.get('id'), view);
+                        return this.add(item.get('id'), view);
                     } else {
-                        this._super.onChatBoxAdded.apply(this, arguments);
+                        return this._super.onChatBoxAdded.apply(this, arguments);
                     }
                 }
             }
@@ -1322,7 +1322,7 @@
                         'jid': jid,
                         'name': name || Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
                         'nick': nick,
-                        'chatroom': true,
+                        'type': 'chatroom',
                         'box_id': b64_sha1(jid)
                     });
                 },
@@ -1358,7 +1358,7 @@
                                     'jid': jid,
                                     'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
                                     'nick': nick,
-                                    'chatroom': true,
+                                    'type': 'chatroom',
                                     'box_id': b64_sha1(jid)
                                 });
                             }