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