Commit 081d3778 authored by JC Brand's avatar JC Brand

Move code from plugins to core.

Move init of RosterGroups collection and presenceHandler registration out of
the controlbox and rosterview plugins and into core, since this code is
generally useful (indeed necessary) even without those plugins.
parent 9cfec0ba
......@@ -18,7 +18,6 @@
"use strict";
// Strophe methods for building stanzas
var Strophe = converse_api.env.Strophe,
b64_sha1 = converse_api.env.b64_sha1,
utils = converse_api.env.utils;
// Other necessary globals
var $ = converse_api.env.jQuery,
......@@ -246,10 +245,7 @@
/* We initialize the roster, which will appear inside the
* Contacts Panel.
*/
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 = new converse.RosterView({model: converse.rostergroups});
this.contactspanel.$el.append(converse.rosterview.$el);
converse.rosterview.render().fetch().update();
return this;
......
......@@ -623,6 +623,7 @@
};
this.afterReconnected = function () {
this.registerPresenceHandler();
this.chatboxes.registerMessageHandler();
this.xmppstatus.sendPresence();
this.giveFeedback(__('Contacts'));
......@@ -664,13 +665,36 @@
this.connection.send(carbons_iq);
};
this.onStatusInitialized = function () {
this.registerIntervalHandler();
this.initRoster = function () {
this.roster = new this.RosterContacts();
this.roster.browserStorage = new Backbone.BrowserStorage[this.storage](
b64_sha1('converse.contacts-'+this.bare_jid));
this.rostergroups = new converse.RosterGroups();
this.rostergroups.browserStorage = new Backbone.BrowserStorage[converse.storage](
b64_sha1('converse.roster.groups'+converse.bare_jid));
};
this.unregisterPresenceHandler = function () {
if (typeof this.presence_ref !== 'undefined') {
this.connection.deleteHandler(this.presence_ref);
delete this.presence_ref;
}
};
this.registerPresenceHandler = function () {
this.unregisterPresenceHandler();
this.presence_ref = converse.connection.addHandler(
function (presence) {
converse.roster.presenceHandler(presence);
return true;
}, null, 'presence', null);
};
this.onStatusInitialized = function () {
this.registerIntervalHandler();
this.initRoster();
this.chatboxes.onConnected();
this.registerPresenceHandler();
this.giveFeedback(__('Contacts'));
if (typeof this.callback === 'function') {
// XXX: Deprecate in favor of init_deferred
......@@ -1806,6 +1830,7 @@
/* Remove those views which are only allowed with a valid
* connection.
*/
this.unregisterPresenceHandler();
if (this.roster) {
this.roster.off().reset(); // Removes roster contacts
}
......
......@@ -49,7 +49,6 @@
afterReconnected: function () {
this.rosterview.registerRosterXHandler();
this.rosterview.registerPresenceHandler();
this._super.afterReconnected.apply(this, arguments);
},
......@@ -223,7 +222,6 @@
initialize: function () {
this.roster_handler_ref = this.registerRosterHandler();
this.rosterx_handler_ref = this.registerRosterXHandler();
this.presence_ref = this.registerPresenceHandler();
converse.roster.on("add", this.onContactAdd, this);
converse.roster.on('change', this.onContactChange, this);
converse.roster.on("destroy", this.update, this);
......@@ -271,8 +269,6 @@
delete this.roster_handler_ref;
converse.connection.deleteHandler(this.rosterx_handler_ref);
delete this.rosterx_handler_ref;
converse.connection.deleteHandler(this.presence_ref);
delete this.presence_ref;
},
update: _.debounce(function () {
......@@ -391,13 +387,6 @@
);
},
registerPresenceHandler: function () {
converse.connection.addHandler(
function (presence) {
converse.roster.presenceHandler(presence);
return true;
}.bind(this), null, 'presence', null);
},
onGroupAdd: function (group) {
var view = new converse.RosterGroupView({model: group});
......
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