Commit b4a70c5f authored by JC Brand's avatar JC Brand

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.
parent 93c956ba
...@@ -70790,7 +70790,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } ...@@ -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; } ...@@ -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))); 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 Promise.all(promises).then(iq => u.marshallAffiliationIQs(iq), iq => u.marshallAffiliationIQs(iq)); })));
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_ ...@@ -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);
};
}); });
/***/ }) /***/ })
...@@ -730,21 +730,21 @@ ...@@ -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( const result = await Promise.all(affiliations.map(a =>
affiliations, this.requestMemberList(a)
_.partial(this.requestMemberList.bind(this)) .then(iq => u.parseMemberListIQ(iq))
); .catch(iq => {
return Promise.all(promises).then( _converse.log(iq, Strophe.LogLevel.ERROR);
(iq) => u.marshallAffiliationIQs(iq), })
(iq) => u.marshallAffiliationIQs(iq) ));
); return [].concat.apply([], result).filter(p => p);
}, },
updateMemberLists (members, affiliations, deltaFunc) { updateMemberLists (members, affiliations, deltaFunc) {
...@@ -766,7 +766,7 @@ ...@@ -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));
}, },
......
...@@ -100,16 +100,4 @@ ...@@ -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);
}
})); }));
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