Remove cruft from gateway object
authorJack Allnutt <jack@allnutt.eu>
Thu, 20 Feb 2014 00:06:24 +0000 (00:06 +0000)
committerJack Allnutt <jack@allnutt.eu>
Thu, 20 Feb 2014 00:10:40 +0000 (00:10 +0000)
Things that should be Network-local now look for properties on the Network
object rather than on the Gateway object.

client-side ignore functionality is now per-network rather than global.

client/src/models/applet.js
client/src/models/application.js
client/src/models/channel.js
client/src/models/gateway.js
client/src/models/network.js
client/src/models/panel.js
client/src/models/query.js
client/src/models/server.js
client/src/views/channel.js
client/src/views/channeltools.js
client/src/views/topicbar.js

index b9692822ff6e016addcfca7ce3b0a88417414512..3414ebf314cadc44d546a6ddd079d50fc11c1173 100644 (file)
@@ -1,9 +1,4 @@
 _kiwi.model.Applet = _kiwi.model.Panel.extend({\r
-    // Used to determine if this is an applet panel. Applet panel tabs are treated\r
-    // differently than others\r
-    applet: true,\r
-\r
-\r
     initialize: function (attributes) {\r
         // Temporary name\r
         var name = "applet_"+(new Date().getTime().toString()) + Math.ceil(Math.random()*100).toString();\r
@@ -82,6 +77,10 @@ _kiwi.model.Applet = _kiwi.model.Panel.extend({
         }\r
 \r
         this.closePanel();\r
+    },\r
+\r
+    isApplet: function () {\r
+        return true;\r
     }\r
 },\r
 \r
index 704587cc5cd96c1440b3259828dea252288ca091..58af46c155cd36af4e75f4bb0c2c4b58bd23d29c 100644 (file)
 \r
 \r
             fn_to_bind['command:ignore'] = function (ev) {\r
-                var list = _kiwi.gateway.get('ignore_list');\r
+                var list = this.connections.active_connection.get('ignore_list');\r
 \r
                 // No parameters passed so list them\r
                 if (!ev.params[0]) {\r
 \r
                 // We have a parameter, so add it\r
                 list.push(ev.params[0]);\r
-                _kiwi.gateway.set('ignore_list', list);\r
+                this.connections.active_connection.set('ignore_list', list);\r
                 _kiwi.app.panels().active.addMsg(' ', _kiwi.global.i18n.translate('client_models_application_ignore_nick').fetch(ev.params[0]));\r
             };\r
 \r
 \r
             fn_to_bind['command:unignore'] = function (ev) {\r
-                var list = _kiwi.gateway.get('ignore_list');\r
+                var list = this.connections.active_connection.get('ignore_list');\r
 \r
                 if (!ev.params[0]) {\r
                     _kiwi.app.panels().active.addMsg(' ', _kiwi.global.i18n.translate('client_models_application_ignore_stop_notice').fetch());\r
                     return pattern === ev.params[0];\r
                 });\r
 \r
-                _kiwi.gateway.set('ignore_list', list);\r
+                this.connections.active_connection.set('ignore_list', list);\r
 \r
                 _kiwi.app.panels().active.addMsg(' ', _kiwi.global.i18n.translate('client_models_application_ignore_stopped').fetch(ev.params[0]));\r
             };\r
     function unknownCommand (ev) {\r
         var raw_cmd = ev.command + ' ' + ev.params.join(' ');\r
         console.log('RAW: ' + raw_cmd);\r
-        _kiwi.gateway.raw(null, raw_cmd);\r
+        this.connections.active_connection.gateway.raw(raw_cmd);\r
     }\r
 \r
     function allCommands (ev) {}\r
         message = formatToIrcMsg(ev.params.join(' '));\r
 \r
         panel.addMsg(_kiwi.app.connections.active_connection.get('nick'), message);\r
-        _kiwi.gateway.privmsg(null, destination, message);\r
+        this.connections.active_connection.gateway.privmsg(destination, message);\r
     }\r
 \r
     function actionCommand (ev) {\r
 \r
         var panel = _kiwi.app.panels().active;\r
         panel.addMsg('', '* ' + _kiwi.app.connections.active_connection.get('nick') + ' ' + ev.params.join(' '), 'action');\r
-        _kiwi.gateway.action(null, panel.get('name'), ev.params.join(' '));\r
+        this.connections.active_connection.gateway.action(panel.get('name'), ev.params.join(' '));\r
     }\r
 \r
     function partCommand (ev) {\r
         if (ev.params.length === 0) {\r
-            _kiwi.gateway.part(null, _kiwi.app.panels().active.get('name'));\r
+            this.connections.active_connection.gateway.part(_kiwi.app.panels().active.get('name'));\r
         } else {\r
             _.each(ev.params, function (channel) {\r
-                _kiwi.gateway.part(null, channel);\r
+                this.connections.active_connection.gateway.part(channel);\r
             });\r
         }\r
     }\r
 \r
     function nickCommand (ev) {\r
-        _kiwi.gateway.changeNick(null, ev.params[0]);\r
+        this.connections.active_connection.gateway.changeNick(ev.params[0]);\r
     }\r
 \r
     function topicCommand (ev) {\r
             channel_name = _kiwi.app.panels().active.get('name');\r
         }\r
 \r
-        _kiwi.gateway.topic(null, channel_name, ev.params.join(' '));\r
+        this.connections.active_connection.gateway.topic(channel_name, ev.params.join(' '));\r
     }\r
 \r
     function noticeCommand (ev) {\r
         destination = ev.params[0];\r
         ev.params.shift();\r
 \r
-        _kiwi.gateway.notice(null, destination, ev.params.join(' '));\r
+        this.connections.active_connection.gateway.notice(destination, ev.params.join(' '));\r
     }\r
 \r
     function quoteCommand (ev) {\r
         var raw = ev.params.join(' ');\r
-        _kiwi.gateway.raw(null, raw);\r
+        this.connections.active_connection.gateway.raw(raw);\r
     }\r
 \r
     function kickCommand (ev) {\r
         nick = ev.params[0];\r
         ev.params.shift();\r
 \r
-        _kiwi.gateway.kick(null, panel.get('name'), nick, ev.params.join(' '));\r
+        this.connections.active_connection.gateway.kick(panel.get('name'), nick, ev.params.join(' '));\r
     }\r
 \r
     function clearCommand (ev) {\r
         type = ev.params[0];\r
         ev.params.shift();\r
 \r
-        _kiwi.gateway.ctcp(null, true, type, target, ev.params.join(' '));\r
+        this.connections.active_connection.gateway.ctcp(true, type, target, ev.params.join(' '));\r
     }\r
 \r
     function settingsCommand (ev) {\r
index 18d0538f97445511baae4d775ce06484c1d3e663..899c450999ea61ae2928b67e9a8e7254accb17dc 100644 (file)
@@ -110,5 +110,9 @@ _kiwi.model.Channel = _kiwi.model.Panel.extend({
 \r
     setMode: function(mode_string) {\r
         this.get('network').gateway.mode(this.get('name'), mode_string);\r
+    },\r
+\r
+    isChannel: function() {\r
+        return true;\r
     }\r
 });\r
index 7ee21fa5bd806a6c185e2d1f76599c540d8b4511..0744803a0677e735b5b736fa65f9d34a4b6746e1 100644 (file)
@@ -3,51 +3,6 @@ _kiwi.model.Gateway = function () {
     // Set to a reference to this object within initialize()\r
     var that = null;\r
 \r
-    this.defaults = {\r
-        /**\r
-        *   The name of the network\r
-        *   @type    String\r
-        */\r
-        name: 'Server',\r
-\r
-        /**\r
-        *   The address (URL) of the network\r
-        *   @type    String\r
-        */\r
-        address: '',\r
-\r
-        /**\r
-        *   The current nickname\r
-        *   @type   String\r
-        */\r
-        nick: '',\r
-\r
-        /**\r
-        *   The channel prefix for this network\r
-        *   @type    String\r
-        */\r
-        channel_prefix: '#',\r
-\r
-        /**\r
-        *   The user prefixes for channel owner/admin/op/voice etc. on this network\r
-        *   @type   Array\r
-        */\r
-        user_prefixes: ['~', '&', '@', '+'],\r
-\r
-        /**\r
-        *   The URL to the Kiwi server\r
-        *   @type   String\r
-        */\r
-        kiwi_server: '//kiwi',\r
-\r
-        /**\r
-        *   List of nicks we are ignoring\r
-        *   @type Array\r
-        */\r
-        ignore_list: []\r
-    };\r
-\r
-\r
     this.initialize = function () {\r
         that = this;\r
 \r
@@ -640,23 +595,6 @@ _kiwi.model.Gateway = function () {
         this.sendData(data, callback);\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
 };\r
index 3f0fab1240dd0c811a8ee7d72660bf62c1e3f548..b9ecb0d4bbee3d0716e07e1d6421389d4825750f 100644 (file)
             *   The user prefixes for channel owner/admin/op/voice etc. on this network
             *   @type   Array
             */
-            user_prefixes: ['~', '&', '@', '+']
+            user_prefixes: ['~', '&', '@', '+'],
+
+            /**
+            *   List of nicks we are ignoring
+            *   @type Array
+            */
+            ignore_list: []
         },
 
 
                 channel_name = channel_name.trim();
 
                 // If not a valid channel name, display a warning
-                if (!_kiwi.app.isChannelName(channel_name)) {
+                if (!that.isChannelName(channel_name)) {
                     that.panels.server.addMsg('', _kiwi.global.i18n.translate('client_models_network_channel_invalid_name').fetch(channel_name));
                     _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_channel_invalid_name').fetch(channel_name), {timeout: 5000});
                     return;
 
                 that.gateway.join(panel.get('name'));
             });
+        },
+
+        isChannelName: function (channel_name) {
+            var channel_prefix = this.get('channel_prefix');
+
+            if (!channel_name || !channel_name.length) return false;
+            return (channel_prefix.indexOf(channel_name[0]) > -1);
+        },
+
+        // Check a nick alongside our ignore list
+        isNickIgnored: function (nick) {
+            var idx, list = this.get('ignore_list');
+            var pattern, regex;
+
+            for (idx = 0; idx < list.length; idx++) {
+                pattern = list[idx].replace(/([.+^$[\]\\(){}|-])/g, "\\$1")
+                    .replace('*', '.*')
+                    .replace('?', '.');
+
+                regex = new RegExp(pattern, 'i');
+                if (regex.test(nick)) return true;
+            }
+
+            return false;
         }
     });
 
             is_pm = (event.channel.toLowerCase() == this.get('nick').toLowerCase());
 
         // An ignored user? don't do anything with it
