Client side /ignore + /unignore commands
[KiwiIRC.git] / client / assets / dev / model_gateway.js
index c9ccf016d33060ae97eb06ba4d6a5ea40b8127b4..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
@@ -54,9 +60,8 @@ _kiwi.model.Gateway = function () {
 \r
     this.applyEventHandlers = function () {\r
         /*\r
-        TODO: Impliment event 'groups' to remove a listener group\r
-        kiwi.gateway.on('msg:#channel', my_function);\r
-        kiwi.gateway.on('msg:somenick', my_function);\r
+        kiwi.gateway.on('message:#channel', my_function);\r
+        kiwi.gateway.on('message:somenick', my_function);\r
 \r
         kiwi.gateway.on('notice:#channel', my_function);\r
         kiwi.gateway.on('action:somenick', my_function);\r
@@ -112,6 +117,13 @@ _kiwi.model.Gateway = function () {
             that.trigger('topic:' + event.channel, event);\r
             that.trigger('topic', event);\r
         });\r
+\r
+\r
+        this.on('onjoin', function (event) {\r
+            that.trigger('join:' + event.channel, event);\r
+            that.trigger('join', event);\r
+        });\r
+\r
     };\r
 \r
 \r
@@ -218,7 +230,8 @@ _kiwi.model.Gateway = function () {
 \r
 \r
     this.parseKiwi = function (command, data) {\r
-        console.log('kiwi event', command, data);\r
+        this.trigger('kiwi:' + command, data);\r
+        this.trigger('kiwi', data);\r
     };\r
     /*\r
         Events:\r
@@ -508,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