From: Jack Allnutt Date: Sat, 3 Nov 2012 20:25:20 +0000 (+0000) Subject: Implement client handling of irc: uris X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2f54e55e8a8d5ce9dd18612cf02fa968e6252690;p=KiwiIRC.git Implement client handling of irc: uris First half of the irc: uri handling. Issue #43 --- diff --git a/client/assets/dev/model_application.js b/client/assets/dev/model_application.js index 916710d..b3d11c7 100644 --- a/client/assets/dev/model_application.js +++ b/client/assets/dev/model_application.js @@ -140,8 +140,10 @@ kiwi.model.Application = function () { server: 'irc.kiwiirc.com', port: 6667, ssl: false, - channel: window.location.hash || '#kiwiirc' + channel: window.location.hash || '#kiwiirc', + channel_key: '' }; + var uricheck; // Process the URL part by part, extracting as we go parts = window.location.pathname.toString().replace(this.get('base_path'), '').split('/'); @@ -150,22 +152,51 @@ kiwi.model.Application = function () { parts.shift(); if (parts.length > 0 && parts[0]) { - // Extract the port+ssl if we find one - if (parts[0].search(/:/) > 0) { - defaults.port = parts[0].substring(parts[0].search(/:/) + 1); - defaults.server = parts[0].substring(0, parts[0].search(/:/)); - if (defaults.port[0] === '+') { - defaults.port = parseInt(defaults.port.substring(1), 10); - defaults.ssl = true; + uricheck = parts[0].substr(0, 7).toLowerCase(); + if ((uricheck === 'ircs%3a') || (uricheck.substr(0,6) === 'irc%3a')) { + parts[0] = decodeURIComponent(parts[0]); + console.log(parts[0]); + // irc[s]://[:]/[[?]] + uricheck = /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts[0]); + console.log(uricheck); + if (uricheck) { + if (uricheck[1]) { + defaults.ssl = true; + if (defaults.port === 6667) { + defaults.port = 6697; + } + } + defaults.server = uricheck[2]; + if (uricheck[3]) { + defaults.port = uricheck[3]; + } + if (uricheck[4]) { + defaults.channel = '#' + uricheck[4]; + if (uricheck[5]) { + defaults.channel_key = uricheck[5]; + } + } + } + console.log(defaults); + parts = []; + } else { + // Extract the port+ssl if we find one + if (parts[0].search(/:/) > 0) { + defaults.port = parts[0].substring(parts[0].search(/:/) + 1); + defaults.server = parts[0].substring(0, parts[0].search(/:/)); + if (defaults.port[0] === '+') { + defaults.port = parseInt(defaults.port.substring(1), 10); + defaults.ssl = true; + } else { + defaults.ssl = false; + } + } else { - defaults.ssl = false; + defaults.server = parts[0]; } - } else { - defaults.server = parts[0]; + parts.shift(); } - - parts.shift(); } if (parts.length > 0 && parts[0]) { @@ -192,7 +223,7 @@ kiwi.model.Application = function () { that.view.barsShow(); if (auto_connect_details.channel) { - that.controlbox.processInput('/JOIN ' + auto_connect_details.channel); + that.controlbox.processInput('/JOIN ' + auto_connect_details.channel + ' ' + auto_connect_details.channel_key); } }); diff --git a/client/assets/dev/view.js b/client/assets/dev/view.js index d15e691..6201b73 100644 --- a/client/assets/dev/view.js +++ b/client/assets/dev/view.js @@ -142,7 +142,8 @@ kiwi.view.ServerSelect = function () { port: $('.port', this.$el).val(), ssl: $('.ssl', this.$el).prop('checked'), password: $('.password', this.$el).val(), - channel: $('.channel', this.$el).val() + channel: $('.channel', this.$el).val(), + channel_key: $('.channel_key', this.$el).val() }; this.trigger('server_connect', values); @@ -159,7 +160,7 @@ kiwi.view.ServerSelect = function () { }, populateFields: function (defaults) { - var nick, server, channel; + var nick, server, port, channel, channel_key, ssl, password; defaults = defaults || {}; @@ -169,6 +170,7 @@ kiwi.view.ServerSelect = function () { ssl = defaults.ssl || 0; password = defaults.password || ''; channel = defaults.channel || ''; + channel_key = defaults.channel_key || ''; $('.nick', this.$el).val(nick); $('.server', this.$el).val(server); @@ -176,6 +178,7 @@ kiwi.view.ServerSelect = function () { $('.ssl', this.$el).prop('checked', ssl); $('.password', this.$el).val(password); $('.channel', this.$el).val(channel); + $('.channel_key', this.$el).val(channel_key); }, hide: function () { diff --git a/client/index.html b/client/index.html index b5f8cfe..d041272 100644 --- a/client/index.html +++ b/client/index.html @@ -91,6 +91,7 @@

+