-        if (_kiwi.gateway.isNickIgnored(event.nick)) {
+        if (this.isNickIgnored(event.nick)) {
             return;
         }
 
 
     function onCtcpRequest(event) {
         // An ignored user? don't do anything with it
-        if (_kiwi.gateway.isNickIgnored(event.nick)) {
+        if (this.isNickIgnored(event.nick)) {
             return;
         }
 
 
     function onCtcpResponse(event) {
         // An ignored user? don't do anything with it
-        if (_kiwi.gateway.isNickIgnored(event.nick)) {
+        if (this.isNickIgnored(event.nick)) {
             return;
         }
 
         var panel, channel_name;
 
         // An ignored user? don't do anything with it
-        if (!event.from_server && event.nick && _kiwi.gateway.isNickIgnored(event.nick)) {
+        if (!event.from_server && event.nick && this.isNickIgnored(event.nick)) {
             return;
         }
 
             is_pm = (event.channel.toLowerCase() == this.get('nick').toLowerCase());
 
         // An ignored user? don't do anything with it
-        if (_kiwi.gateway.isNickIgnored(event.nick)) {
+        if (this.isNickIgnored(event.nick)) {
             return;
         }
 
index 943658e7acdd697225545673afe79fd90317d201..ec483f624955dcc637ae984051b28ab84543cde5 100644 (file)
@@ -39,27 +39,19 @@ _kiwi.model.Panel = Backbone.Model.extend({
     },\r
 \r
     isChannel: function () {\r
-        var channel_prefix = _kiwi.gateway.get('channel_prefix'),\r
-            this_name = this.get('name');\r
-\r
-        if (this.isApplet() || !this_name) return false;\r
-        return (channel_prefix.indexOf(this_name[0]) > -1);\r
+        return false;\r
     },\r
 \r
     isQuery: function () {\r
-        if (!this.isChannel() && !this.isApplet() && !this.isServer()) {\r
-            return true;\r
-        }\r
-\r
         return false;\r
     },\r
 \r
     isApplet: function () {\r
-        return this.applet ? true : false;\r
+        return false;\r
     },\r
 \r
     isServer: function () {\r
-        return this.server ? true : false;\r
+        return false;\r
     },\r
 \r
     isActive: function () {\r
index 3cf82ff4cbfed86f81f10cf87c24ff0cdaaa07a6..293be21b1eec1365e12e46ee103b834a48ec784a 100644 (file)
@@ -8,5 +8,13 @@ _kiwi.model.Query = _kiwi.model.Channel.extend({
             "name": name,\r
             "scrollback": []\r
         }, {"silent": true});\r
+    },\r
+\r
+    isChannel: function () {\r
+        return false;\r
+    },\r
+\r
+    isQuery: function () {\r
+        return true;\r
     }\r
 });
\ No newline at end of file
index f3017c22e46f9425c7d385ef79001c260b8b8c96..3410394e7ccc4d683f0db891321b66e0d138797b 100644 (file)
@@ -1,7 +1,4 @@
 _kiwi.model.Server = _kiwi.model.Channel.extend({\r
-    // Used to determine if this is a server panel\r
-    server: true,\r
-\r
     initialize: function (attributes) {\r
         var name = "Server";\r
         this.view = new _kiwi.view.Channel({"model": this, "name": name});\r
@@ -11,5 +8,13 @@ _kiwi.model.Server = _kiwi.model.Channel.extend({
         }, {"silent": true});\r
 \r
         //this.addMsg(' ', '--> Kiwi IRC: Such an awesome IRC client', '', {style: 'color:#009900;'});\r
+    },\r
+\r
+    isServer: function () {\r
+        return true;\r
+    },\r
+\r
+    isChannel: function () {\r
+        return false;\r
     }\r
 });
\ No newline at end of file
index cac53655b4238e4c04f0611c109b75215d0d517f..8bbaa99f8f0ee55c2cc15282a952da5c68194f0d 100644 (file)
@@ -58,7 +58,8 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
             nick_colour_hex, nick_hex, is_highlight, msg_css_classes = '',
             time_difference,
             sb = this.model.get('scrollback'),
-            prev_msg = sb[sb.length-2];
+            prev_msg = sb[sb.length-2],
+            network;
 
         // Nick highlight detecting
         if ((new RegExp('(^|\\W)(' + escapeRegex(_kiwi.app.connections.active_connection.get('nick')) + ')(\\W|$)', 'i')).test(msg.msg)) {
@@ -70,10 +71,12 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
         msg.msg =  $('<div />').text(msg.msg).html();
 
         // Make the channels clickable
-        re = new RegExp('(?:^|\\s)([' + escapeRegex(_kiwi.gateway.get('channel_prefix')) + '][^ ,\\007]+)', 'g');
-        msg.msg = msg.msg.replace(re, function (match) {
-            return '<a class="chan" data-channel="' + match.trim() + '">' + match + '</a>';
-        });
+        if ((network = this.model.get('network'))) {
+        re = new RegExp('(?:^|\\s)([' + escapeRegex(network.get('channel_prefix')) + '][^ ,\\007]+)', 'g');
+            msg.msg = msg.msg.replace(re, function (match) {
+                return '<a class="chan" data-channel="' + match.trim() + '">' + match + '</a>';
+            });
+        }
 
 
         // Parse any links found
@@ -275,12 +278,9 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
 
 
     chanClick: function (event) {
-        if (event.target) {
-            _kiwi.gateway.join(null, $(event.target).data('channel'));
-        } else {
-            // IE...
-            _kiwi.gateway.join(null, $(event.srcElement).data('channel'));
-        }
+        var target = (event.target) ? $(event.target).data('channel') : $(event.srcElement).data('channel');
+
+        _kiwi.app.connections.active_connection.gateway.join(target);
     },
 
 
index ffbfda06eeab9e4e05801e8fd78e0733a14841ae..bc98fdf3d4e3e8e1bc562b6baa6d3f249d703b7b 100644 (file)
@@ -11,6 +11,6 @@ _kiwi.view.ChannelTools = Backbone.View.extend({
     },
 
     partClick: function (event) {
-        _kiwi.gateway.part(null, _kiwi.app.panels().active.get('name'));
+        _kiwi.app.connections.active_connection.gateway.part(_kiwi.app.panels().active.get('name'));
     }
 });
\ No newline at end of file
index 7cc2f3733db114e858d36b4ee52e664b9d499b64..c12507fe369b580384543408cdad8d578b7dec18 100644 (file)
@@ -29,7 +29,7 @@ _kiwi.view.TopicBar = Backbone.View.extend({
 
         // If hit return key, update the current topic
         if (ev.keyCode === 13) {
-            _kiwi.gateway.topic(null, _kiwi.app.panels().active.get('name'), inp_val);
+            _kiwi.app.connections.active_connection.gateway.topic(_kiwi.app.panels().active.get('name'), inp_val);
             return false;
         }
     },