Commit 0bcf6138 authored by JC Brand's avatar JC Brand

Work around a Prosody bug.

Prosody doesn't handle it if we set the affiliation for multiple JIDs in one
stanza, so we need to send a stanza for each JID.

Refs https://prosody.im/issues/issue/795
parent 37df4ad1
...@@ -587,11 +587,16 @@ ...@@ -587,11 +587,16 @@
}, },
setAffiliation: function (affiliation, members) { setAffiliation: function (affiliation, members) {
/* Send an IQ stanzas to the server to modify one particular /* Send IQ stanzas to the server to set an affiliation for
* affiliation for certain members * the provided JIDs.
* *
* See: http://xmpp.org/extensions/xep-0045.html#modifymember * See: http://xmpp.org/extensions/xep-0045.html#modifymember
* *
* XXX: Prosody doesn't accept multiple JIDs' affiliations
* being set in one IQ stanza, so as a workaround we send
* a separate stanza for each JID.
* Related ticket: https://prosody.im/issues/issue/795
*
* Parameters: * Parameters:
* (Object) members: A map of jids, affiliations and * (Object) members: A map of jids, affiliations and
* optionally reasons. Only those entries with the * optionally reasons. Only those entries with the
...@@ -602,26 +607,28 @@ ...@@ -602,26 +607,28 @@
* A promise which resolves and fails depending on the * A promise which resolves and fails depending on the
* XMPP server response. * XMPP server response.
*/ */
var deferred = new $.Deferred(); members = _.filter(members, function (member) {
var iq = $iq({to: this.model.get('jid'), type: "set"}) // We only want those members who have the right
.c("query", {xmlns: Strophe.NS.MUC_ADMIN}); // affiliation (or none, which implies the provided
// one).
_.each(members, function (member) { return _.isUndefined(member.affiliation) ||
if (!_.isUndefined(member.affiliation) && member.affiliation === affiliation;
member.affiliation !== affiliation) { });
return; var promises = _.map(members, function (member) {
} var deferred = new $.Deferred();
iq.c("item", { var iq = $iq({to: this.model.get('jid'), type: "set"})
'affiliation': member.affiliation || affiliation, .c("query", {xmlns: Strophe.NS.MUC_ADMIN})
'jid': member.jid .c("item", {
}); 'affiliation': member.affiliation || affiliation,
'jid': member.jid
});
if (!_.isUndefined(member.reason)) { if (!_.isUndefined(member.reason)) {
iq.c("reason", member.reason).up(); iq.c("reason", member.reason);
} }
iq.up(); converse.connection.sendIQ(iq, deferred.resolve, deferred.reject);
}); return deferred;
converse.connection.sendIQ(iq, deferred.resolve, deferred.reject); }, this);
return deferred; return $.when.apply($, promises);
}, },
setAffiliations: function (members, onSuccess, onError) { setAffiliations: function (members, onSuccess, onError) {
......
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