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