Commit e3d59afd authored by JC Brand's avatar JC Brand

Use `converse` instead of `this`, or `that` instead of bind

parent ec9ed965
...@@ -127,7 +127,7 @@ ...@@ -127,7 +127,7 @@
clearSession: function () { clearSession: function () {
this.__super__.clearSession.apply(this, arguments); this.__super__.clearSession.apply(this, arguments);
if (typeof this.connection !== 'undefined' && this.connection.connected) { if (_.isUndefined(this.connection) && this.connection.connected) {
this.chatboxes.get('controlbox').save({'connected': false}); this.chatboxes.get('controlbox').save({'connected': false});
} }
}, },
......
...@@ -390,13 +390,15 @@ ...@@ -390,13 +390,15 @@
this.reconnect = _.debounce(function (condition) { this.reconnect = _.debounce(function (condition) {
converse.connection.reconnecting = true;
converse.connection.disconnect('re-connecting');
converse.connection.reset();
converse.log('The connection has dropped, attempting to reconnect.'); converse.log('The connection has dropped, attempting to reconnect.');
converse.giveFeedback( converse.giveFeedback(
__("Reconnecting"), 'warn', __('The connection has dropped, attempting to reconnect.') __("Reconnecting"),
'warn',
__('The connection has dropped, attempting to reconnect.')
); );
converse.connection.reconnecting = true;
converse.connection.disconnect('re-connecting');
converse.connection.reset();
converse.clearSession(); converse.clearSession();
converse._tearDown(); converse._tearDown();
if (converse.authentication !== "prebind") { if (converse.authentication !== "prebind") {
...@@ -566,7 +568,6 @@ ...@@ -566,7 +568,6 @@
converse.clearMsgCounter(); converse.clearMsgCounter();
} }
converse.windowState = state; converse.windowState = state;
}; };
this.registerGlobalEventHandlers = function () { this.registerGlobalEventHandlers = function () {
...@@ -684,15 +685,15 @@ ...@@ -684,15 +685,15 @@
}; };
this.onStatusInitialized = function () { this.onStatusInitialized = function () {
this.registerIntervalHandler(); converse.registerIntervalHandler();
this.initRoster(); converse.initRoster();
this.populateRoster(); converse.populateRoster();
this.chatboxes.onConnected(); converse.chatboxes.onConnected();
this.registerPresenceHandler(); converse.registerPresenceHandler();
this.giveFeedback(__('Contacts')); converse.giveFeedback(__('Contacts'));
if (typeof this.callback === 'function') { if (typeof converse.callback === 'function') {
// XXX: Deprecate in favor of init_deferred // XXX: Deprecate in favor of init_deferred
this.callback(); converse.callback();
} }
if (converse.connection.service === 'jasmine tests') { if (converse.connection.service === 'jasmine tests') {
init_deferred.resolve(converse); init_deferred.resolve(converse);
...@@ -702,10 +703,17 @@ ...@@ -702,10 +703,17 @@
converse.emit('initialized'); converse.emit('initialized');
}; };
this.setUserJid = function () {
converse.jid = converse.connection.jid;
converse.bare_jid = Strophe.getBareJidFromJid(converse.connection.jid);
converse.resource = Strophe.getResourceFromJid(converse.connection.jid);
converse.domain = Strophe.getDomainFromJid(converse.connection.jid);
};
this.onConnected = function (callback) { this.onConnected = function (callback) {
// When reconnecting, there might be some open chat boxes. We don't /* Called as soon as a new connection has been established, either
// know whether these boxes are of the same account or not, so we * by logging in or by attaching to an existing BOSH session.
// close them now. */
// XXX: ran into an issue where a returned PubSub BOSH response was // XXX: ran into an issue where a returned PubSub BOSH response was
// not received by the browser. The solution was to flush the // not received by the browser. The solution was to flush the
// connection early on. I don't know what the underlying cause of // connection early on. I don't know what the underlying cause of
...@@ -715,17 +723,14 @@ ...@@ -715,17 +723,14 @@
// In any case, flushing here (sending out a new BOSH request) // In any case, flushing here (sending out a new BOSH request)
// solves the problem. // solves the problem.
converse.connection.flush(); converse.connection.flush();
/* Called as soon as a new connection has been established, either // When reconnecting, there might be some open chat boxes. We don't
* by logging in or by attaching to an existing BOSH session. // know whether these boxes are of the same account or not, so we
*/ // close them now.
this.chatboxviews.closeAllChatBoxes(); converse.chatboxviews.closeAllChatBoxes();
this.jid = this.connection.jid; converse.setUserJid();
this.bare_jid = Strophe.getBareJidFromJid(this.connection.jid); converse.features = new converse.Features();
this.resource = Strophe.getResourceFromJid(this.connection.jid); converse.enableCarbons();
this.domain = Strophe.getDomainFromJid(this.connection.jid); converse.initStatus().done(converse.onStatusInitialized);
this.features = new this.Features();
this.enableCarbons();
this.initStatus().done(_.bind(this.onStatusInitialized, this));
converse.emit('connected'); converse.emit('connected');
converse.emit('ready'); // BBB: Will be removed. converse.emit('ready'); // BBB: Will be removed.
}; };
...@@ -1367,11 +1372,12 @@ ...@@ -1367,11 +1372,12 @@
* This method gets overridden entirely in src/converse-controlbox.js * This method gets overridden entirely in src/converse-controlbox.js
* if the controlbox plugin is active. * if the controlbox plugin is active.
*/ */
var that = this;
collection.each(function (chatbox) { collection.each(function (chatbox) {
if (this.chatBoxMayBeShown(chatbox)) { if (that.chatBoxMayBeShown(chatbox)) {
chatbox.trigger('show'); chatbox.trigger('show');
} }
}.bind(this)); });
converse.emit('chatBoxesFetched'); converse.emit('chatBoxesFetched');
}, },
......
...@@ -392,7 +392,6 @@ ...@@ -392,7 +392,6 @@
); );
}, },
onGroupAdd: function (group) { onGroupAdd: function (group) {
var view = new converse.RosterGroupView({model: group}); var view = new converse.RosterGroupView({model: group});
this.add(group.get('name'), view.render()); this.add(group.get('name'), view.render());
......
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