Explorar o código

Refactor `getJidsWithAffiliations`

Previously the Promise.all made it all-or-nothing, now it'll return
partial matches as well and it'll also log error stanzas.
JC Brand %!s(int64=6) %!d(string=hai) anos
pai
achega
b4a70c5f31
Modificáronse 3 ficheiros con 15 adicións e 37 borrados
  1. 5 15
      dist/converse.js
  2. 10 10
      src/converse-muc.js
  3. 0 12
      src/utils/muc.js

+ 5 - 15
dist/converse.js

@@ -70790,7 +70790,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
           return Promise.all(_.map(affiliations, _.partial(this.setAffiliation.bind(this), _, members)));
           return Promise.all(_.map(affiliations, _.partial(this.setAffiliation.bind(this), _, members)));
         },
         },
 
 
-        getJidsWithAffiliations(affiliations) {
+        async getJidsWithAffiliations(affiliations) {
           /* Returns a map of JIDs that have the affiliations
           /* Returns a map of JIDs that have the affiliations
            * as provided.
            * as provided.
            */
            */
@@ -70798,9 +70798,10 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
             affiliations = [affiliations];
             affiliations = [affiliations];
           }
           }
 
 
-          const promises = _.map(affiliations, _.partial(this.requestMemberList.bind(this)));
-
-          return Promise.all(promises).then(iq => u.marshallAffiliationIQs(iq), iq => u.marshallAffiliationIQs(iq));
+          const result = await Promise.all(affiliations.map(a => this.requestMemberList(a).then(iq => u.parseMemberListIQ(iq)).catch(iq => {
+            _converse.log(iq, Strophe.LogLevel.ERROR);
+          })));
+          return [].concat.apply([], result).filter(p => p);
         },
         },
 
 
         updateMemberLists(members, affiliations, deltaFunc) {
         updateMemberLists(members, affiliations, deltaFunc) {
@@ -103693,17 +103694,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
       return data;
       return data;
     });
     });
   };
   };
-
-  u.marshallAffiliationIQs = function marshallAffiliationIQs() {
-    /* Marshall a list of IQ stanzas into a map of JIDs and
-        * affiliations.
-        *
-        * Parameters:
-        *  Any amount of XMLElement objects, representing the IQ
-        *  stanzas.
-        */
-    return _.flatMap(arguments[0], u.parseMemberListIQ);
-  };
 });
 });
 
 
 /***/ })
 /***/ })

+ 10 - 10
src/converse-muc.js

@@ -730,21 +730,21 @@
                     return Promise.all(_.map(affiliations, _.partial(this.setAffiliation.bind(this), _, members)));
                     return Promise.all(_.map(affiliations, _.partial(this.setAffiliation.bind(this), _, members)));
                 },
                 },
 
 
-                getJidsWithAffiliations (affiliations) {
+                async getJidsWithAffiliations (affiliations) {
                     /* Returns a map of JIDs that have the affiliations
                     /* Returns a map of JIDs that have the affiliations
                      * as provided.
                      * as provided.
                      */
                      */
                     if (_.isString(affiliations)) {
                     if (_.isString(affiliations)) {
                         affiliations = [affiliations];
                         affiliations = [affiliations];
                     }
                     }
-                    const promises = _.map(
-                        affiliations,
-                        _.partial(this.requestMemberList.bind(this))
-                    );
-                    return Promise.all(promises).then(
-                        (iq) => u.marshallAffiliationIQs(iq),
-                        (iq) => u.marshallAffiliationIQs(iq)
-                    );
+                    const result = await Promise.all(affiliations.map(a =>
+                        this.requestMemberList(a)
+                            .then(iq => u.parseMemberListIQ(iq))
+                            .catch(iq => {
+                                _converse.log(iq, Strophe.LogLevel.ERROR);
+                            })
+                    ));
+                    return [].concat.apply([], result).filter(p => p);
                 },
                 },
 
 
                 updateMemberLists (members, affiliations, deltaFunc) {
                 updateMemberLists (members, affiliations, deltaFunc) {
@@ -766,7 +766,7 @@
                      *  to update the list.
                      *  to update the list.
                      */
                      */
                     this.getJidsWithAffiliations(affiliations)
                     this.getJidsWithAffiliations(affiliations)
-                        .then((old_members) => this.setAffiliations(deltaFunc(members, old_members)))
+                        .then(old_members => this.setAffiliations(deltaFunc(members, old_members)))
                         .then(() => this.occupants.fetchMembers())
                         .then(() => this.occupants.fetchMembers())
                         .catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
                         .catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
                 },
                 },

+ 0 - 12
src/utils/muc.js

@@ -100,16 +100,4 @@
             }
             }
         );
         );
     };
     };
-
-    u.marshallAffiliationIQs = function marshallAffiliationIQs () {
-        /* Marshall a list of IQ stanzas into a map of JIDs and
-            * affiliations.
-            *
-            * Parameters:
-            *  Any amount of XMLElement objects, representing the IQ
-            *  stanzas.
-            */
-        return _.flatMap(arguments[0], u.parseMemberListIQ);
-    }
-
 }));
 }));