Commit 4f67f352 authored by JC Brand's avatar JC Brand

Fix `/${command}` parsing bug

parent 6a419cc1
......@@ -3180,8 +3180,10 @@
keyCode: 13
});
expect(view.validateRoleOrAffiliationChangeArgs).toHaveBeenCalled();
expect(view.showErrorMessage).toHaveBeenCalledWith(
expect(view.showErrorMessage).toHaveBeenCalled();
expect(view.el.querySelector('.message:first-child').textContent).toBe(
"Error: the \"ban\" command takes two arguments, the user's nickname and optionally a reason.");
expect(view.model.setAffiliation).not.toHaveBeenCalled();
// Call now with the correct amount of arguments.
// XXX: Calling onFormSubmitted directly, trying
......@@ -3215,12 +3217,30 @@
'role': 'participant'
});
_converse.connection._dataRecv(test_utils.createRequest(presence));
expect(
view.el.querySelectorAll('.chat-info')[3].textContent).toBe(
expect(view.el.querySelectorAll('.chat-info')[3].textContent).toBe(
"annoyingGuy has been banned from this groupchat");
presence = $pres({
'from': 'lounge@montague.lit/joe2',
'id':'27C55F89-1C6A-459A-9EB5-77690145D624',
'to': 'romeo@montague.lit/desktop'
})
.c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
.c('item', {
'jid': 'joe2@montague.lit',
'affiliation': 'member',
'role': 'participant'
});
_converse.connection._dataRecv(test_utils.createRequest(presence));
textarea.value = '/ban joe22';
view.onFormSubmitted(new Event('submit'));
expect(view.el.querySelector('.message:first-child').textContent).toBe(
"Error: couldn't find a groupchat participant based on your arguments");
done();
}));
it("takes a /kick command to kick a user",
mock.initConverse(
null, ['rosterGroupsFetched'], {},
......
......@@ -854,9 +854,18 @@ converse.plugins.add('converse-muc-views', {
const [text, references] = this.model.parseTextForReferences(args);
if (!references.length) {
this.showErrorMessage(__("Error: couldn't find a groupchat participant based on your arguments"));
return false;
return;
}
if (references.length > 1) {
this.showErrorMessage(__("Error: found multiple groupchat participant based on your arguments"));
return;
}
const nick_or_jid = references.pop().value;
if (!args.split(nick_or_jid, 2)[1].startsWith(' ')) {
this.showErrorMessage(__("Error: couldn't find a groupchat participant based on your arguments"));
return;
}
return references.pop();
return nick_or_jid;
},
setAffiliation (command, args, required_affiliations) {
......@@ -870,7 +879,7 @@ converse.plugins.add('converse-muc-views', {
if (!this.validateRoleOrAffiliationChangeArgs(command, args)) {
return false;
}
const nick_or_jid = _.get(this.getNickOrJIDFromCommandArgs(args), 'value', null);
const nick_or_jid = this.getNickOrJIDFromCommandArgs(args);
if (!nick_or_jid) {
return false;
}
......@@ -907,7 +916,7 @@ converse.plugins.add('converse-muc-views', {
if (!this.validateRoleOrAffiliationChangeArgs(command, args)) {
return false;
}
const nick_or_jid = _.get(this.getNickOrJIDFromCommandArgs(args), 'value', null);
const nick_or_jid = this.getNickOrJIDFromCommandArgs(args);
if (!nick_or_jid) {
return false;
}
......
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