瀏覽代碼

Test the /voice command and fix a bug

JC Brand 7 年之前
父節點
當前提交
dc16930464
共有 2 個文件被更改,包括 61 次插入6 次删除
  1. 38 1
      spec/chatroom.js
  2. 23 5
      src/converse-muc.js

+ 38 - 1
spec/chatroom.js

@@ -1977,7 +1977,7 @@
                 });
                 });
             }));
             }));
 
 
-            it("/mute to mute a user",
+            it("/mute and /voice to mute and unmute a user",
                 mock.initConverseWithPromises(
                 mock.initConverseWithPromises(
                     null, ['rosterGroupsFetched'], {},
                     null, ['rosterGroupsFetched'], {},
                     function (done, _converse) {
                     function (done, _converse) {
@@ -2069,6 +2069,43 @@
                     _converse.connection._dataRecv(test_utils.createRequest(presence));
                     _converse.connection._dataRecv(test_utils.createRequest(presence));
                     info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
                     info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
                     expect(info_msgs.pop().textContent).toBe("annoyingGuy has been muted.");
                     expect(info_msgs.pop().textContent).toBe("annoyingGuy has been muted.");
+
+                    view.onMessageSubmitted('/voice annoyingGuy Now you can talk again');
+                    expect(view.validateRoleChangeCommand.calls.count()).toBe(3);
+                    expect(view.showStatusNotification.calls.count()).toBe(2);
+                    expect(view.modifyRole).toHaveBeenCalled();
+                    expect(sent_IQ.toLocaleString()).toBe(
+                        "<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
+                            "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
+                                "<item nick='annoyingGuy' role='participant'>"+
+                                    "<reason>Now you can talk again</reason>"+
+                                "</item>"+
+                            "</query>"+
+                        "</iq>");
+
+                   /* <presence
+                    *     from='coven@chat.shakespeare.lit/thirdwitch'
+                    *     to='crone1@shakespeare.lit/desktop'>
+                    * <x xmlns='http://jabber.org/protocol/muc#user'>
+                    *     <item affiliation='member'
+                    *         jid='hag66@shakespeare.lit/pda'
+                    *         role='visitor'/>
+                    * </x>
+                    * </presence>
+                    */
+                    presence = $pres({
+                            'from': 'lounge@localhost/annoyingGuy',
+                            'to': 'dummy@localhost/desktop'
+                        })
+                        .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
+                            .c('item', {
+                                'jid': 'annoyingguy@localhost',
+                                'affiliation': 'member',
+                                'role': 'participant'
+                            });
+                    _converse.connection._dataRecv(test_utils.createRequest(presence));
+                    info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
+                    expect(info_msgs.pop().textContent).toBe("annoyingGuy has been given a voice again.");
                     done();
                     done();
                 });
                 });
             }));
             }));

+ 23 - 5
src/converse-muc.js

@@ -510,10 +510,28 @@
                     return this;
                     return this;
                 },
                 },
 
 
-                informOfOccupantsRoleChange (occupant) {
+                informOfOccupantsRoleChange (occupant, changed) {
+                    const previous_role = occupant._previousAttributes.role;
+                    if (previous_role === 'moderator') {
+                        this.showStatusNotification(
+                            __("%1$s is no longer a moderator.", occupant.get('nick')),
+                            false, true)
+                    }
+                    if (previous_role === 'visitor') {
+                        this.showStatusNotification(
+                            __("%1$s has been given a voice again.", occupant.get('nick')),
+                            false, true)
+                    }
+
                     if (occupant.get('role') === 'visitor') {
                     if (occupant.get('role') === 'visitor') {
                         this.showStatusNotification(
                         this.showStatusNotification(
-                            __("%1$s has been muted.", occupant.get('nick')), false, true)
+                            __("%1$s has been muted.", occupant.get('nick')),
+                            false, true)
+                    }
+                    if (occupant.get('role') === 'moderator') {
+                        this.showStatusNotification(
+                            __("%1$s is now a moderator.", occupant.get('nick')),
+                            false, true)
                     }
                     }
                 },
                 },
 
 
@@ -1023,7 +1041,7 @@
                         case 'deop':
                         case 'deop':
                             if (!this.validateRoleChangeCommand(command, args)) { break; }
                             if (!this.validateRoleChangeCommand(command, args)) { break; }
                             this.modifyRole(
                             this.modifyRole(
-                                    this.model.get('jid'), args[0], 'occupant', args[1],
+                                    this.model.get('jid'), args[0], 'participant', args[1],
                                     undefined, this.onCommandError.bind(this));
                                     undefined, this.onCommandError.bind(this));
                             break;
                             break;
                         case 'help':
                         case 'help':
@@ -1031,7 +1049,7 @@
                                 `<strong>/admin</strong>: ${__("Change user's affiliation to admin")}`,
                                 `<strong>/admin</strong>: ${__("Change user's affiliation to admin")}`,
                                 `<strong>/ban</strong>: ${__('Ban user from room')}`,
                                 `<strong>/ban</strong>: ${__('Ban user from room')}`,
                                 `<strong>/clear</strong>: ${__('Remove messages')}`,
                                 `<strong>/clear</strong>: ${__('Remove messages')}`,
-                                `<strong>/deop</strong>: ${__('Change user role to occupant')}`,
+                                `<strong>/deop</strong>: ${__('Change user role to participant')}`,
                                 `<strong>/help</strong>: ${__('Show this menu')}`,
                                 `<strong>/help</strong>: ${__('Show this menu')}`,
                                 `<strong>/kick</strong>: ${__('Kick user from room')}`,
                                 `<strong>/kick</strong>: ${__('Kick user from room')}`,
                                 `<strong>/me</strong>: ${__('Write in 3rd person')}`,
                                 `<strong>/me</strong>: ${__('Write in 3rd person')}`,
@@ -1105,7 +1123,7 @@
                         case 'voice':
                         case 'voice':
                             if (!this.validateRoleChangeCommand(command, args)) { break; }
                             if (!this.validateRoleChangeCommand(command, args)) { break; }
                             this.modifyRole(
                             this.modifyRole(
-                                    this.model.get('jid'), args[0], 'occupant', args[1],
+                                    this.model.get('jid'), args[0], 'participant', args[1],
                                     undefined, this.onCommandError.bind(this));
                                     undefined, this.onCommandError.bind(this));
                             break;
                             break;
                         default:
                         default: