Commit a4567ee0 authored by JC Brand's avatar JC Brand

muc: Store `connection_status` in session storage

Otherwise we might run into a situation where a very old,
cached MUC that's being restored has `connection_status` set to ENTERED
(and the user happens to be in the MUC via another client)
and then restores cached messages without taking
`clear_messages_on_reconnection` into account.
parent 09b085be
...@@ -91,6 +91,7 @@ ...@@ -91,6 +91,7 @@
while (sent_IQs.length) { sent_IQs.pop(); } while (sent_IQs.length) { sent_IQs.pop(); }
await u.waitUntil(() => _converse.chatboxes.length === 1); await u.waitUntil(() => _converse.chatboxes.length === 1);
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo'); await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
view = _converse.chatboxviews.get(muc_jid); view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => view.model.messages.length); await u.waitUntil(() => view.model.messages.length);
......
...@@ -292,13 +292,13 @@ ...@@ -292,13 +292,13 @@
spyOn(view.model, 'join').and.callThrough(); spyOn(view.model, 'join').and.callThrough();
await test_utils.waitForReservedNick(_converse, muc_jid, ''); await test_utils.waitForReservedNick(_converse, muc_jid, '');
const input = await u.waitUntil(() => view.el.querySelector('input[name="nick"]'), 1000); const input = await u.waitUntil(() => view.el.querySelector('input[name="nick"]'), 1000);
expect(view.model.get('connection_status')).toBe(converse.ROOMSTATUS.NICKNAME_REQUIRED); expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.NICKNAME_REQUIRED);
input.value = 'nicky'; input.value = 'nicky';
view.el.querySelector('input[type=submit]').click(); view.el.querySelector('input[type=submit]').click();
expect(view.model.join).toHaveBeenCalled(); expect(view.model.join).toHaveBeenCalled();
_converse.connection.IQ_stanzas = []; _converse.connection.IQ_stanzas = [];
await test_utils.getRoomFeatures(_converse, muc_jid); await test_utils.getRoomFeatures(_converse, muc_jid);
await u.waitUntil(() => view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING); await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING);
// The user has just entered the room (because join was called) // The user has just entered the room (because join was called)
// and receives their own presence from the server. // and receives their own presence from the server.
...@@ -327,7 +327,7 @@ ...@@ -327,7 +327,7 @@
.c('status').attrs({code:'201'}).nodeTree; .c('status').attrs({code:'201'}).nodeTree;
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
await u.waitUntil(() => view.model.get('connection_status') === converse.ROOMSTATUS.ENTERED); await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED);
await test_utils.returnMemberLists(_converse, muc_jid); await test_utils.returnMemberLists(_converse, muc_jid);
// await u.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-info').length === 2); // await u.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-info').length === 2);
...@@ -419,7 +419,7 @@ ...@@ -419,7 +419,7 @@
await test_utils.waitForReservedNick(_converse, muc_jid, nick); await test_utils.waitForReservedNick(_converse, muc_jid, nick);
test_utils.receiveOwnMUCPresence(_converse, muc_jid, nick); test_utils.receiveOwnMUCPresence(_converse, muc_jid, nick);
const view = _converse.chatboxviews.get(muc_jid); const view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.ENTERED)); await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED));
// Check in reverse order that we requested all three lists // Check in reverse order that we requested all three lists
const owner_iq = sent_IQs.pop(); const owner_iq = sent_IQs.pop();
...@@ -2203,7 +2203,7 @@ ...@@ -2203,7 +2203,7 @@
const muc_jid = 'coven@chat.shakespeare.lit'; const muc_jid = 'coven@chat.shakespeare.lit';
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo'); await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
const view = _converse.chatboxviews.get(muc_jid); const view = _converse.chatboxviews.get(muc_jid);
expect(view.model.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED); expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED);
await test_utils.sendMessage(view, 'hello world'); await test_utils.sendMessage(view, 'hello world');
const stanza = u.toStanza(` const stanza = u.toStanza(`
...@@ -2258,7 +2258,7 @@ ...@@ -2258,7 +2258,7 @@
const muc_jid = 'coven@chat.shakespeare.lit'; const muc_jid = 'coven@chat.shakespeare.lit';
await test_utils.openAndEnterChatRoom(_converse, 'coven@chat.shakespeare.lit', 'romeo'); await test_utils.openAndEnterChatRoom(_converse, 'coven@chat.shakespeare.lit', 'romeo');
const view = _converse.chatboxviews.get(muc_jid); const view = _converse.chatboxviews.get(muc_jid);
expect(view.model.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED); expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED);
const stanza = u.toStanza(` const stanza = u.toStanza(`
<message from='${muc_jid}' <message from='${muc_jid}'
...@@ -2321,7 +2321,7 @@ ...@@ -2321,7 +2321,7 @@
const __ = _converse.__; const __ = _converse.__;
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'oldnick'); await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'oldnick');
const view = _converse.chatboxviews.get('lounge@montague.lit'); const view = _converse.chatboxviews.get('lounge@montague.lit');
expect(view.model.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED); expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED);
const chat_content = view.el.querySelector('.chat-content'); const chat_content = view.el.querySelector('.chat-content');
await u.waitUntil(() => view.el.querySelectorAll('li .occupant-nick').length, 500); await u.waitUntil(() => view.el.querySelectorAll('li .occupant-nick').length, 500);
...@@ -2355,7 +2355,7 @@ ...@@ -2355,7 +2355,7 @@
expect(sizzle('div.chat-info:last').pop().textContent.trim()).toBe( expect(sizzle('div.chat-info:last').pop().textContent.trim()).toBe(
__(_converse.muc.new_nickname_messages["303"], "newnick") __(_converse.muc.new_nickname_messages["303"], "newnick")
); );
expect(view.model.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED); expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED);
occupants = view.el.querySelector('.occupant-list'); occupants = view.el.querySelector('.occupant-list');
expect(occupants.childNodes.length).toBe(1); expect(occupants.childNodes.length).toBe(1);
...@@ -2374,7 +2374,7 @@ ...@@ -2374,7 +2374,7 @@
.c('status').attrs({code:'110'}).nodeTree; .c('status').attrs({code:'110'}).nodeTree;
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.model.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED); expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED);
// XXX: currently we still have an additional "has entered the groupchat" // XXX: currently we still have an additional "has entered the groupchat"
// notification for the new nickname. Ideally we'd not have // notification for the new nickname. Ideally we'd not have
// that, but that's probably not possible without some // that, but that's probably not possible without some
...@@ -2450,7 +2450,7 @@ ...@@ -2450,7 +2450,7 @@
.c('feature', {'var': 'muc_nonanonymous'}); .c('feature', {'var': 'muc_nonanonymous'});
_converse.connection._dataRecv(test_utils.createRequest(features_stanza)); _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
let view = _converse.chatboxviews.get('coven@chat.shakespeare.lit'); let view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
await u.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING)); await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
view = _converse.chatboxviews.get('coven@chat.shakespeare.lit'); view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
expect(view.model.features.get('fetched')).toBeTruthy(); expect(view.model.features.get('fetched')).toBeTruthy();
expect(view.model.features.get('passwordprotected')).toBe(true); expect(view.model.features.get('passwordprotected')).toBe(true);
...@@ -3898,7 +3898,7 @@ ...@@ -3898,7 +3898,7 @@
spyOn(_converse.api, "trigger").and.callThrough(); spyOn(_converse.api, "trigger").and.callThrough();
expect(_converse.chatboxes.length).toBe(2); expect(_converse.chatboxes.length).toBe(2);
_converse.connection._dataRecv(test_utils.createRequest(result_stanza)); _converse.connection._dataRecv(test_utils.createRequest(result_stanza));
await u.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.DISCONNECTED)); await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.DISCONNECTED));
await u.waitUntil(() => _converse.chatboxes.length === 1); await u.waitUntil(() => _converse.chatboxes.length === 1);
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object)); expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
done(); done();
...@@ -3986,7 +3986,7 @@ ...@@ -3986,7 +3986,7 @@
.c('feature', {'var': 'muc_temporary'}).up() .c('feature', {'var': 'muc_temporary'}).up()
.c('feature', {'var': 'muc_membersonly'}).up(); .c('feature', {'var': 'muc_membersonly'}).up();
_converse.connection._dataRecv(test_utils.createRequest(features_stanza)); _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
await u.waitUntil(() => view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING); await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING);
const presence = $pres().attrs({ const presence = $pres().attrs({
from: `${muc_jid}/romeo`, from: `${muc_jid}/romeo`,
...@@ -4031,7 +4031,7 @@ ...@@ -4031,7 +4031,7 @@
_converse.connection._dataRecv(test_utils.createRequest(features_stanza)); _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
const view = _converse.chatboxviews.get(muc_jid); const view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING); await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING);
const presence = $pres().attrs({ const presence = $pres().attrs({
from: `${muc_jid}/romeo`, from: `${muc_jid}/romeo`,
...@@ -4163,7 +4163,7 @@ ...@@ -4163,7 +4163,7 @@
_converse.connection._dataRecv(test_utils.createRequest(features_stanza)); _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
const view = _converse.chatboxviews.get(muc_jid); const view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING)); await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
const presence = $pres().attrs({ const presence = $pres().attrs({
from: `${muc_jid}/romeo`, from: `${muc_jid}/romeo`,
...@@ -4204,7 +4204,7 @@ ...@@ -4204,7 +4204,7 @@
_converse.connection._dataRecv(test_utils.createRequest(features_stanza)); _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
const view = _converse.chatboxviews.get(muc_jid); const view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING)); await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
const presence = $pres().attrs({ const presence = $pres().attrs({
from: `${muc_jid}/romeo`, from: `${muc_jid}/romeo`,
...@@ -4246,7 +4246,7 @@ ...@@ -4246,7 +4246,7 @@
_converse.connection._dataRecv(test_utils.createRequest(features_stanza)); _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
const view = _converse.chatboxviews.get(muc_jid); const view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING)); await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
const presence = $pres().attrs({ const presence = $pres().attrs({
from: `${muc_jid}/romeo`, from: `${muc_jid}/romeo`,
...@@ -4288,7 +4288,7 @@ ...@@ -4288,7 +4288,7 @@
_converse.connection._dataRecv(test_utils.createRequest(features_stanza)); _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
const view = _converse.chatboxviews.get(muc_jid); const view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING)); await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
const presence = $pres().attrs({ const presence = $pres().attrs({
from: `${muc_jid}/romeo`, from: `${muc_jid}/romeo`,
...@@ -4347,7 +4347,7 @@ ...@@ -4347,7 +4347,7 @@
.c('feature', {'var': 'muc_temporary'}).up() .c('feature', {'var': 'muc_temporary'}).up()
.c('feature', {'var': 'muc_membersonly'}).up(); .c('feature', {'var': 'muc_membersonly'}).up();
_converse.connection._dataRecv(test_utils.createRequest(features_stanza)); _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
await u.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING)); await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
expect(view.model.features.get('membersonly')).toBeTruthy(); expect(view.model.features.get('membersonly')).toBeTruthy();
await room_creation_promise; await room_creation_promise;
......
...@@ -181,7 +181,7 @@ ...@@ -181,7 +181,7 @@
.c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'}) .c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'})
.c('value').t(0); .c('value').t(0);
_converse.connection._dataRecv(test_utils.createRequest(features_stanza)); _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
await u.waitUntil(() => view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING) await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING)
let presence = $pres({ let presence = $pres({
to: _converse.connection.jid, to: _converse.connection.jid,
from: 'coven@chat.shakespeare.lit/some1', from: 'coven@chat.shakespeare.lit/some1',
......
...@@ -664,7 +664,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -664,7 +664,7 @@ converse.plugins.add('converse-muc-views', {
}); });
this.listenTo(this.model, 'change', this.renderHeading); this.listenTo(this.model, 'change', this.renderHeading);
this.listenTo(this.model, 'change:connection_status', this.onConnectionStatusChanged); this.listenTo(this.model.session, 'change:connection_status', this.onConnectionStatusChanged);
this.listenTo(this.model, 'change:hidden_occupants', this.updateOccupantsToggle); this.listenTo(this.model, 'change:hidden_occupants', this.updateOccupantsToggle);
this.listenTo(this.model, 'change:subject', this.setChatRoomSubject); this.listenTo(this.model, 'change:subject', this.setChatRoomSubject);
this.listenTo(this.model, 'configurationNeeded', this.getAndRenderConfigurationForm); this.listenTo(this.model, 'configurationNeeded', this.getAndRenderConfigurationForm);
...@@ -704,7 +704,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -704,7 +704,7 @@ converse.plugins.add('converse-muc-views', {
this.renderChatArea(); this.renderChatArea();
this.renderBottomPanel(); this.renderBottomPanel();
if (!_converse.muc_show_logs_before_join) { if (!_converse.muc_show_logs_before_join) {
this.model.get('connection_status') !== converse.ROOMSTATUS.ENTERED && this.showSpinner(); this.model.session.get('connection_status') !== converse.ROOMSTATUS.ENTERED && this.showSpinner();
} }
if (!this.model.get('hidden')) { if (!this.model.get('hidden')) {
this.show(); this.show();
...@@ -723,7 +723,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -723,7 +723,7 @@ converse.plugins.add('converse-muc-views', {
renderBottomPanel () { renderBottomPanel () {
const container = this.el.querySelector('.bottom-panel'); const container = this.el.querySelector('.bottom-panel');
const entered = this.model.get('connection_status') === converse.ROOMSTATUS.ENTERED; const entered = this.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED;
const can_edit = entered && !(this.model.features.get('moderated') && this.model.getOwnRole() === 'visitor'); const can_edit = entered && !(this.model.features.get('moderated') && this.model.getOwnRole() === 'visitor');
container.innerHTML = tpl_chatroom_bottom_panel({__, can_edit, entered}); container.innerHTML = tpl_chatroom_bottom_panel({__, can_edit, entered});
if (entered && can_edit) { if (entered && can_edit) {
...@@ -1127,7 +1127,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1127,7 +1127,7 @@ converse.plugins.add('converse-muc-views', {
}, },
onConnectionStatusChanged () { onConnectionStatusChanged () {
const conn_status = this.model.get('connection_status'); const conn_status = this.model.session.get('connection_status');
if (conn_status === converse.ROOMSTATUS.NICKNAME_REQUIRED) { if (conn_status === converse.ROOMSTATUS.NICKNAME_REQUIRED) {
this.renderNicknameForm(); this.renderNicknameForm();
} else if (conn_status === converse.ROOMSTATUS.PASSWORD_REQUIRED) { } else if (conn_status === converse.ROOMSTATUS.PASSWORD_REQUIRED) {
...@@ -1562,7 +1562,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1562,7 +1562,7 @@ converse.plugins.add('converse-muc-views', {
const container = this.el.querySelector('.chatroom-body'); const container = this.el.querySelector('.chatroom-body');
container.insertAdjacentHTML('beforeend', html); container.insertAdjacentHTML('beforeend', html);
} }
u.safeSave(this.model, {'connection_status': converse.ROOMSTATUS.NICKNAME_REQUIRED}); u.safeSave(this.model.session, {'connection_status': converse.ROOMSTATUS.NICKNAME_REQUIRED});
}, },
closeForm () { closeForm () {
...@@ -1623,7 +1623,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1623,7 +1623,7 @@ converse.plugins.add('converse-muc-views', {
this.password_form.model.set('validation_message', message); this.password_form.model.set('validation_message', message);
} }
u.showElement(this.password_form.el); u.showElement(this.password_form.el);
this.model.save('connection_status', converse.ROOMSTATUS.PASSWORD_REQUIRED); this.model.session.save('connection_status', converse.ROOMSTATUS.PASSWORD_REQUIRED);
}, },
showDestroyedMessage () { showDestroyedMessage () {
...@@ -1734,7 +1734,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1734,7 +1734,7 @@ converse.plugins.add('converse-muc-views', {
}, },
onOccupantRemoved (occupant) { onOccupantRemoved (occupant) {
if (this.model.get('connection_status') === converse.ROOMSTATUS.ENTERED && if (this.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED &&
occupant.get('show') === 'online') { occupant.get('show') === 'online') {
this.showLeaveNotification(occupant); this.showLeaveNotification(occupant);
} }
...@@ -1784,7 +1784,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1784,7 +1784,7 @@ converse.plugins.add('converse-muc-views', {
showJoinNotification (occupant) { showJoinNotification (occupant) {
if (!_converse.muc_show_join_leave || if (!_converse.muc_show_join_leave ||
this.model.get('connection_status') !== converse.ROOMSTATUS.ENTERED) { this.model.session.get('connection_status') !== converse.ROOMSTATUS.ENTERED) {
return; return;
} }
const nick = occupant.get('nick'), const nick = occupant.get('nick'),
...@@ -1899,11 +1899,12 @@ converse.plugins.add('converse-muc-views', { ...@@ -1899,11 +1899,12 @@ converse.plugins.add('converse-muc-views', {
* @method _converse.ChatRoomView#renderAfterTransition * @method _converse.ChatRoomView#renderAfterTransition
*/ */
renderAfterTransition () { renderAfterTransition () {
if (this.model.get('connection_status') == converse.ROOMSTATUS.NICKNAME_REQUIRED) { const conn_status = this.model.session.get('connection_status')
if (conn_status == converse.ROOMSTATUS.NICKNAME_REQUIRED) {
this.renderNicknameForm(); this.renderNicknameForm();
} else if (this.model.get('connection_status') == converse.ROOMSTATUS.PASSWORD_REQUIRED) { } else if (conn_status == converse.ROOMSTATUS.PASSWORD_REQUIRED) {
this.renderPasswordForm(); this.renderPasswordForm();
} else if (this.model.get('connection_status') == converse.ROOMSTATUS.ENTERED) { } else if (conn_status == converse.ROOMSTATUS.ENTERED) {
this.hideChatRoomContents(); this.hideChatRoomContents();
u.showElement(this.el.querySelector('.chat-area')); u.showElement(this.el.querySelector('.chat-area'));
u.showElement(this.el.querySelector('.occupants')); u.showElement(this.el.querySelector('.occupants'));
......
...@@ -224,7 +224,7 @@ converse.plugins.add('converse-mam', { ...@@ -224,7 +224,7 @@ converse.plugins.add('converse-mam', {
function preMUCJoinMAMFetch (room) { function preMUCJoinMAMFetch (room) {
if (!_converse.muc_show_logs_before_join || if (!_converse.muc_show_logs_before_join ||
!room.features.get('mam_enabled') || !room.features.get('mam_enabled') ||
room.get('connection_status') !== converse.ROOMSTATUS.ENTERED || room.session.get('connection_status') !== converse.ROOMSTATUS.ENTERED ||
room.get('prejoin_mam_fetched')) { room.get('prejoin_mam_fetched')) {
return; return;
} }
......
...@@ -322,6 +322,15 @@ converse.plugins.add('converse-muc', { ...@@ -322,6 +322,15 @@ converse.plugins.add('converse-muc', {
}); });
const MUCSession = Backbone.Model.extend({
defaults () {
return {
'connection_status': converse.ROOMSTATUS.DISCONNECTED
}
}
});
/** /**
* Collection which stores MUC messages * Collection which stores MUC messages
* @class * @class
...@@ -357,7 +366,6 @@ converse.plugins.add('converse-muc', { ...@@ -357,7 +366,6 @@ converse.plugins.add('converse-muc', {
'bookmarked': false, 'bookmarked': false,
'chat_state': undefined, 'chat_state': undefined,
'connection_status': converse.ROOMSTATUS.DISCONNECTED,
'description': '', 'description': '',
'hidden': ['mobile', 'fullscreen'].includes(_converse.view_mode), 'hidden': ['mobile', 'fullscreen'].includes(_converse.view_mode),
'message_type': 'groupchat', 'message_type': 'groupchat',
...@@ -372,12 +380,18 @@ converse.plugins.add('converse-muc', { ...@@ -372,12 +380,18 @@ converse.plugins.add('converse-muc', {
async initialize() { async initialize() {
this.initialized = u.getResolveablePromise(); this.initialized = u.getResolveablePromise();
const id = `muc.session-${this.get('jid')}`;
this.session = new MUCSession({id});
this.session.browserStorage = _converse.createStore(id, "session");
await new Promise(r => this.session.fetch({'success': r, 'error': r}));
this.setVCard(); this.setVCard();
this.set('box_id', `box-${btoa(this.get('jid'))}`); this.set('box_id', `box-${btoa(this.get('jid'))}`);
this.initFeatures(); // sendChatState depends on this.features this.initFeatures(); // sendChatState depends on this.features
this.on('change:chat_state', this.sendChatState, this); this.on('change:chat_state', this.sendChatState, this);
this.on('change:connection_status', this.onConnectionStatusChanged, this); this.session.on('change:connection_status', this.onConnectionStatusChanged, this);
this.initMessages(); this.initMessages();
this.initOccupants(); this.initOccupants();
...@@ -405,7 +419,7 @@ converse.plugins.add('converse-muc', { ...@@ -405,7 +419,7 @@ converse.plugins.add('converse-muc', {
* @returns { Boolean } Returns `true` if we're still joined, otherwise returns `false`. * @returns { Boolean } Returns `true` if we're still joined, otherwise returns `false`.
*/ */
async restoreFromCache () { async restoreFromCache () {
if (this.get('connection_status') === converse.ROOMSTATUS.ENTERED && await this.isJoined()) { if (this.session.get('connection_status') === converse.ROOMSTATUS.ENTERED && await this.isJoined()) {
// We've restored the room from cache and we're still joined. // We've restored the room from cache and we're still joined.
await new Promise(resolve => this.features.fetch({'success': resolve, 'error': resolve})); await new Promise(resolve => this.features.fetch({'success': resolve, 'error': resolve}));
await this.fetchOccupants(); await this.fetchOccupants();
...@@ -425,7 +439,7 @@ converse.plugins.add('converse-muc', { ...@@ -425,7 +439,7 @@ converse.plugins.add('converse-muc', {
* @param { String } [password] - Optional password, if required by the groupchat. * @param { String } [password] - Optional password, if required by the groupchat.
*/ */
async join (nick, password) { async join (nick, password) {
if (this.get('connection_status') === converse.ROOMSTATUS.ENTERED) { if (this.session.get('connection_status') === converse.ROOMSTATUS.ENTERED) {
// We have restored a groupchat from session storage, // We have restored a groupchat from session storage,
// so we don't send out a presence stanza again. // so we don't send out a presence stanza again.
return this; return this;
...@@ -433,7 +447,7 @@ converse.plugins.add('converse-muc', { ...@@ -433,7 +447,7 @@ converse.plugins.add('converse-muc', {
await this.refreshRoomFeatures(); await this.refreshRoomFeatures();
nick = await this.getAndPersistNickname(nick); nick = await this.getAndPersistNickname(nick);
if (!nick) { if (!nick) {
u.safeSave(this, {'connection_status': converse.ROOMSTATUS.NICKNAME_REQUIRED}); u.safeSave(this.session, {'connection_status': converse.ROOMSTATUS.NICKNAME_REQUIRED});
if (_converse.muc_show_logs_before_join) { if (_converse.muc_show_logs_before_join) {
await this.fetchMessages(); await this.fetchMessages();
} }
...@@ -448,13 +462,13 @@ converse.plugins.add('converse-muc', { ...@@ -448,13 +462,13 @@ converse.plugins.add('converse-muc', {
if (password) { if (password) {
stanza.cnode(Strophe.xmlElement("password", [], password)); stanza.cnode(Strophe.xmlElement("password", [], password));
} }
this.save('connection_status', converse.ROOMSTATUS.CONNECTING); this.session.save('connection_status', converse.ROOMSTATUS.CONNECTING);
_converse.api.send(stanza); _converse.api.send(stanza);
return this; return this;
}, },
async clearCache () { async clearCache () {
this.save('connection_status', converse.ROOMSTATUS.DISCONNECTED); this.session.save('connection_status', converse.ROOMSTATUS.DISCONNECTED);
if (this.occupants.length) { if (this.occupants.length) {
// Remove non-members when reconnecting // Remove non-members when reconnecting
this.occupants.filter(o => !o.isMember()).forEach(o => o.destroy()); this.occupants.filter(o => !o.isMember()).forEach(o => o.destroy());
...@@ -478,7 +492,7 @@ converse.plugins.add('converse-muc', { ...@@ -478,7 +492,7 @@ converse.plugins.add('converse-muc', {
}, },
async onConnectionStatusChanged () { async onConnectionStatusChanged () {
if (this.get('connection_status') === converse.ROOMSTATUS.ENTERED) { if (this.session.get('connection_status') === converse.ROOMSTATUS.ENTERED) {
if (_converse.muc_fetch_members) { if (_converse.muc_fetch_members) {
await this.occupants.fetchMembers(); await this.occupants.fetchMembers();
} }
...@@ -739,18 +753,21 @@ converse.plugins.add('converse-muc', { ...@@ -739,18 +753,21 @@ converse.plugins.add('converse-muc', {
if (_converse.api.connection.connected()) { if (_converse.api.connection.connected()) {
this.sendUnavailablePresence(exit_msg); this.sendUnavailablePresence(exit_msg);
} }
u.safeSave(this, {'connection_status': converse.ROOMSTATUS.DISCONNECTED}); u.safeSave(this.session, {'connection_status': converse.ROOMSTATUS.DISCONNECTED});
this.removeHandlers(); this.removeHandlers();
}, },
async close () { async close () {
try { // Delete the session model
await new Promise((success, reject) => { await new Promise(resolve => this.session.destroy({
return this.features.destroy({success, 'error': (m, e) => reject(e)}) 'success': resolve,
}); 'error': (m, e) => { log.error(e); resolve() }
} catch (e) { }));
log.error(e); // Delete the features model
} await new Promise(resolve => this.features.destroy({
'success': resolve,
'error': (m, e) => { log.error(e); resolve() }
}));
return _converse.ChatBox.prototype.close.call(this); return _converse.ChatBox.prototype.close.call(this);
}, },
...@@ -878,7 +895,7 @@ converse.plugins.add('converse-muc', { ...@@ -878,7 +895,7 @@ converse.plugins.add('converse-muc', {
sendChatState () { sendChatState () {
if (!_converse.send_chat_state_notifications || if (!_converse.send_chat_state_notifications ||
!this.get('chat_state') || !this.get('chat_state') ||
this.get('connection_status') !== converse.ROOMSTATUS.ENTERED || this.session.get('connection_status') !== converse.ROOMSTATUS.ENTERED ||
this.features.get('moderated') && this.getOwnRole() === 'visitor') { this.features.get('moderated') && this.getOwnRole() === 'visitor') {
return; return;
} }
...@@ -1762,7 +1779,7 @@ converse.plugins.add('converse-muc', { ...@@ -1762,7 +1779,7 @@ converse.plugins.add('converse-muc', {
handleModifyError(pres) { handleModifyError(pres) {
const text = get(pres.querySelector('error text'), 'textContent'); const text = get(pres.querySelector('error text'), 'textContent');
if (text) { if (text) {
if (this.get('connection_status') === converse.ROOMSTATUS.CONNECTING) { if (this.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING) {
this.setDisconnectionMessage(text); this.setDisconnectionMessage(text);
} else { } else {
const attrs = { const attrs = {
...@@ -1858,11 +1875,11 @@ converse.plugins.add('converse-muc', { ...@@ -1858,11 +1875,11 @@ converse.plugins.add('converse-muc', {
setDisconnectionMessage (message, reason, actor) { setDisconnectionMessage (message, reason, actor) {
this.save({ this.save({
'connection_status': converse.ROOMSTATUS.DISCONNECTED,
'disconnection_message': message, 'disconnection_message': message,
'disconnection_reason': reason, 'disconnection_reason': reason,
'disconnection_actor': actor 'disconnection_actor': actor
}); });
this.session.save({'connection_status': converse.ROOMSTATUS.DISCONNECTED});
}, },
...@@ -1880,9 +1897,10 @@ converse.plugins.add('converse-muc', { ...@@ -1880,9 +1897,10 @@ converse.plugins.add('converse-muc', {
this.save({ this.save({
'nickname_validation_message': __( 'nickname_validation_message': __(
"The nickname you chose is reserved or "+ "The nickname you chose is reserved or "+
"currently in use, please choose a different one."), "currently in use, please choose a different one."
'connection_status': converse.ROOMSTATUS.NICKNAME_REQUIRED )
}); });
this.session.save({'connection_status': converse.ROOMSTATUS.NICKNAME_REQUIRED});
} }
}, },
...@@ -1903,10 +1921,8 @@ converse.plugins.add('converse-muc', { ...@@ -1903,10 +1921,8 @@ converse.plugins.add('converse-muc', {
this.handleModifyError(stanza); this.handleModifyError(stanza);
} else if (error_type === 'auth') { } else if (error_type === 'auth') {
if (sizzle(`not-authorized[xmlns="${Strophe.NS.STANZAS}"]`, error).length) { if (sizzle(`not-authorized[xmlns="${Strophe.NS.STANZAS}"]`, error).length) {
this.save({ this.save({'password_validation_message': reason || __("Password incorrect")});
'password_validation_message': reason || __("Password incorrect"), this.session.save({'connection_status': converse.ROOMSTATUS.PASSWORD_REQUIRED});
'connection_status': converse.ROOMSTATUS.PASSWORD_REQUIRED
});
} }
if (error.querySelector('registration-required')) { if (error.querySelector('registration-required')) {
const message = __('You are not on the member list of this groupchat.'); const message = __('You are not on the member list of this groupchat.');
...@@ -1926,11 +1942,8 @@ converse.plugins.add('converse-muc', { ...@@ -1926,11 +1942,8 @@ converse.plugins.add('converse-muc', {
const moved_jid = get(sizzle(`gone[xmlns="${Strophe.NS.STANZAS}"]`, error).pop(), 'textContent') const moved_jid = get(sizzle(`gone[xmlns="${Strophe.NS.STANZAS}"]`, error).pop(), 'textContent')
.replace(/^xmpp:/, '') .replace(/^xmpp:/, '')
.replace(/\?join$/, ''); .replace(/\?join$/, '');
this.save({ this.save({ moved_jid, 'destroyed_reason': reason});
'connection_status': converse.ROOMSTATUS.DESTROYED, this.session.save({'connection_status': converse.ROOMSTATUS.DESTROYED});
'destroyed_reason': reason,
'moved_jid': moved_jid
});
} else if (error.querySelector('conflict')) { } else if (error.querySelector('conflict')) {
this.onNicknameClash(stanza); this.onNicknameClash(stanza);
} else if (error.querySelector('item-not-found')) { } else if (error.querySelector('item-not-found')) {
...@@ -1962,8 +1975,8 @@ converse.plugins.add('converse-muc', { ...@@ -1962,8 +1975,8 @@ converse.plugins.add('converse-muc', {
if (stanza.querySelector("status[code='110']")) { if (stanza.querySelector("status[code='110']")) {
this.onOwnPresence(stanza); this.onOwnPresence(stanza);
if (this.getOwnRole() !== 'none' && if (this.getOwnRole() !== 'none' &&
this.get('connection_status') === converse.ROOMSTATUS.CONNECTING) { this.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING) {
this.save('connection_status', converse.ROOMSTATUS.CONNECTED); this.session.save('connection_status', converse.ROOMSTATUS.CONNECTED);
} }
} else { } else {
this.updateOccupantsOnPresence(stanza); this.updateOccupantsOnPresence(stanza);
...@@ -1987,7 +2000,7 @@ converse.plugins.add('converse-muc', { ...@@ -1987,7 +2000,7 @@ converse.plugins.add('converse-muc', {
*/ */
onOwnPresence (stanza) { onOwnPresence (stanza) {
if (stanza.getAttribute('type') !== 'unavailable') { if (stanza.getAttribute('type') !== 'unavailable') {
this.save('connection_status', converse.ROOMSTATUS.ENTERED); this.session.save('connection_status', converse.ROOMSTATUS.ENTERED);
} }
this.updateOccupantsOnPresence(stanza); this.updateOccupantsOnPresence(stanza);
...@@ -2026,7 +2039,7 @@ converse.plugins.add('converse-muc', { ...@@ -2026,7 +2039,7 @@ converse.plugins.add('converse-muc', {
} }
} }
} }
this.save({'connection_status': converse.ROOMSTATUS.ENTERED}); this.session.save({'connection_status': converse.ROOMSTATUS.ENTERED});
}, },
/** /**
...@@ -2247,7 +2260,7 @@ converse.plugins.add('converse-muc', { ...@@ -2247,7 +2260,7 @@ converse.plugins.add('converse-muc', {
} }
if (result === true) { if (result === true) {
const chatroom = await openChatRoom(room_jid, {'password': x_el.getAttribute('password') }); const chatroom = await openChatRoom(room_jid, {'password': x_el.getAttribute('password') });
if (chatroom.get('connection_status') === converse.ROOMSTATUS.DISCONNECTED) { if (chatroom.session.get('connection_status') === converse.ROOMSTATUS.DISCONNECTED) {
_converse.chatboxes.get(room_jid).rejoin(); _converse.chatboxes.get(room_jid).rejoin();
} }
} }
...@@ -2311,7 +2324,7 @@ converse.plugins.add('converse-muc', { ...@@ -2311,7 +2324,7 @@ converse.plugins.add('converse-muc', {
/************************ BEGIN Event Handlers ************************/ /************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('beforeTearDown', () => { _converse.api.listen.on('beforeTearDown', () => {
const groupchats = _converse.chatboxes.where({'type': _converse.CHATROOMS_TYPE}); const groupchats = _converse.chatboxes.where({'type': _converse.CHATROOMS_TYPE});
groupchats.forEach(gc => u.safeSave(gc, {'connection_status': converse.ROOMSTATUS.DISCONNECTED})); groupchats.forEach(muc => u.safeSave(muc.session, {'connection_status': converse.ROOMSTATUS.DISCONNECTED}));
}); });
_converse.api.listen.on('windowStateChanged', onWindowStateChanged); _converse.api.listen.on('windowStateChanged', onWindowStateChanged);
...@@ -2334,7 +2347,7 @@ converse.plugins.add('converse-muc', { ...@@ -2334,7 +2347,7 @@ converse.plugins.add('converse-muc', {
*/ */
return _converse.chatboxes return _converse.chatboxes
.filter(m => (m.get('type') === _converse.CHATROOMS_TYPE)) .filter(m => (m.get('type') === _converse.CHATROOMS_TYPE))
.forEach(m => m.save({'connection_status': converse.ROOMSTATUS.DISCONNECTED})); .forEach(m => m.session.save({'connection_status': converse.ROOMSTATUS.DISCONNECTED}));
} }
_converse.api.listen.on('disconnected', disconnectChatRooms); _converse.api.listen.on('disconnected', disconnectChatRooms);
......
...@@ -286,7 +286,6 @@ ...@@ -286,7 +286,6 @@
}).up() }).up()
.c('status').attrs({code:'110'}); .c('status').attrs({code:'110'});
_converse.connection._dataRecv(utils.createRequest(presence)); _converse.connection._dataRecv(utils.createRequest(presence));
// return utils.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.ENTERED));
}; };
...@@ -302,7 +301,7 @@ ...@@ -302,7 +301,7 @@
await room_creation_promise; await room_creation_promise;
const view = _converse.chatboxviews.get(muc_jid); const view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.ENTERED)); await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED));
if (_converse.muc_fetch_members) { if (_converse.muc_fetch_members) {
await utils.returnMemberLists(_converse, muc_jid, members); await utils.returnMemberLists(_converse, muc_jid, members);
} }
......
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