Improved message routing to panels; Unknown commands now recognised
authorDarren <darren@darrenwhitlen.com>
Sun, 26 Aug 2012 20:47:37 +0000 (21:47 +0100)
committerDarren <darren@darrenwhitlen.com>
Sun, 26 Aug 2012 20:47:37 +0000 (21:47 +0100)
client_backbone/model_application.js
client_backbone/view.js

index 58e4d677af5cb68979dc2a5139c5b37cc0a2b075..65f77ff4e30abaaacbbed238c152966b16baf373 100644 (file)
@@ -47,7 +47,7 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
         // Populate the server select box with defaults\r
         this.panels.server.server_login.populateFields({\r
             'nick': getQueryVariable('nick') || 'kiwi_' + Math.ceil(Math.random() * 10000).toString(),\r
-            'server': getQueryVariable('server') || 'irc.kiwiirc.net',\r
+            'server': getQueryVariable('server') || 'irc.kiwiirc.com',\r
             'channel': window.location.hash || '#test'\r
         });\r
     };\r
@@ -130,9 +130,8 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
         gw.on('onnotice', function (event) {\r
             var panel;\r
 \r
-            // If a panel isn't found for this channel, reroute to the\r
-            // server panel\r
-            panel = that.panels.getByName(event.target);\r
+            // Find a panel for the destination(channel) or who its from\r
+            panel = that.panels.getByName(event.target) || that.panels.getByName(event.nick);\r
             if (!panel) {\r
                 panel = that.panels.server;\r
             }\r
@@ -253,6 +252,9 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
             kiwi.gateway.changeNick(ev.params[0]);\r
         });\r
 \r
+        controlbox.on('command_query', this.queryCommand);\r
+        controlbox.on('command_q', this.queryCommand);\r
+\r
         controlbox.on('command_topic', this.topicCommand);\r
 \r
         controlbox.on('command_notice', this.noticeCommand);\r
@@ -265,8 +267,11 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
         });\r
     };\r
 \r
+    // A fallback action. Send a raw command to the server\r
     this.unknownCommand = function (ev) {\r
-        kiwi.gateway.raw(ev.command + ' ' + ev.params.join(' '));\r
+        var raw_cmd = ev.command + ' ' + ev.params.join(' ');\r
+        console.log('RAW: ' + raw_cmd);\r
+        kiwi.gateway.raw(raw_cmd);\r
     };\r
 \r
     this.allCommands = function (ev) {\r
@@ -296,9 +301,30 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
         \r
     };\r
 \r
+    this.queryCommand = function (ev) {\r
+        var destination, panel;\r
+\r
+        destination = ev.params[0];\r
+\r
+        // Check if we have the panel already. If not, create it\r
+        panel = that.panels.getByName(destination);\r
+        if (!panel) {\r
+            panel = new kiwi.model.Channel({name: destination});\r
+            kiwi.app.panels.add(panel);\r
+        }\r
+\r
+        if (panel) panel.view.show();\r
+        \r
+    };\r
+\r
     this.msgCommand = function (ev) {\r
-        kiwi.current_panel.addMsg(kiwi.gateway.get('nick'), ev.params.join(' '));\r
-        kiwi.gateway.privmsg(kiwi.current_panel.get('name'), ev.params.join(' '));\r
+        var destination = ev.params[0],\r
+            panel = that.panels.getByName(destination) || that.panels.server;\r
+\r
+        ev.params.shift();\r
+\r
+        panel.addMsg(kiwi.gateway.get('nick'), ev.params.join(' '));\r
+        kiwi.gateway.privmsg(destination, ev.params.join(' '));\r
     };\r
 \r
     this.partCommand = function (ev) {\r
index 9861d48fa8561649a132f7fd977bf7ecdd915460..76bf71e2da210511d296a4351bb8cc5ceabff4bb 100644 (file)
@@ -396,7 +396,9 @@ kiwi.view.ControlBox = Backbone.View.extend({
             command = params[0].substr(1).toLowerCase();\r
             params = params.splice(1);\r
         } else {\r
+            // Default command\r
             command = 'msg';\r
+            params.unshift(kiwi.current_panel.get('name'));\r
         }\r
 \r
         // Trigger the command events\r
@@ -405,7 +407,7 @@ kiwi.view.ControlBox = Backbone.View.extend({
 \r
         // If we didn't have any listeners for this event, fire a special case\r
         // TODO: This feels dirty. Should this really be done..?\r
-        if (!this._callbacks['command' + command]) {\r
+        if (!this._callbacks['command_' + command]) {\r
             this.trigger('unknown_command', {command: command, params: params});\r
         }\r
     }\r