Commit 1aceaa9c authored by JC Brand's avatar JC Brand

Avoid creating unnecesary promises

by returning existing promises and by using _converse.api.sendIQ
parent daf470e3
...@@ -471,13 +471,11 @@ ...@@ -471,13 +471,11 @@
* A promise which resolves once the list has been * A promise which resolves once the list has been
* retrieved. * retrieved.
*/ */
return new Promise((resolve, reject) => { affiliation = affiliation || 'member';
affiliation = affiliation || 'member'; const iq = $iq({to: this.get('jid'), type: "get"})
const iq = $iq({to: this.get('jid'), type: "get"}) .c("query", {xmlns: Strophe.NS.MUC_ADMIN})
.c("query", {xmlns: Strophe.NS.MUC_ADMIN}) .c("item", {'affiliation': affiliation});
.c("item", {'affiliation': affiliation}); return _converse.api.sendIQ(iq);
_converse.connection.sendIQ(iq, resolve, reject);
});
}, },
setAffiliation (affiliation, members) { setAffiliation (affiliation, members) {
...@@ -678,16 +676,14 @@ ...@@ -678,16 +676,14 @@
if (_.isString(affiliations)) { if (_.isString(affiliations)) {
affiliations = [affiliations]; affiliations = [affiliations];
} }
return new Promise((resolve, reject) => { const promises = _.map(
const promises = _.map( affiliations,
affiliations, _.partial(this.requestMemberList.bind(this))
_.partial(this.requestMemberList.bind(this)) );
); return Promise.all(promises).then(
Promise.all(promises).then( (iq) => u.marshallAffiliationIQs(iq),
_.flow(u.marshallAffiliationIQs, resolve), (iq) => u.marshallAffiliationIQs(iq)
_.flow(u.marshallAffiliationIQs, resolve) );
);
});
}, },
updateMemberLists (members, affiliations, deltaFunc) { updateMemberLists (members, affiliations, deltaFunc) {
......
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