Explorar o código

Use switch statement instead of ifs

JC Brand %!s(int64=12) %!d(string=hai) anos
pai
achega
6a49090a21
Modificáronse 1 ficheiros con 18 adicións e 18 borrados
  1. 18 18
      converse.js

+ 18 - 18
converse.js

@@ -832,26 +832,27 @@
         },
 
         sendGroupMessage: function (body) {
-            var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/);
-            if (match) {
-                if (match[1] === "msg") {
+            var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false];
+            switch (match[1]) {
+                case 'msg':
                     // TODO: Private messages
-                } else if (match[1] === "topic") {
+                    break;
+                case 'topic':
                     xmppchat.connection.muc.setTopic(this.model.get('jid'), match[2]);
-
-                } else if (match[1] === "kick") {
+                    break;
+                case 'kick':
                     xmppchat.connection.muc.kick(this.model.get('jid'), match[2]);
-
-                } else if (match[1] === "ban") {
+                    break;
+                case 'ban':
                     xmppchat.connection.muc.ban(this.model.get('jid'), match[2]);
-
-                } else if (match[1] === "op") {
+                    break;
+                case 'op':
                     xmppchat.connection.muc.op(this.model.get('jid'), match[2]);
-
-                } else if (match[1] === "deop") {
+                    break;
+                case 'deop':
                     xmppchat.connection.muc.deop(this.model.get('jid'), match[2]);
-
-                } else if (match[1] === "help") {
+                    break;
+                case 'help':
                     $chat_content = $(this.el).find('.chat-content');
                     $chat_content.append($('<div class="chat-help"><strong>/help</strong>: Show this menu</div>'));
                     $chat_content.append($('<div class="chat-help"><strong>/topic</strong>: Set chatroom topic</div>'));
@@ -862,11 +863,10 @@
                     $chat_content.append($('<div class="chat-help"><strong>/deop $user</strong>: Remove messages</div>'));
                     */
                     this.scrolldown();
-                } else {
+                    break;
+                default:
                     this.last_msgid = xmppchat.connection.muc.groupchat(this.model.get('jid'), body);
-                }
-            } else {
-                this.last_msgid = xmppchat.connection.muc.groupchat(this.model.get('jid'), body);
+                break;
             }
         },