Commit ffbab33a authored by JC Brand's avatar JC Brand

Create own occupant before setting `connection_status` to ENTERED

This makes it possible to wait for the connection_status before trying
to call `getOwnOccupant` in plugins
parent b7654f1f
...@@ -272,6 +272,7 @@ describe("Groupchats", function () { ...@@ -272,6 +272,7 @@ describe("Groupchats", function () {
let IQ_stanzas = _converse.connection.IQ_stanzas; let IQ_stanzas = _converse.connection.IQ_stanzas;
const muc_jid = 'lounge@montague.lit'; const muc_jid = 'lounge@montague.lit';
const nick = 'nicky';
await mock.openChatRoom(_converse, 'lounge', 'montague.lit', 'romeo'); await mock.openChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
const disco_selector = `iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`; const disco_selector = `iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`;
...@@ -291,12 +292,14 @@ describe("Groupchats", function () { ...@@ -291,12 +292,14 @@ describe("Groupchats", function () {
await mock.waitForReservedNick(_converse, muc_jid, ''); await mock.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.session.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 = nick;
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 mock.getRoomFeatures(_converse, muc_jid); await mock.getRoomFeatures(_converse, muc_jid);
await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING); await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING);
await mock.receiveOwnMUCPresence(_converse, muc_jid, nick);
// 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.
......
...@@ -2339,9 +2339,15 @@ converse.plugins.add('converse-muc', { ...@@ -2339,9 +2339,15 @@ converse.plugins.add('converse-muc', {
*/ */
onOwnPresence (stanza) { onOwnPresence (stanza) {
if (stanza.getAttribute('type') !== 'unavailable') { if (stanza.getAttribute('type') !== 'unavailable') {
this.session.save('connection_status', converse.ROOMSTATUS.ENTERED); // Set connection_status before creating the occupant, but
// only trigger afterwards, so that plugins can access the
// occupant in their event handlers.
this.session.save('connection_status', converse.ROOMSTATUS.ENTERED, {'silent': true});
this.updateOccupantsOnPresence(stanza);
this.session.trigger('change:connection_status');
} else {
this.updateOccupantsOnPresence(stanza);
} }
this.updateOccupantsOnPresence(stanza);
if (stanza.getAttribute('type') === 'unavailable') { if (stanza.getAttribute('type') === 'unavailable') {
this.handleDisconnection(stanza); this.handleDisconnection(stanza);
......
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