فهرست منبع

Fix `/${command}` parsing bug

JC Brand 6 سال پیش
والد
کامیت
4f67f352f5
2فایلهای تغییر یافته به همراه36 افزوده شده و 7 حذف شده
  1. 23 3
      spec/muc.js
  2. 13 4
      src/converse-muc-views.js

+ 23 - 3
spec/muc.js

@@ -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'], {},

+ 13 - 4
src/converse-muc-views.js

@@ -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;
                 }