Prechádzať zdrojové kódy

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.
JC Brand 6 rokov pred
rodič
commit
d426d79702
3 zmenil súbory, kde vykonal 44 pridanie a 10 odobranie
  1. 8 2
      CHANGES.md
  2. 29 1
      src/converse-disco.js
  3. 7 7
      src/converse-muc.js

+ 8 - 2
CHANGES.md

@@ -1,5 +1,10 @@
 # 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)
 
 - 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
 - #1220 Converse not working in Edge
 - #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)
 
@@ -62,7 +68,7 @@
 - New API method `_converse.api.vcard.update`.
 - The `contactStatusChanged` event has been renamed to `contactPresenceChanged`
   and a event `presenceChanged` is now also triggered on the contact.
-- `_converse.api.chats.open` and `_converse.api.rooms.open` now returns a 
+- `_converse.api.chats.open` and `_converse.api.rooms.open` now returns a
   `Presence` which resolves with the `Backbone.Model` representing the chat
   object.
 
@@ -73,7 +79,7 @@
 - Fontawesome 5 is used for icons.
 - User Avatars are now shown in chat messages.
 
-## Configuration changes 
+## Configuration changes
 
 - Removed the `storage` configuration setting, use [trusted](https://conversejs.org/docs/html/configuration.html#trusted) instead.
 - Removed the `use_vcards` configuration setting, instead VCards are always used.

+ 29 - 1
src/converse-disco.js

@@ -137,7 +137,7 @@
 
                 queryInfo () {
                     _converse.api.disco.info(this.get('jid'), null)
-                        .then((stanza) => this.onInfo(stanza))
+                        .then(stanza => this.onInfo(stanza))
                         .catch(iq => {
                             this.waitUntilFeaturesDiscovered.resolve(this);
                             _converse.log(iq, Strophe.LogLevel.ERROR);
@@ -576,11 +576,39 @@
                         }).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
                      *
                      * @method _converse.api.disco.getFeatures
                      * @param {string} jid The JID of the entity whose features are returned.
+                     * @returns {promise} A promise which resolves with the returned features
                      * @example
                      * const features = await _converse.api.disco.getFeatures('room@conference.example.org');
                      */

+ 7 - 7
src/converse-muc.js

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