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.
*/ */
members = _.filter(members, function (member) {
// We only want those members who have the right
// affiliation (or none, which implies the provided
// one).
return _.isUndefined(member.affiliation) ||
member.affiliation === affiliation;
});
var promises = _.map(members, function (member) {
var deferred = new $.Deferred(); var deferred = new $.Deferred();
var iq = $iq({to: this.model.get('jid'), type: "set"}) var iq = $iq({to: this.model.get('jid'), type: "set"})
.c("query", {xmlns: Strophe.NS.MUC_ADMIN}); .c("query", {xmlns: Strophe.NS.MUC_ADMIN})
.c("item", {
_.each(members, function (member) {
if (!_.isUndefined(member.affiliation) &&
member.affiliation !== affiliation) {
return;
}
iq.c("item", {
'affiliation': member.affiliation || affiliation, 'affiliation': member.affiliation || affiliation,
'jid': member.jid '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); converse.connection.sendIQ(iq, deferred.resolve, deferred.reject);
return deferred; return deferred;
}, this);
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