Improved channel joining + panel creation; Auto joining improved
authorDarren <darren@Darrens-MacBook-Pro.local>
Wed, 1 May 2013 21:48:48 +0000 (22:48 +0100)
committerDarren <darren@Darrens-MacBook-Pro.local>
Wed, 1 May 2013 21:48:48 +0000 (22:48 +0100)
client/assets/dev/model_application.js
client/assets/dev/model_network.js

index 98933074fadcd090738141d31c943ff6c4d66894..2b65e371972fecbc64e0cfaa50d50e5ce2bf71cb 100644 (file)
@@ -550,38 +550,14 @@ _kiwi.model.Application = function () {
         function allCommands (ev) {}\r
 \r
         function joinCommand (ev) {\r
-            var channel, channel_names;\r
+            var panels, channel_names;\r
 \r
             channel_names = ev.params.join(' ').split(',');\r
+            panels = that.connections.active_connection.createAndJoinChannels(channel_names);\r
 \r
-            $.each(channel_names, function (index, channel_name_key) {\r
-                // We may have a channel key so split it off\r
-                var spli = channel_name_key.split(' '),\r
-                    channel_name = spli[0],\r
-                    channel_key = spli[1] || '';\r
-\r
-                // Trim any whitespace off the name\r
-                channel_name = channel_name.trim();\r
-\r
-                // If not a valid channel name, display a warning\r
-                if (!that.isChannelName(channel_name)) {\r
-                    _kiwi.app.panels().server.addMsg('', channel_name + ' is not a valid channel name');\r
-                    _kiwi.app.message.text(channel_name + ' is not a valid channel name', {timeout: 5000});\r
-                    return;\r
-                }\r
-\r
-                // Check if we have the panel already. If not, create it\r
-                channel = that.connections.active_connection.panels.getByName(channel_name);\r
-                if (!channel) {\r
-                    channel = new _kiwi.model.Channel({name: channel_name});\r
-                    _kiwi.app.connections.active_connection.panels.add(channel);\r
-                }\r
-\r
-                _kiwi.gateway.join(channel_name, channel_key);\r
-            });\r
-\r
-            if (channel) channel.view.show();\r
-            \r
+            // Show the last channel if we have one\r
+            if (panels)\r
+                panels[panels.length - 1].view.show();\r
         }\r
 \r
         function queryCommand (ev) {\r
@@ -746,18 +722,6 @@ _kiwi.model.Application = function () {
         };\r
 \r
 \r
-\r
-        this.eachPanel = function (fn) {\r
-            alert('Switch this call with _kiwi.app.panels! location in console.log');\r
-            console.log('Switch this call with _kiwi.app.panels! location in console.log');\r
-            if (typeof fn !== 'function')\r
-                return;\r
-\r
-            _.each(this.connections.models, function(connection) {\r
-                _.each(connection.panels.model, fn);\r
-            });\r
-        };\r
-\r
     };\r
 \r
 \r
index 0a0301b6e284a818977034eb76de05236d4b64b1..26e9a8ee6112bf9c95b89180d12e47dd61cbada9 100644 (file)
             this.gateway.on('whois', onWhois, this);
             this.gateway.on('away', onAway, this);
             this.gateway.on('list_start', onListStart, this);
+        },
+
+
+        /**
+         * Create panels and join the channel
+         * This will not wait for the join event to create a panel. This
+         * increases responsiveness in case of network lag
+         */
+        createAndJoinChannels: function (channels) {
+            var that = this,
+                panels = [];
+
+            // Multiple channels may come as comma-delimited 
+            if (typeof channels === 'string') {
+                channels = channels.split(',');
+            }
+
+            $.each(channels, function (index, channel_name_key) {
+                // We may have a channel key so split it off
+                var spli = channel_name_key.trim().split(' '),
+                    channel_name = spli[0],
+                    channel_key = spli[1] || '';
+
+                // Trim any whitespace off the name
+                channel_name = channel_name.trim();
+
+                // If not a valid channel name, display a warning
+                if (!_kiwi.app.isChannelName(channel_name)) {
+                    that.panels.server.addMsg('', channel_name + ' is not a valid channel name');
+                    _kiwi.app.message.text(channel_name + ' is not a valid channel name', {timeout: 5000});
+                    return;
+                }
+
+                // Check if we have the panel already. If not, create it
+                channel = that.panels.getByName(channel_name);
+                if (!channel) {
+                    channel = new _kiwi.model.Channel({name: channel_name});
+                    that.panels.add(channel);
+                }
+
+                panels.push(channel);
+
+                that.gateway.join(channel_name, channel_key);
+            });
+
+            return panels;
         }
     });
 
 
 
     function onConnect(event) {
+        var panels, channel_names;
+
+        // Update our nick with what the network gave us
         this.set('nick', event.nick);
 
+        // Auto joining channels
         if (this.auto_join && this.auto_join.channel) {
-            this.gateway.join(this.auto_join.channel, this.auto_join.channel_key);
+            panels = this.createAndJoinChannels(this.auto_join.channel + ' ' + (this.auto_join.channel_key || ''));
+
+            // Show the last channel if we have one
+            if (panels)
+                panels[panels.length - 1].view.show();
         }
     }