فهرست منبع

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

JC Brand 8 سال پیش
والد
کامیت
54371f0e7d
2فایلهای تغییر یافته به همراه33 افزوده شده و 38 حذف شده
  1. 3 3
      spec/chatroom.js
  2. 30 35
      src/converse-muc.js

+ 3 - 3
spec/chatroom.js

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

+ 30 - 35
src/converse-muc.js

@@ -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(