|
@@ -586,14 +586,52 @@
|
|
|
return delta;
|
|
|
},
|
|
|
|
|
|
+ setAffiliation: function (affiliation, members) {
|
|
|
+ /* Send an IQ stanzas to the server to modify one particular
|
|
|
+ * affiliation for certain members
|
|
|
+ *
|
|
|
+ * See: http://xmpp.org/extensions/xep-0045.html#modifymember
|
|
|
+ *
|
|
|
+ * Parameters:
|
|
|
+ * (Object) members: A map of jids, affiliations and
|
|
|
+ * optionally reasons. Only those entries with the
|
|
|
+ * same affiliation as being currently set will be
|
|
|
+ * considered.
|
|
|
+ *
|
|
|
+ * Returns:
|
|
|
+ * A promise which resolves and fails depending on the
|
|
|
+ * XMPP server response.
|
|
|
+ */
|
|
|
+ var deferred = new $.Deferred();
|
|
|
+ var iq = $iq({to: this.model.get('jid'), type: "set"})
|
|
|
+ .c("query", {xmlns: Strophe.NS.MUC_ADMIN});
|
|
|
+
|
|
|
+ _.each(members, function (member) {
|
|
|
+ if (!_.isUndefined(member.affiliation) &&
|
|
|
+ member.affiliation !== affiliation) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ iq.c("item", {
|
|
|
+ 'affiliation': member.affiliation || affiliation,
|
|
|
+ 'jid': member.jid
|
|
|
+ });
|
|
|
+ if (!_.isUndefined(member.reason)) {
|
|
|
+ iq.c("reason", member.reason).up();
|
|
|
+ }
|
|
|
+ iq.up();
|
|
|
+ });
|
|
|
+ converse.connection.sendIQ(iq, deferred.resolve, deferred.reject);
|
|
|
+ return deferred;
|
|
|
+ },
|
|
|
+
|
|
|
setAffiliations: function (members, onSuccess, onError) {
|
|
|
- /* Send an IQ stanza to the server to modify the
|
|
|
+ /* Send IQ stanzas to the server to modify the
|
|
|
* affiliations in this room.
|
|
|
*
|
|
|
* See: http://xmpp.org/extensions/xep-0045.html#modifymember
|
|
|
*
|
|
|
* Parameters:
|
|
|
- * (Object) members: A map of jids and affiliations
|
|
|
+ * (Object) members: A map of jids, affiliations and optionally reasons
|
|
|
* (Function) onSuccess: callback for a succesful response
|
|
|
* (Function) onError: callback for an error response
|
|
|
*/
|
|
@@ -602,26 +640,9 @@
|
|
|
onSuccess(null);
|
|
|
return;
|
|
|
}
|
|
|
- var room_jid = this.model.get('jid');
|
|
|
var affiliations = _.uniq(_.pluck(members, 'affiliation'));
|
|
|
- _.each(affiliations, function (affiliation) {
|
|
|
- var iq = $iq({to: room_jid, type: "set"})
|
|
|
- .c("query", {xmlns: Strophe.NS.MUC_ADMIN});
|
|
|
- _.each(members, function (member) {
|
|
|
- if (member.affiliation !== affiliation) {
|
|
|
- return;
|
|
|
- }
|
|
|
- iq.c("item", {
|
|
|
- 'affiliation': member.affiliation,
|
|
|
- 'jid': member.jid
|
|
|
- });
|
|
|
- if (!_.isUndefined(member.reason)) {
|
|
|
- iq.c("reason", member.reason).up();
|
|
|
- }
|
|
|
- iq.up();
|
|
|
- });
|
|
|
- converse.connection.sendIQ(iq, onSuccess, onError);
|
|
|
- });
|
|
|
+ var promises = _.map(affiliations, _.partial(this.setAffiliation, _, members), this);
|
|
|
+ $.when.apply($, promises).done(onSuccess).fail(onError);
|
|
|
},
|
|
|
|
|
|
marshallAffiliationIQs: function () {
|
|
@@ -836,21 +857,17 @@
|
|
|
switch (match[1]) {
|
|
|
case 'admin':
|
|
|
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
|
|
|
- this.setAffiliations(
|
|
|
- [{'jid': args[0],
|
|
|
- 'affiliation': 'admin',
|
|
|
- 'reason': args[1]
|
|
|
- }], undefined, this.onCommandError.bind(this)
|
|
|
- );
|
|
|
+ this.setAffiliation('admin',
|
|
|
+ [{ 'jid': args[0],
|
|
|
+ 'reason': args[1]
|
|
|
+ }]).fail(this.onCommandError.bind(this));
|
|
|
break;
|
|
|
case 'ban':
|
|
|
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
|
|
|
- this.setAffiliations(
|
|
|
- [{'jid': args[0],
|
|
|
- 'affiliation': 'outcast',
|
|
|
- 'reason': args[1]
|
|
|
- }], undefined, this.onCommandError.bind(this)
|
|
|
- );
|
|
|
+ this.setAffiliation('outcast',
|
|
|
+ [{ 'jid': args[0],
|
|
|
+ 'reason': args[1]
|
|
|
+ }]).fail(this.onCommandError.bind(this));
|
|
|
break;
|
|
|
case 'clear':
|
|
|
this.clearChatRoomMessages();
|
|
@@ -894,12 +911,10 @@
|
|
|
break;
|
|
|
case 'member':
|
|
|
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
|
|
|
- this.setAffiliations(
|
|
|
- [{'jid': args[0],
|
|
|
- 'affiliation': 'member',
|
|
|
- 'reason': args[1]
|
|
|
- }], undefined, this.onCommandError.bind(this)
|
|
|
- );
|
|
|
+ this.setAffiliation('member',
|
|
|
+ [{ 'jid': args[0],
|
|
|
+ 'reason': args[1]
|
|
|
+ }]).fail(this.onCommandError.bind(this));
|
|
|
break;
|
|
|
case 'nick':
|
|
|
converse.connection.send($pres({
|
|
@@ -910,12 +925,10 @@
|
|
|
break;
|
|
|
case 'owner':
|
|
|
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
|
|
|
- this.setAffiliations(
|
|
|
- [{'jid': args[0],
|
|
|
- 'affiliation': 'owner',
|
|
|
- 'reason': args[1]
|
|
|
- }], undefined, this.onCommandError.bind(this)
|
|
|
- );
|
|
|
+ this.setAffiliation('owner',
|
|
|
+ [{ 'jid': args[0],
|
|
|
+ 'reason': args[1]
|
|
|
+ }]).fail(this.onCommandError.bind(this));
|
|
|
break;
|
|
|
case 'op':
|
|
|
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
|
|
@@ -925,12 +938,10 @@
|
|
|
break;
|
|
|
case 'revoke':
|
|
|
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
|
|
|
- this.setAffiliations(
|
|
|
- [{'jid': args[0],
|
|
|
- 'affiliation': 'none',
|
|
|
- 'reason': args[1]
|
|
|
- }], undefined, this.onCommandError.bind(this)
|
|
|
- );
|
|
|
+ this.setAffiliation('none',
|
|
|
+ [{ 'jid': args[0],
|
|
|
+ 'reason': args[1]
|
|
|
+ }]).fail(this.onCommandError.bind(this));
|
|
|
break;
|
|
|
case 'topic':
|
|
|
converse.connection.send(
|