Commit 5f041769 authored by JC Brand's avatar JC Brand

Clear messages when converse reconnects

parent 886ff1bd
...@@ -1490,18 +1490,6 @@ converse.plugins.add('converse-muc', { ...@@ -1490,18 +1490,6 @@ converse.plugins.add('converse-muc', {
_converse.api.trigger('roomsAutoJoined'); _converse.api.trigger('roomsAutoJoined');
} }
function disconnectChatRooms () {
/* When disconnecting, mark all groupchats as
* disconnected, so that they will be properly entered again
* when fetched from session storage.
*/
_converse.chatboxes.each(model => {
if (model.get('type') === _converse.CHATROOMS_TYPE) {
model.save('connection_status', converse.ROOMSTATUS.DISCONNECTED);
}
});
}
/************************ BEGIN Event Handlers ************************/ /************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('addClientFeatures', () => { _converse.api.listen.on('addClientFeatures', () => {
...@@ -1513,13 +1501,23 @@ converse.plugins.add('converse-muc', { ...@@ -1513,13 +1501,23 @@ converse.plugins.add('converse-muc', {
} }
}); });
_converse.api.listen.on('chatBoxesFetched', autoJoinRooms); _converse.api.listen.on('chatBoxesFetched', autoJoinRooms);
function disconnectChatRooms () {
/* When disconnecting, mark all groupchats as
* disconnected, so that they will be properly entered again
* when fetched from session storage.
*/
return _converse.chatboxes
.filter(m => (m.get('type') === _converse.CHATROOMS_TYPE))
.forEach(m => m.save('connection_status', converse.ROOMSTATUS.DISCONNECTED))
}
_converse.api.listen.on('disconnecting', disconnectChatRooms); _converse.api.listen.on('disconnecting', disconnectChatRooms);
_converse.api.listen.on('statusInitialized', () => { _converse.api.listen.on('statusInitialized', () => {
// XXX: For websocket connections, we disconnect from all // XXX: For websocket connections, we disconnect from all
// chatrooms when the page reloads. This is a workaround for // chatrooms when the page reloads. This is a workaround for
// issue #1111 and should be removed once we support XEP-0198 // issue #1111 and should be removed once we support XEP-0198
const options = {'once': true, 'passive': true};
window.addEventListener(_converse.unloadevent, () => { window.addEventListener(_converse.unloadevent, () => {
if (_converse.connection._proto instanceof Strophe.Websocket) { if (_converse.connection._proto instanceof Strophe.Websocket) {
disconnectChatRooms(); disconnectChatRooms();
...@@ -1531,13 +1529,14 @@ converse.plugins.add('converse-muc', { ...@@ -1531,13 +1529,14 @@ converse.plugins.add('converse-muc', {
/* Upon a reconnection event from converse, join again /* Upon a reconnection event from converse, join again
* all the open groupchats. * all the open groupchats.
*/ */
_converse.chatboxes.each(model => { _converse.chatboxes
if (model.get('type') === _converse.CHATROOMS_TYPE) { .filter(m => (m.get('type') === _converse.CHATROOMS_TYPE))
model.save('connection_status', converse.ROOMSTATUS.DISCONNECTED); .forEach(m => m.save('connection_status', converse.ROOMSTATUS.DISCONNECTED))
model.registerHandlers(); .forEach(room => {
model.join(); room.clearMessages();
} room.registerHandlers();
}); room.join();
});
} }
_converse.api.listen.on('reconnected', reconnectToChatRooms); _converse.api.listen.on('reconnected', reconnectToChatRooms);
/************************ END Event Handlers ************************/ /************************ END Event Handlers ************************/
......
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