From f3373c44fdb28eae0927e95d678e6166dfdc5b48 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 21 Apr 2017 17:52:54 +0200 Subject: [PATCH] Fixes #850. `.where` method doesn't match numbers. --- spec/controlbox.js | 4 ++-- src/converse-core.js | 7 ++++--- src/converse-rosterview.js | 16 ++++++++-------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/spec/controlbox.js b/spec/controlbox.js index aeb4dc48d..d8efd9d85 100644 --- a/spec/controlbox.js +++ b/spec/controlbox.js @@ -151,7 +151,7 @@ }).then(function (contacts) { expect($roster.find('dd:visible').eq(0).text().trim()).toBe('Candice van der Knijff'); expect($roster.find('dt:visible').length).toBe(1); - expect($roster.find('dt:visible').eq(0).text()).toBe('colleagues'); + expect(_.trim($roster.find('dt:visible').eq(0).text())).toBe('colleagues'); $filter = _converse.rosterview.$('.roster-filter'); $filter.val("an"); $filter.trigger('keydown'); @@ -204,7 +204,7 @@ return $roster.find('dt:visible').length === 1; }, 500); }).then(function () { - expect($roster.find('dt:visible').eq(0).text()).toBe('colleagues'); + expect(_.trim($roster.find('dt:visible').eq(0).text())).toBe('colleagues'); expect($roster.find('dd:visible').length).toBe(3); // Check that all contacts under the group are shown expect($roster.find('dt:visible').nextUntil('dt', 'dd:hidden').length).toBe(0); diff --git a/src/converse-core.js b/src/converse-core.js index 1b40f4947..d9ee3704e 100755 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -1146,10 +1146,11 @@ /* Get the roster from the XMPP server */ var iq = $iq({type: 'get', 'id': _converse.connection.getUniqueId('roster')}) .c('query', {xmlns: Strophe.NS.ROSTER}); + var that = this; return _converse.connection.sendIQ(iq, function () { - this.onReceivedFromServer.apply(this, arguments); - callback.apply(this, arguments); - }.bind(this)); + that.onReceivedFromServer.apply(that, arguments); + callback.apply(that, arguments); + }); }, onReceivedFromServer: function (iq) { diff --git a/src/converse-rosterview.js b/src/converse-rosterview.js index 623022f6b..1f079ef59 100644 --- a/src/converse-rosterview.js +++ b/src/converse-rosterview.js @@ -32,6 +32,7 @@ b64_sha1 = converse.env.b64_sha1, _ = converse.env._; + converse.plugins.add('converse-rosterview', { overrides: { @@ -643,7 +644,7 @@ // would simplify things by not having to check whether the // group is collapsed or not. var name = this.$el.prevAll('dt:first').data('group'); - var group = _converse.rosterview.model.where({'name': name})[0]; + var group = _.head(_converse.rosterview.model.where({'name': name.toString()})); if (group.get('state') === _converse.CLOSED) { return true; } @@ -742,13 +743,12 @@ render: function () { this.el.setAttribute('data-group', this.model.get('name')); - this.$el.html( - $(tpl_group_header({ - label_group: this.model.get('name'), - desc_group_toggle: this.model.get('description'), - toggle_state: this.model.get('state') - })) - ); + var html = tpl_group_header({ + label_group: this.model.get('name'), + desc_group_toggle: this.model.get('description'), + toggle_state: this.model.get('state') + }); + this.el.innerHTML = html; return this; },