Bugfix. Room features weren't being refreshed properly

We were removing the disco entity, but it's associated collections
(`features`, `fields`, `identities` etc) were still stored in
localStorage and not cleared.

So when the entity gets recreated, the stale localStorage cached items
repopulate the collections.

Added `refreshFeatures` API method for refetching disco features and use
that instead.
This commit is contained in:
JC Brand 2018-10-05 04:39:19 +02:00
parent c1106f3867
commit d426d79702
3 changed files with 44 additions and 10 deletions

View File

@ -1,5 +1,10 @@
# Changelog # Changelog
## 4.0.3 (Unreleased)
- Bugfix. Handler not triggered when submitting MUC password form 2nd time
- Bugfix. MUC features weren't being refreshed when saving the config form
## 4.0.2 (2018-10-02) ## 4.0.2 (2018-10-02)
- M4A and WEBM files, when sent as XEP-0066 Out of Band Data, are now playable directly in chat - M4A and WEBM files, when sent as XEP-0066 Out of Band Data, are now playable directly in chat
@ -9,6 +14,7 @@
- #1189 Video playback failure - #1189 Video playback failure
- #1220 Converse not working in Edge - #1220 Converse not working in Edge
- #1225 User profile sometimes not displayed when libsignal-protocol.js is used - #1225 User profile sometimes not displayed when libsignal-protocol.js is used
- #1227 Login form does not work in Epiphany
## 4.0.1 (2018-09-19) ## 4.0.1 (2018-09-19)

View File

@ -137,7 +137,7 @@
queryInfo () { queryInfo () {
_converse.api.disco.info(this.get('jid'), null) _converse.api.disco.info(this.get('jid'), null)
.then((stanza) => this.onInfo(stanza)) .then(stanza => this.onInfo(stanza))
.catch(iq => { .catch(iq => {
this.waitUntilFeaturesDiscovered.resolve(this); this.waitUntilFeaturesDiscovered.resolve(this);
_converse.log(iq, Strophe.LogLevel.ERROR); _converse.log(iq, Strophe.LogLevel.ERROR);
@ -576,11 +576,39 @@
}).then(result => f.filter(f.isObject, result)); }).then(result => f.filter(f.isObject, result));
}, },
/**
* Refresh the features (and fields and identities) associated with a
* disco entity by refetching them from the server
*
* @method _converse.api.disco.refreshFeatures
* @param {string} jid The JID of the entity whose features are refreshed.
* @returns {promise} A promise which resolves once the features have been refreshed
* @example
* await _converse.api.disco.refreshFeatures('room@conference.example.org');
*/
'refreshFeatures' (jid) {
if (_.isNil(jid)) {
throw new TypeError('api.disco.refreshFeatures: You need to provide an entity JID');
}
return _converse.api.waitUntil('discoInitialized')
.then(() => _converse.api.disco.entities.get(jid, true))
.then(entity => {
entity.features.reset();
entity.fields.reset();
entity.identities.reset();
entity.waitUntilFeaturesDiscovered = utils.getResolveablePromise()
entity.queryInfo();
return entity.waitUntilFeaturesDiscovered();
})
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
},
/** /**
* Return all the features associated with a disco entity * Return all the features associated with a disco entity
* *
* @method _converse.api.disco.getFeatures * @method _converse.api.disco.getFeatures
* @param {string} jid The JID of the entity whose features are returned. * @param {string} jid The JID of the entity whose features are returned.
* @returns {promise} A promise which resolves with the returned features
* @example * @example
* const features = await _converse.api.disco.getFeatures('room@conference.example.org'); * const features = await _converse.api.disco.getFeatures('room@conference.example.org');
*/ */

View File

@ -70,8 +70,10 @@
overrides: { overrides: {
tearDown () { tearDown () {
const groupchats = this.chatboxes.where({'type': this.CHATROOMS_TYPE}); const { _converse } = this.__super__,
_.each(groupchats, gc => u.safeSave(gc, {'connection_status': this.ROOMSTATUS.DISCONNECTED})); groupchats = this.chatboxes.where({'type': _converse.CHATROOMS_TYPE});
_.each(groupchats, gc => u.safeSave(gc, {'connection_status': converse.ROOMSTATUS.DISCONNECTED}));
this.__super__.tearDown.call(this, arguments); this.__super__.tearDown.call(this, arguments);
}, },
@ -477,11 +479,8 @@
}); });
}, },
refreshRoomFeatures () { async refreshRoomFeatures () {
const entity = _converse.disco_entities.get(this.get('jid')); await _converse.api.disco.refreshFeatures(this.get('jid'));
if (entity) {
entity.destroy();
}
return this.getRoomFeatures(); return this.getRoomFeatures();
}, },
@ -493,6 +492,7 @@
'features_fetched': moment().format(), 'features_fetched': moment().format(),
'name': identity && identity.get('name') 'name': identity && identity.get('name')
}; };
features.each(feature => { features.each(feature => {
const fieldname = feature.get('var'); const fieldname = feature.get('var');
if (!fieldname.startsWith('muc_')) { if (!fieldname.startsWith('muc_')) {