Commit 597e3693 authored by JC Brand's avatar JC Brand

Call initRoster only after controlbox is connected.

parent 3a30f30f
...@@ -669,7 +669,6 @@ ...@@ -669,7 +669,6 @@
this.initStatus($.proxy(function () { this.initStatus($.proxy(function () {
this.chatboxes.onConnected(); this.chatboxes.onConnected();
this.connection.roster.get(function () {});
this.giveFeedback(__('Online Contacts')); this.giveFeedback(__('Online Contacts'));
if (this.callback) { if (this.callback) {
if (this.connection.service === 'jasmine tests') { if (this.connection.service === 'jasmine tests') {
...@@ -1615,21 +1614,6 @@ ...@@ -1615,21 +1614,6 @@
initialize: function (cfg) { initialize: function (cfg) {
cfg.$parent.append(this.$el); cfg.$parent.append(this.$el);
this.$tabs = cfg.$parent.parent().find('#controlbox-tabs'); this.$tabs = cfg.$parent.parent().find('#controlbox-tabs');
this.initRoster();
},
initRoster: function () {
/* We initialize the roster, which will appear inside the
* Contacts Panel.
*/
converse.roster = new converse.RosterContacts();
converse.roster.browserStorage = new Backbone.BrowserStorage[converse.storage](
b64_sha1('converse.contacts-'+converse.bare_jid));
var rostergroups = new converse.RosterGroups();
rostergroups.browserStorage = new Backbone.BrowserStorage[converse.storage](
b64_sha1('converse.roster.groups'+converse.bare_jid));
converse.rosterview = new converse.RosterView({model: rostergroups});
converse.rosterview.render().fetch().update();
}, },
render: function () { render: function () {
...@@ -1662,7 +1646,6 @@ ...@@ -1662,7 +1646,6 @@
} }
this.$el.html(widgets); this.$el.html(widgets);
this.$el.find('.search-xmpp ul').append(markup); this.$el.find('.search-xmpp ul').append(markup);
this.$el.append(converse.rosterview.$el);
return this; return this;
}, },
...@@ -1941,6 +1924,7 @@ ...@@ -1941,6 +1924,7 @@
this.model.on('change:connected', $.proxy(function (item) { this.model.on('change:connected', $.proxy(function (item) {
this.render(); this.render();
if (this.model.get('connected')) { if (this.model.get('connected')) {
this.initRoster();
converse.features.off('add', this.featureAdded, this); converse.features.off('add', this.featureAdded, this);
converse.features.on('add', this.featureAdded, this); converse.features.on('add', this.featureAdded, this);
// Features could have been added before the controlbox was // Features could have been added before the controlbox was
...@@ -1956,6 +1940,24 @@ ...@@ -1956,6 +1940,24 @@
this.model.on('hide', this.hide, this); this.model.on('hide', this.hide, this);
}, },
initRoster: function () {
/* We initialize the roster, which will appear inside the
* Contacts Panel.
*/
if (!converse.roster) {
converse.roster = new converse.RosterContacts();
converse.roster.browserStorage = new Backbone.BrowserStorage[converse.storage](
b64_sha1('converse.contacts-'+converse.bare_jid));
var rostergroups = new converse.RosterGroups();
rostergroups.browserStorage = new Backbone.BrowserStorage[converse.storage](
b64_sha1('converse.roster.groups'+converse.bare_jid));
converse.rosterview = new converse.RosterView({model: rostergroups});
}
converse.rosterview.render().fetch().update();
this.contactspanel.$el.append(converse.rosterview.$el);
converse.connection.roster.get(function () {});
},
render: function () { render: function () {
if (!converse.connection.connected || !converse.connection.authenticated || converse.connection.disconnecting) { if (!converse.connection.connected || !converse.connection.authenticated || converse.connection.disconnecting) {
// TODO: we might need to take prebinding into consideration here. // TODO: we might need to take prebinding into consideration here.
...@@ -3413,27 +3415,26 @@ ...@@ -3413,27 +3415,26 @@
return count; return count;
}, },
cleanCache: function (items) { clearCache: function (items) {
/* The localstorage cache containing roster contacts might contain /* The localstorage cache containing roster contacts might contain
* some contacts that aren't actually in our roster anymore. We * some contacts that aren't actually in our roster anymore. We
* therefore need to remove them now. * therefore need to remove them now.
*/ */
var id, i, var id, i, contact;
roster_ids = [];
for (i=0; i < items.length; ++i) {
roster_ids.push(items[i].jid);
}
for (i=0; i < this.models.length; ++i) { for (i=0; i < this.models.length; ++i) {
id = this.models[i].get('id'); id = this.models[i].get('id');
if (_.indexOf(roster_ids, id) === -1) { if (_.indexOf(_.pluck(items, 'jid'), id) === -1) {
this.get(id).destroy(); contact = this.get(id);
if (contact) {
contact.destroy();
}
} }
} }
}, },
rosterHandler: function (items) { rosterHandler: function (items) {
converse.emit('roster', items); converse.emit('roster', items);
this.cleanCache(items); this.clearCache(items);
_.each(items, function (item, index, items) { _.each(items, function (item, index, items) {
if (this.isSelf(item.jid)) { return; } if (this.isSelf(item.jid)) { return; }
var model = this.get(item.jid); var model = this.get(item.jid);
...@@ -3634,8 +3635,10 @@ ...@@ -3634,8 +3635,10 @@
view = this.positionContact(contact).render(); view = this.positionContact(contact).render();
if (this.model.get('state') === CLOSED) { if (this.model.get('state') === CLOSED) {
view.$el.hide(); view.$el.hide();
}
this.$el.show(); this.$el.show();
} else {
this.show();
}
}, },
positionContact: function (contact) { positionContact: function (contact) {
...@@ -4013,7 +4016,7 @@ ...@@ -4013,7 +4016,7 @@
this.getGroup(name).contacts.add(contact); this.getGroup(name).contacts.add(contact);
}, },
addCurrentContact: function (contact) { addExistingContact: function (contact) {
var groups; var groups;
if (converse.roster_groups) { if (converse.roster_groups) {
groups = contact.get('groups'); groups = contact.get('groups');
...@@ -4029,11 +4032,10 @@ ...@@ -4029,11 +4032,10 @@
}, },
addRosterContact: function (contact) { addRosterContact: function (contact) {
var view;
if (contact.get('subscription') === 'both' || contact.get('subscription') === 'to') { if (contact.get('subscription') === 'both' || contact.get('subscription') === 'to') {
this.addCurrentContact(contact); this.addExistingContact(contact);
} else { } else {
view = (new converse.RosterContactView({model: contact})).render(); (new converse.RosterContactView({model: contact})).render();
if ((contact.get('ask') === 'subscribe') || (contact.get('subscription') === 'from')) { if ((contact.get('ask') === 'subscribe') || (contact.get('subscription') === 'from')) {
this.addContactToGroup(contact, HEADER_PENDING_CONTACTS); this.addContactToGroup(contact, HEADER_PENDING_CONTACTS);
} else if (contact.get('requesting') === true) { } else if (contact.get('requesting') === true) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment