Implement client handling of irc: uris
authorJack Allnutt <m2ys4u@Gmail.com>
Sat, 3 Nov 2012 20:25:20 +0000 (20:25 +0000)
committerJack Allnutt <m2ys4u@Gmail.com>
Sat, 3 Nov 2012 20:25:20 +0000 (20:25 +0000)
First half of the irc: uri handling.

Issue #43

client/assets/dev/model_application.js
client/assets/dev/view.js
client/index.html

index 916710def8a0392d7ad9b2f0a974fdaae0773950..b3d11c7c467f3b099aaf6bf39ed08a1aef2a13ec 100644 (file)
@@ -140,8 +140,10 @@ kiwi.model.Application = function () {
                 server: 'irc.kiwiirc.com',\r
                 port: 6667,\r
                 ssl: false,\r
-                channel: window.location.hash || '#kiwiirc'\r
+                channel: window.location.hash || '#kiwiirc',\r
+                channel_key: ''\r
             };\r
+            var uricheck;\r
 \r
             // Process the URL part by part, extracting as we go\r
             parts = window.location.pathname.toString().replace(this.get('base_path'), '').split('/');\r
@@ -150,22 +152,51 @@ kiwi.model.Application = function () {
                 parts.shift();\r
 \r
                 if (parts.length > 0 && parts[0]) {\r
-                    // Extract the port+ssl if we find one\r
-                    if (parts[0].search(/:/) > 0) {\r
-                        defaults.port = parts[0].substring(parts[0].search(/:/) + 1);\r
-                        defaults.server = parts[0].substring(0, parts[0].search(/:/));\r
-                        if (defaults.port[0] === '+') {\r
-                            defaults.port = parseInt(defaults.port.substring(1), 10);\r
-                            defaults.ssl = true;\r
+                    uricheck = parts[0].substr(0, 7).toLowerCase();\r
+                    if ((uricheck === 'ircs%3a') || (uricheck.substr(0,6) === 'irc%3a')) {\r
+                        parts[0] = decodeURIComponent(parts[0]);\r
+                        console.log(parts[0]);\r
+                        // irc[s]://<host>[:<port>]/[<channel>[?<password>]]\r
+                        uricheck = /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts[0]);\r
+                        console.log(uricheck);\r
+                        if (uricheck) {\r
+                            if (uricheck[1]) {\r
+                                defaults.ssl = true;\r
+                                if (defaults.port === 6667) {\r
+                                    defaults.port = 6697;\r
+                                }\r
+                            }\r
+                            defaults.server = uricheck[2];\r
+                            if (uricheck[3]) {\r
+                                defaults.port = uricheck[3];\r
+                            }\r
+                            if (uricheck[4]) {\r
+                                defaults.channel = '#' + uricheck[4];\r
+                                if (uricheck[5]) {\r
+                                    defaults.channel_key = uricheck[5];\r
+                                }\r
+                            }\r
+                        }\r
+                        console.log(defaults);\r
+                        parts = [];\r
+                    } else {\r
+                        // Extract the port+ssl if we find one\r
+                        if (parts[0].search(/:/) > 0) {\r
+                            defaults.port = parts[0].substring(parts[0].search(/:/) + 1);\r
+                            defaults.server = parts[0].substring(0, parts[0].search(/:/));\r
+                            if (defaults.port[0] === '+') {\r
+                                defaults.port = parseInt(defaults.port.substring(1), 10);\r
+                                defaults.ssl = true;\r
+                            } else {\r
+                                defaults.ssl = false;\r
+                            }\r
+\r
                         } else {\r
-                            defaults.ssl = false;\r
+                            defaults.server = parts[0];\r
                         }\r
 \r
-                    } else {\r
-                        defaults.server = parts[0];\r
+                        parts.shift();\r
                     }\r
-\r
-                    parts.shift();\r
                 }\r
 \r
                 if (parts.length > 0 && parts[0]) {\r
@@ -192,7 +223,7 @@ kiwi.model.Application = function () {
                 that.view.barsShow();\r
                 \r
                 if (auto_connect_details.channel) {\r
-                    that.controlbox.processInput('/JOIN ' + auto_connect_details.channel);\r
+                    that.controlbox.processInput('/JOIN ' + auto_connect_details.channel + ' ' + auto_connect_details.channel_key);\r
                 }\r
             });\r
 \r
index d15e69184bc6ce0a53797c5e56d6ad02689d4884..6201b73f5625e26ad7fa7e1811f555552cd15c56 100644 (file)
@@ -142,7 +142,8 @@ kiwi.view.ServerSelect = function () {
                 port: $('.port', this.$el).val(),\r
                 ssl: $('.ssl', this.$el).prop('checked'),\r
                 password: $('.password', this.$el).val(),\r
-                channel: $('.channel', this.$el).val()\r
+                channel: $('.channel', this.$el).val(),\r
+                channel_key: $('.channel_key', this.$el).val()\r
             };\r
 \r
             this.trigger('server_connect', values);\r
@@ -159,7 +160,7 @@ kiwi.view.ServerSelect = function () {
         },\r
 \r
         populateFields: function (defaults) {\r
-            var nick, server, channel;\r
+            var nick, server, port, channel, channel_key, ssl, password;\r
 \r
             defaults = defaults || {};\r
 \r
@@ -169,6 +170,7 @@ kiwi.view.ServerSelect = function () {
             ssl = defaults.ssl || 0;\r
             password = defaults.password || '';\r
             channel = defaults.channel || '';\r
+            channel_key = defaults.channel_key || '';\r
 \r
             $('.nick', this.$el).val(nick);\r
             $('.server', this.$el).val(server);\r
@@ -176,6 +178,7 @@ kiwi.view.ServerSelect = function () {
             $('.ssl', this.$el).prop('checked', ssl);\r
             $('.password', this.$el).val(password);\r
             $('.channel', this.$el).val(channel);\r
+            $('.channel_key', this.$el).val(channel_key);\r
         },\r
 \r
         hide: function () {\r
index b5f8cfeb256205a5259d07fdcfdfd462fdeb83e2..d041272a7303f250275fd48e1334f63f2d68535c 100644 (file)
@@ -91,6 +91,7 @@
                         <input type="text" class="server" id="server_select_server"> <br />
                         <label for="server_select_channel">Channel</label>
                         <input type="text" class="channel" id="server_select_channel"> <br />
+                        <input type="hidden" class="channel_key">
                         <br />
                         <label for="server_select_port">Port</label>
                         <input type="text" class="port" id="server_select_port"> <br />