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.
This commit is contained in:
parent
93c956ba4b
commit
b4a70c5f31
20
dist/converse.js
vendored
20
dist/converse.js
vendored
@ -70790,7 +70790,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
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
|
||||
* as provided.
|
||||
*/
|
||||
@ -70798,9 +70798,10 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
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) {
|
||||
@ -103693,17 +103694,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
||||
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 @@
|
||||
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
|
||||
* as provided.
|
||||
*/
|
||||
if (_.isString(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) {
|
||||
@ -766,7 +766,7 @@
|
||||
* to update the list.
|
||||
*/
|
||||
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())
|
||||
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
|
||||
},
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user