Browse Source

All tests pass \o/

JC Brand 11 years ago
parent
commit
be76156292
2 changed files with 9 additions and 13 deletions
  1. 8 12
      converse.js
  2. 1 1
      spec/controlbox.js

+ 8 - 12
converse.js

@@ -3237,6 +3237,11 @@
             },
 
             initialize: function () {
+                /* If initialize ever gets called again, event listeners will
+                 * be registered twice. So we turn them off first.
+                 * Currently only an issue in tests.
+                 */
+                this.model.off(); 
                 this.model.on("add", this.onAdd, this);
                 this.model.on('change', this.onChange, this); 
                 this.model.on("remove", this.removeRosterItemView, this);
@@ -3271,7 +3276,7 @@
             },
 
             onAdd: function (item) {
-                this.addRosterItemView(item).addRosterItem(item).updateRoster();
+                this.addRosterItem(item).updateRoster();
                 if (item.get('is_last')) {
                     this.sortRoster().showRoster();
                 }
@@ -3316,12 +3321,6 @@
                 return this;
             },
 
-            addRosterItemView: function (item) {
-                var view = new converse.RosterItemView({model: item});
-                this.add(item.id, view);
-                return this;
-            },
-
             removeAllRosterItemViews: function () {
                 this.removeAll();
                 this.updateRoster();
@@ -3363,14 +3362,11 @@
             },
 
             addRosterItem: function (item) {
+                var view = new converse.RosterItemView({model: item});
+                this.add(item.id, view);
                 if ((converse.show_only_online_users) && (item.get('chat_status') !== 'online')) {
                     return this;
                 }
-                var view = this.get(item.id);
-                if (!view) {
-                    converse.log("renderRosterItem called with item that doesn't have a view", "error");
-                    return this;
-                }
                 view.render()
                 var $el = this.getRosterElement();
                 if (view.$el.hasClass('current-xmpp-contact')) {

+ 1 - 1
spec/controlbox.js

@@ -132,7 +132,7 @@
             function _clearContacts () {
                 utils.clearBrowserStorage();
                 converse.rosterview.model.reset();
-                converse.rosterview.initialize();
+                converse.rosterview.initialize(); // Register new listeners and document fragment
             };
 
             function _addContacts () {