Commit ec91175a authored by JC Brand's avatar JC Brand

converse-muc: Don't send a join presence at every page reload.

Instead, keep track of the connection state of the room and send a presence
only when the room's connection was disrupted.
parent d7892d94
...@@ -825,6 +825,11 @@ ...@@ -825,6 +825,11 @@
* the room. * the room.
*/ */
this.registerHandlers(); this.registerHandlers();
if (this.model.get('connection_status') === Strophe.Status.CONNECTED) {
// We have restored a chat room from session storage,
// so we don't send out a presence stanza again.
return;
}
var stanza = $pres({ var stanza = $pres({
'from': converse.connection.jid, 'from': converse.connection.jid,
'to': this.getRoomJIDAndNick(nick) 'to': this.getRoomJIDAndNick(nick)
...@@ -833,12 +838,12 @@ ...@@ -833,12 +838,12 @@
if (password) { if (password) {
stanza.cnode(Strophe.xmlElement("password", [], password)); stanza.cnode(Strophe.xmlElement("password", [], password));
} }
this.model.set('connection_status', Strophe.Status.CONNECTING); this.model.save('connection_status', Strophe.Status.CONNECTING);
return converse.connection.send(stanza); return converse.connection.send(stanza);
}, },
cleanup: function () { cleanup: function () {
this.model.set('connection_status', Strophe.Status.DISCONNECTED); this.model.save('connection_status', Strophe.Status.DISCONNECTED);
this.removeHandlers(); this.removeHandlers();
}, },
...@@ -1371,7 +1376,7 @@ ...@@ -1371,7 +1376,7 @@
if (notification.reason) { if (notification.reason) {
this.showDisconnectMessage(__(___('The reason given is: <em>"%1$s"</em>.'), notification.reason)); this.showDisconnectMessage(__(___('The reason given is: <em>"%1$s"</em>.'), notification.reason));
} }
this.model.set('connection_status', Strophe.Status.DISCONNECTED); this.model.save('connection_status', Strophe.Status.DISCONNECTED);
return; return;
} }
_.each(notification.messages, function (message) { _.each(notification.messages, function (message) {
...@@ -1479,7 +1484,7 @@ ...@@ -1479,7 +1484,7 @@
* (XMLElement) pres: The stanza * (XMLElement) pres: The stanza
*/ */
if (pres.getAttribute('type') === 'error') { if (pres.getAttribute('type') === 'error') {
this.model.set('connection_status', Strophe.Status.DISCONNECTED); this.model.save('connection_status', Strophe.Status.DISCONNECTED);
this.showErrorMessage(pres); this.showErrorMessage(pres);
return true; return true;
} }
...@@ -1514,7 +1519,7 @@ ...@@ -1514,7 +1519,7 @@
this.hideSpinner().showStatusMessages(pres); this.hideSpinner().showStatusMessages(pres);
} }
this.occupantsview.updateOccupantsOnPresence(pres); this.occupantsview.updateOccupantsOnPresence(pres);
this.model.set('connection_status', Strophe.Status.CONNECTED); this.model.save('connection_status', Strophe.Status.CONNECTED);
return true; return true;
}, },
...@@ -2191,6 +2196,33 @@ ...@@ -2191,6 +2196,33 @@
} }
} }
}); });
var reconnectToChatRooms = function () {
/* Upon a reconnection event from converse, join again
* all the open chat rooms.
*/
converse.chatboxviews.each(function (view) {
if (view.model.get('type') === 'chatroom') {
view.model.save('connection_status', Strophe.Status.DISCONNECTED);
view.join(view.model.get('nick'));
}
});
};
converse.on('reconnected', reconnectToChatRooms);
var disconnectChatRooms = function () {
/* When disconnecting, or reconnecting, mark all chat rooms as
* disconnected, so that they will be properly entered again
* when fetched from session storage.
*/
converse.chatboxes.each(function (model) {
if (model.get('type') === 'chatroom') {
model.save('connection_status', Strophe.Status.DISCONNECTED);
}
});
};
converse.on('reconnecting', disconnectChatRooms);
converse.on('disconnecting', disconnectChatRooms);
} }
}); });
})); }));
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