From e5b2acde062cd4fabf2a705b1af0f2064ce269d6 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 2 Nov 2016 14:51:23 +0000 Subject: [PATCH] MUC: Don't send out unavailable presence when connection is lost. --- src/converse-muc.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/converse-muc.js b/src/converse-muc.js index 60f17f387..d1770a013 100755 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -668,7 +668,17 @@ return converse.connection.send(stanza); }, + cleanup: function () { + this.model.set('connection_status', Strophe.Status.DISCONNECTED); + this.removeHandlers(); + }, + leave: function(exit_msg) { + if (!converse.connection.connected) { + // Don't send out a stanza if we're not connected. + this.cleanup(); + return; + } var presenceid = converse.connection.getUniqueId(); var presence = $pres({ type: "unavailable", @@ -679,12 +689,10 @@ if (exit_msg !== null) { presence.c("status", exit_msg); } - var that = this; converse.connection.addHandler( - function () { - that.model.set('connection_status', Strophe.Status.DISCONNECTED); - that.removeHandlers(); - }, null, "presence", null, presenceid); + this.cleanup.bind(this), + null, "presence", null, presenceid + ); converse.connection.send(presence); },