Commit 40469a97 authored by JC Brand's avatar JC Brand

MUC: Refresh room features when re-entering a cached room

Only fetch messages after we have the latest room features
Otherwise we run into race conditions where MAM messages are fetched
before we know whether (updated) the room supports MAM or not.
parent ac007bb5
...@@ -2120,11 +2120,14 @@ ...@@ -2120,11 +2120,14 @@
<not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> <not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
</error> </error>
</iq>`); </iq>`);
_converse.connection.sent_stanzas = [];
sent_stanzas = _converse.connection.sent_stanzas; sent_stanzas = _converse.connection.sent_stanzas;
const index = sent_stanzas.length -1;
_converse.connection._dataRecv(test_utils.createRequest(result)); _converse.connection._dataRecv(test_utils.createRequest(result));
await test_utils.getRoomFeatures(_converse, 'coven', 'chat.shakespeare.lit');
const pres = await test_utils.waitUntil( const pres = await test_utils.waitUntil(
() => sent_stanzas.filter(s => s.nodeName === 'presence').pop()); () => sent_stanzas.slice(index).filter(s => s.nodeName === 'presence').pop());
expect(Strophe.serialize(pres)).toBe( expect(Strophe.serialize(pres)).toBe(
`<presence from="${_converse.jid}" to="coven@chat.shakespeare.lit/romeo" xmlns="jabber:client">`+ `<presence from="${_converse.jid}" to="coven@chat.shakespeare.lit/romeo" xmlns="jabber:client">`+
`<x xmlns="http://jabber.org/protocol/muc"><history maxstanzas="0"/></x>`+ `<x xmlns="http://jabber.org/protocol/muc"><history maxstanzas="0"/></x>`+
......
...@@ -307,6 +307,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -307,6 +307,7 @@ converse.plugins.add('converse-chatboxes', {
} }
this.on('change:chat_state', this.sendChatState, this); this.on('change:chat_state', this.sendChatState, this);
this.initMessages(); this.initMessages();
this.fetchMessages();
}, },
initMessages () { initMessages () {
...@@ -320,7 +321,6 @@ converse.plugins.add('converse-chatboxes', { ...@@ -320,7 +321,6 @@ converse.plugins.add('converse-chatboxes', {
_converse.api.send(this.createMessageStanza(message)); _converse.api.send(this.createMessageStanza(message));
} }
}); });
this.fetchMessages();
}, },
afterMessagesFetched () { afterMessagesFetched () {
......
...@@ -211,7 +211,7 @@ converse.plugins.add('converse-disco', { ...@@ -211,7 +211,7 @@ converse.plugins.add('converse-disco', {
}); });
// XEP-0128 Service Discovery Extensions // XEP-0128 Service Discovery Extensions
_.forEach(sizzle('x[type="result"][xmlns="jabber:x:data"] field', stanza), field => { sizzle('x[type="result"][xmlns="jabber:x:data"] field', stanza).forEach(field => {
this.fields.create({ this.fields.create({
'var': field.getAttribute('var'), 'var': field.getAttribute('var'),
'value': _.get(field.querySelector('value'), 'textContent'), 'value': _.get(field.querySelector('value'), 'textContent'),
......
...@@ -300,16 +300,18 @@ converse.plugins.add('converse-muc', { ...@@ -300,16 +300,18 @@ converse.plugins.add('converse-muc', {
if (conn_status !== converse.ROOMSTATUS.ENTERED) { if (conn_status !== converse.ROOMSTATUS.ENTERED) {
// We're not restoring a room from cache, so let's clear // We're not restoring a room from cache, so let's clear
// the cache (which might be stale). // the cache (which might be stale).
this.clearMessages();
this.clearOccupants(); this.clearOccupants();
await this.refreshRoomFeatures();
await this.getRoomFeatures(); this.clearMessages(); // XXX: This should be conditional
this.fetchMessages();
if (!u.isPersistableModel(this)) { if (!u.isPersistableModel(this)) {
// XXX: Happens during tests, nothing to do if this // XXX: Happens during tests, nothing to do if this
// is a hanging chatbox (i.e. not in the collection anymore). // is a hanging chatbox (i.e. not in the collection anymore).
return; return;
} }
this.join(); this.join();
} else {
this.features.fetch();
} }
}, },
...@@ -350,7 +352,6 @@ converse.plugins.add('converse-muc', { ...@@ -350,7 +352,6 @@ converse.plugins.add('converse-muc', {
_.assign({id}, _.zipObject(converse.ROOM_FEATURES, _.map(converse.ROOM_FEATURES, _.stubFalse))) _.assign({id}, _.zipObject(converse.ROOM_FEATURES, _.map(converse.ROOM_FEATURES, _.stubFalse)))
); );
this.features.browserStorage = new BrowserStorage.session(id); this.features.browserStorage = new BrowserStorage.session(id);
this.features.fetch();
}, },
initOccupants () { initOccupants () {
...@@ -1188,15 +1189,14 @@ converse.plugins.add('converse-muc', { ...@@ -1188,15 +1189,14 @@ converse.plugins.add('converse-muc', {
}, },
fetchFeaturesIfConfigurationChanged (stanza) { fetchFeaturesIfConfigurationChanged (stanza) {
const configuration_changed = stanza.querySelector("status[code='104']"), // 104: configuration change
logging_enabled = stanza.querySelector("status[code='170']"), // 170: logging enabled
logging_disabled = stanza.querySelector("status[code='171']"), // 171: logging disabled
room_no_longer_anon = stanza.querySelector("status[code='172']"), // 172: room no longer anonymous
room_now_semi_anon = stanza.querySelector("status[code='173']"), // 173: room now semi-anonymous
room_now_fully_anon = stanza.querySelector("status[code='173']"); // 174: room now fully anonymous
const codes = ['104', '170', '171', '172', '173', '174'];
if (configuration_changed || logging_enabled || logging_disabled || if (sizzle('status', stanza).filter(e => codes.includes(e.getAttribute('status'))).length) {
room_no_longer_anon || room_now_semi_anon || room_now_fully_anon) {
this.refreshRoomFeatures(); this.refreshRoomFeatures();
} }
}, },
......
...@@ -123,8 +123,9 @@ ...@@ -123,8 +123,9 @@
utils.getRoomFeatures = async function (_converse, room, server, features=[]) { utils.getRoomFeatures = async function (_converse, room, server, features=[]) {
const room_jid = `${room}@${server}`.toLowerCase(); const room_jid = `${room}@${server}`.toLowerCase();
const stanzas = _converse.connection.IQ_stanzas; const stanzas = _converse.connection.IQ_stanzas;
const index = stanzas.length-1;
const stanza = await utils.waitUntil(() => _.filter( const stanza = await utils.waitUntil(() => _.filter(
stanzas, stanzas.slice(index),
iq => iq.querySelector( iq => iq.querySelector(
`iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]` `iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
)).pop()); )).pop());
......
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