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);
......
This diff is collapsed.
...@@ -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;
} }
......
This diff is collapsed.
...@@ -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