From 18818abd0acc14bd7799ef54c39aa3b609b984ae Mon Sep 17 00:00:00 2001 From: Darren Date: Wed, 1 May 2013 22:48:48 +0100 Subject: [PATCH] Improved channel joining + panel creation; Auto joining improved --- client/assets/dev/model_application.js | 46 +++------------------ client/assets/dev/model_network.js | 56 +++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/client/assets/dev/model_application.js b/client/assets/dev/model_application.js index 9893307..2b65e37 100644 --- a/client/assets/dev/model_application.js +++ b/client/assets/dev/model_application.js @@ -550,38 +550,14 @@ _kiwi.model.Application = function () { function allCommands (ev) {} function joinCommand (ev) { - var channel, channel_names; + var panels, channel_names; channel_names = ev.params.join(' ').split(','); + panels = that.connections.active_connection.createAndJoinChannels(channel_names); - $.each(channel_names, function (index, channel_name_key) { - // We may have a channel key so split it off - var spli = channel_name_key.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 (!that.isChannelName(channel_name)) { - _kiwi.app.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.connections.active_connection.panels.getByName(channel_name); - if (!channel) { - channel = new _kiwi.model.Channel({name: channel_name}); - _kiwi.app.connections.active_connection.panels.add(channel); - } - - _kiwi.gateway.join(channel_name, channel_key); - }); - - if (channel) channel.view.show(); - + // Show the last channel if we have one + if (panels) + panels[panels.length - 1].view.show(); } function queryCommand (ev) { @@ -746,18 +722,6 @@ _kiwi.model.Application = function () { }; - - this.eachPanel = function (fn) { - alert('Switch this call with _kiwi.app.panels! location in console.log'); - console.log('Switch this call with _kiwi.app.panels! location in console.log'); - if (typeof fn !== 'function') - return; - - _.each(this.connections.models, function(connection) { - _.each(connection.panels.model, fn); - }); - }; - }; diff --git a/client/assets/dev/model_network.js b/client/assets/dev/model_network.js index 0a0301b..26e9a8e 100644 --- a/client/assets/dev/model_network.js +++ b/client/assets/dev/model_network.js @@ -80,16 +80,70 @@ 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(); } } -- 2.25.1