Commit b516ae51 authored by JC Brand's avatar JC Brand

Move code into separate function.

parent 802c9d1f
...@@ -608,6 +608,17 @@ ...@@ -608,6 +608,17 @@
return converse.connection.sendIQ(iq, onSuccess, onError); return converse.connection.sendIQ(iq, onSuccess, onError);
}, },
marshallAffiliationIQs: function (iqs) {
/* Marshall a list of IQ stanzas into a map of JIDs and
* affiliations.
*/
var affiliations = _.flatten(_.map(iqs, this.parseMemberListIQ));
return _.reduce(affiliations, function (memo, member) {
memo[member.jid] = member.affiliation;
return memo;
}, {});
},
getJidsWithAffiliations: function (affiliations) { getJidsWithAffiliations: function (affiliations) {
/* Returns a map of JIDs that have the affiliations /* Returns a map of JIDs that have the affiliations
* as provided. * as provided.
...@@ -621,14 +632,9 @@ ...@@ -621,14 +632,9 @@
_.each(affiliations, function (affiliation) { _.each(affiliations, function (affiliation) {
promises.push(that.requestMemberList(affiliation)); promises.push(that.requestMemberList(affiliation));
}); });
$.when.apply($, promises).always(function () { $.when.apply($, promises).always(
var old_members = _.flatten(_.map(arguments, that.parseMemberListIQ)); _.compose(deferred.resolve, this.marshallAffiliationIQs.bind(this))
old_members = _.reduce(old_members, function (memo, member) { );
memo[member.jid] = member.affiliation;
return memo;
}, {});
deferred.resolve(old_members);
});
return deferred.promise(); return deferred.promise();
}, },
......
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