Commit 54371f0e authored by JC Brand's avatar JC Brand

Remove `setAffiliation` and use the more general purpose `setAffiliations`

parent 77d3e64f
......@@ -1167,7 +1167,7 @@
test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
var view = converse.chatboxviews.get('lounge@localhost');
spyOn(view, 'onMessageSubmitted').andCallThrough();
spyOn(view, 'setAffiliation').andCallThrough();
spyOn(view, 'setAffiliations').andCallThrough();
spyOn(view, 'showStatusNotification').andCallThrough();
spyOn(view, 'validateRoleChangeCommand').andCallThrough();
view.$el.find('.chat-textarea').text('/ban');
......@@ -1178,7 +1178,7 @@
"Error: the \"ban\" command takes two arguments, the user's nickname and optionally a reason.",
true
);
expect(view.setAffiliation).not.toHaveBeenCalled();
expect(view.setAffiliations).not.toHaveBeenCalled();
// Call now with the correct amount of arguments.
// XXX: Calling onMessageSubmitted directly, trying
......@@ -1187,7 +1187,7 @@
view.onMessageSubmitted('/ban jid This is the reason');
expect(view.validateRoleChangeCommand.callCount).toBe(2);
expect(view.showStatusNotification.callCount).toBe(1);
expect(view.setAffiliation).toHaveBeenCalled();
expect(view.setAffiliations).toHaveBeenCalled();
}));
});
......
......@@ -780,13 +780,6 @@
});
},
setAffiliation: function(room, jid, affiliation, reason, onSuccess, onError) {
var item = $build("item", {jid: jid, affiliation: affiliation});
var iq = $iq({to: room, type: "set"}).c("query", {xmlns: Strophe.NS.MUC_ADMIN}).cnode(item.node);
if (reason !== null) { iq.c("reason", reason); }
return converse.connection.sendIQ(iq.tree(), onSuccess, onError);
},
modifyRole: function(room, nick, role, reason, onSuccess, onError) {
var item = $build("item", {nick: nick, role: role});
var iq = $iq({to: room, type: "set"}).c("query", {xmlns: Strophe.NS.MUC_ADMIN}).cnode(item.node);
......@@ -794,19 +787,6 @@
return converse.connection.sendIQ(iq.tree(), onSuccess, onError);
},
member: function(room, jid, reason, handler_cb, error_cb) {
return this.setAffiliation(room, jid, 'member', reason, handler_cb, error_cb);
},
revoke: function(room, jid, reason, handler_cb, error_cb) {
return this.setAffiliation(room, jid, 'none', reason, handler_cb, error_cb);
},
owner: function(room, jid, reason, handler_cb, error_cb) {
return this.setAffiliation(room, jid, 'owner', reason, handler_cb, error_cb);
},
admin: function(room, jid, reason, handler_cb, error_cb) {
return this.setAffiliation(room, jid, 'admin', reason, handler_cb, error_cb);
},
validateRoleChangeCommand: function (command, args) {
/* Check that a command to change a chat room user's role or
* affiliation has anough arguments.
......@@ -849,15 +829,21 @@
switch (match[1]) {
case 'admin':
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
this.setAffiliation(
this.model.get('jid'), args[0], 'admin', args[1],
undefined, this.onCommandError.bind(this));
this.setAffiliations(
[{'jid': args[0],
'affiliation': 'admin',
'reason': args[1]
}], undefined, this.onCommandError.bind(this)
);
break;
case 'ban':
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
this.setAffiliation(
this.model.get('jid'), args[0], 'outcast', args[1],
undefined, this.onCommandError.bind(this));
this.setAffiliations(
[{'jid': args[0],
'affiliation': 'outcast',
'reason': args[1]
}], undefined, this.onCommandError.bind(this)
);
break;
case 'clear':
this.clearChatRoomMessages();
......@@ -901,9 +887,12 @@
break;
case 'member':
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
this.setAffiliation(
this.model.get('jid'), args[0], 'member', args[1],
undefined, this.onCommandError.bind(this));
this.setAffiliations(
[{'jid': args[0],
'affiliation': 'member',
'reason': args[1]
}], undefined, this.onCommandError.bind(this)
);
break;
case 'nick':
converse.connection.send($pres({
......@@ -914,9 +903,12 @@
break;
case 'owner':
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
this.setAffiliation(
this.model.get('jid'), args[0], 'owner', args[1],
undefined, this.onCommandError.bind(this));
this.setAffiliations(
[{'jid': args[0],
'affiliation': 'owner',
'reason': args[1]
}], undefined, this.onCommandError.bind(this)
);
break;
case 'op':
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
......@@ -926,9 +918,12 @@
break;
case 'revoke':
if (!this.validateRoleChangeCommand(match[1], args)) { break; }
this.setAffiliation(
this.model.get('jid'), args[0], 'none', args[1],
undefined, this.onCommandError.bind(this));
this.setAffiliations(
[{'jid': args[0],
'affiliation': 'none',
'reason': args[1]
}], undefined, this.onCommandError.bind(this)
);
break;
case 'topic':
converse.connection.send(
......
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