Client side /ignore + /unignore commands
authorDarren <darren@Darrens-MacBook-Pro.local>
Mon, 11 Mar 2013 16:26:52 +0000 (16:26 +0000)
committerDarren <darren@Darrens-MacBook-Pro.local>
Mon, 11 Mar 2013 16:26:52 +0000 (16:26 +0000)
client/assets/dev/model_application.js
client/assets/dev/model_gateway.js

index 2c99b16d412d6c652aa639cecd0163be9f3e308a..be5fbd0d5786908fe32f182bb3a6823917a242e4 100644 (file)
@@ -424,6 +424,11 @@ _kiwi.model.Application = function () {
                 var panel,\r
                     is_pm = (event.channel == _kiwi.gateway.get('nick'));\r
 \r
+                // An ignored user? don't do anything with it\r
+                if (gw.isNickIgnored(event.nick)) {\r
+                    return;\r
+                }\r
+\r
                 if (is_pm) {\r
                     // If a panel isn't found for this PM, create one\r
                     panel = that.panels.getByName(event.nick);\r
@@ -440,12 +445,17 @@ _kiwi.model.Application = function () {
                         panel = that.panels.server;\r
                     }\r
                 }\r
-                \r
+\r
                 panel.addMsg(event.nick, event.msg);\r
             });\r
 \r
 \r
             gw.on('onctcp_request', function (event) {\r
+                // An ignored user? don't do anything with it\r
+                if (gw.isNickIgnored(event.nick)) {\r
+                    return;\r
+                }\r
+\r
                 // Reply to a TIME ctcp\r
                 if (event.msg.toUpperCase() === 'TIME') {\r
                     gw.ctcp(false, event.type, event.nick, (new Date()).toString());\r
@@ -454,6 +464,11 @@ _kiwi.model.Application = function () {
 \r
 \r
             gw.on('onctcp_response', function (event) {\r
+                // An ignored user? don't do anything with it\r
+                if (gw.isNickIgnored(event.nick)) {\r
+                    return;\r
+                }\r
+                \r
                 that.panels.server.addMsg('[' + event.nick + ']', 'CTCP ' + event.msg);\r
             });\r
 \r
@@ -461,6 +476,11 @@ _kiwi.model.Application = function () {
             gw.on('onnotice', function (event) {\r
                 var panel;\r
 \r
+                // An ignored user? don't do anything with it\r
+                if (event.nick && gw.isNickIgnored(event.nick)) {\r
+                    return;\r
+                }\r
+\r
                 // Find a panel for the destination(channel) or who its from\r
                 panel = that.panels.getByName(event.target) || that.panels.getByName(event.nick);\r
                 if (!panel) {\r
@@ -475,6 +495,11 @@ _kiwi.model.Application = function () {
                 var panel,\r
                     is_pm = (event.channel == _kiwi.gateway.get('nick'));\r
 \r
+                // An ignored user? don't do anything with it\r
+                if (gw.isNickIgnored(event.nick)) {\r
+                    return;\r
+                }\r
+\r
                 if (is_pm) {\r
                     // If a panel isn't found for this PM, create one\r
                     panel = that.panels.getByName(event.nick);\r
@@ -906,6 +931,48 @@ _kiwi.model.Application = function () {
                 controlbox.preprocessor.aliases[name] = rule;\r
             });\r
 \r
+            \r
+            controlbox.on('command:ignore', function (ev) {\r
+                var list = _kiwi.gateway.get('ignore_list');\r
+\r
+                // No parameters passed so list them\r
+                if (!ev.params[0]) {\r
+                    if (list.length > 0) {\r
+                        _kiwi.app.panels.active.addMsg(' ', 'Ignored nicks:');\r
+                        $.each(list, function (idx, ignored_pattern) {\r
+                            _kiwi.app.panels.active.addMsg(' ', ignored_pattern);\r
+                        });\r
+                    } else {\r
+                        _kiwi.app.panels.active.addMsg(' ', 'Not ignoring anybody');\r
+                    }\r
+                    return;\r
+                }\r
+\r
+                // We have a parameter, so add it\r
+                list.push(ev.params[0]);\r
+                _kiwi.gateway.set('ignore_list', list);\r
+                _kiwi.app.panels.active.addMsg(' ', 'Ignoring ' + ev.params[0]);\r
+            });\r
+\r
+\r
+            controlbox.on('command:unignore', function (ev) {\r
+                var list = _kiwi.gateway.get('ignore_list');\r
+\r
+                if (!ev.params[0]) {\r
+                    _kiwi.app.panels.active.addMsg(' ', 'Specifiy which nick you wish to stop ignoring');\r
+                    return;\r
+                }\r
+\r
+                list = _.reject(list, function(pattern) {\r
+                    return pattern === ev.params[0];\r
+                });\r
+\r
+                _kiwi.gateway.set('ignore_list', list);\r
+\r
+                _kiwi.app.panels.active.addMsg(' ', 'Stopped ignoring ' + ev.params[0]);\r
+            });\r
+\r
+\r
             controlbox.on('command:applet', appletCommand);\r
             controlbox.on('command:settings', settingsCommand);\r
             controlbox.on('command:script', scriptCommand);\r
index 31766ea9e2999be4a02859f7a33dfbe43262e950..c06b39cc3dd8c83e8792b3bbeb7959ad37235370 100644 (file)
@@ -38,7 +38,13 @@ _kiwi.model.Gateway = function () {
         *   The URL to the Kiwi server\r
         *   @type   String\r
         */\r
-        kiwi_server: '//kiwi'\r
+        kiwi_server: '//kiwi',\r
+\r
+        /**\r
+        *   List of nicks we are ignoring\r
+        *   @type Array\r
+        */\r
+        ignore_list: []\r
     };\r
 \r
 \r
@@ -515,5 +521,23 @@ _kiwi.model.Gateway = function () {
     };\r
 \r
 \r
+    // Check a nick alongside our ignore list\r
+    this.isNickIgnored = function (nick) {\r
+        var idx, list = this.get('ignore_list');\r
+        var pattern, regex;\r
+\r
+        for (idx = 0; idx < list.length; idx++) {\r
+            pattern = list[idx].replace(/([.+^$[\]\\(){}|-])/g, "\\$1")\r
+                .replace('*', '.*')\r
+                .replace('?', '.');\r
+\r
+            regex = new RegExp(pattern, 'i');\r
+            if (regex.test(nick)) return true;\r
+        }\r
+\r
+        return false;\r
+    }\r
+\r
+\r
     return new (Backbone.Model.extend(this))(arguments);\r
 };
\ No newline at end of file