From fc9b83de71cce0b055b9cb2a0aaeaabf74c15ff1 Mon Sep 17 00:00:00 2001 From: Darren Date: Wed, 24 Apr 2013 22:03:50 +0100 Subject: [PATCH] Change nick UI + nick updating properly --- client/assets/dev/app.js | 2 +- client/assets/dev/model_application.js | 2 +- client/assets/dev/model_gateway.js | 25 ++++++++++--------------- client/assets/dev/view.js | 8 ++++---- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/client/assets/dev/app.js b/client/assets/dev/app.js index 6b9922b..39c5be6 100644 --- a/client/assets/dev/app.js +++ b/client/assets/dev/app.js @@ -65,7 +65,7 @@ _kiwi.global = { var funcs = { kiwi: 'kiwi', raw: 'raw', kick: 'kick', topic: 'topic', part: 'part', join: 'join', action: 'action', ctcp: 'ctcp', - notice: 'notice', msg: 'privmsg', + notice: 'notice', msg: 'privmsg', changeNick: 'changeNick', get: 'get' }; diff --git a/client/assets/dev/model_application.js b/client/assets/dev/model_application.js index bff5175..3825f61 100644 --- a/client/assets/dev/model_application.js +++ b/client/assets/dev/model_application.js @@ -72,7 +72,7 @@ _kiwi.model.Application = function () { _kiwi.gateway.set('kiwi_server', that.kiwi_server + '/kiwi'); _kiwi.gateway.set('nick', event.nick); - _kiwi.gateway.connect(event.server, event.port, event.ssl, event.password, function (error) { + _kiwi.gateway.connect(event.nick, event.server, event.port, event.ssl, event.password, function (error) { if (error) { kiwiServerNotFound(); } diff --git a/client/assets/dev/model_gateway.js b/client/assets/dev/model_gateway.js index 9db724b..5e0caa5 100644 --- a/client/assets/dev/model_gateway.js +++ b/client/assets/dev/model_gateway.js @@ -75,7 +75,8 @@ _kiwi.model.Gateway = function () { // Some easier handler events this.on('onmsg', function (event) { var source, - is_pm = (event.channel == that.get('nick')); + connection = _kiwi.app.connections.getByConnectionId(event.server), + is_pm = (event.channel == connection.get('nick')); source = is_pm ? event.nick : event.channel; @@ -100,7 +101,8 @@ _kiwi.model.Gateway = function () { this.on('onaction', function (event) { var source, - is_pm = (event.channel == that.get('nick')); + connection = _kiwi.app.connections.getByConnectionId(event.server), + is_pm = (event.channel == cinnection.get('nick')); source = is_pm ? event.nick : event.channel; @@ -130,13 +132,14 @@ _kiwi.model.Gateway = function () { /** * Connects to the server + * @param {String} nick The nickname of the user to use on the network * @param {String} host The hostname or IP address of the IRC server to connect to * @param {Number} port The port of the IRC server to connect to * @param {Boolean} ssl Whether or not to connect to the IRC server using SSL * @param {String} password The password to supply to the IRC server during registration * @param {Function} callback A callback function to be invoked once Kiwi's server has connected to the IRC server */ - this.connect = function (host, port, ssl, password, callback) { + this.connect = function (nick, host, port, ssl, password, callback) { var resource; // Work out the resource URL for socket.io @@ -180,7 +183,7 @@ _kiwi.model.Gateway = function () { */ this.socket.on('connect', function () { that.newConnection({ - nick: that.get('nick'), + nick: nick, host: host, port: port, ssl: ssl, @@ -291,8 +294,6 @@ _kiwi.model.Gateway = function () { //console.log('gateway event', command, data); if (command !== undefined) { - that.trigger('on' + command, data); - switch (command) { case 'options': $.each(data.options, function (name, value) { @@ -311,15 +312,6 @@ _kiwi.model.Gateway = function () { that.set('cap', data.cap); break; - case 'connect': - that.set('nick', data.nick); - break; - - case 'nick': - if (data.nick === that.get('nick')) { - that.set('nick', data.newnick); - } - break; /* case 'sync': if (_kiwi.gateway.onSync && _kiwi.gateway.syncing) { @@ -342,6 +334,9 @@ _kiwi.model.Gateway = function () { event_data: data }); } + + // Trigger the global events (Mainly legacy now) + that.trigger('on' + command, data); }; /** diff --git a/client/assets/dev/view.js b/client/assets/dev/view.js index d7ba008..31f73ff 100644 --- a/client/assets/dev/view.js +++ b/client/assets/dev/view.js @@ -154,7 +154,10 @@ _kiwi.view.NickChangeBox = Backbone.View.extend({ changeNick: function (event) { var that = this; - _kiwi.gateway.changeNick(this.$el.find('input').val(), function (err, val) { + + event.preventDefault(); + + _kiwi.app.connections.active_connection.gateway.changeNick(this.$el.find('input').val(), function (err, val) { that.close(); }); return false; @@ -904,9 +907,6 @@ _kiwi.view.ControlBox = Backbone.View.extend({ _kiwi.gateway.bind('onnick', function (event) { $('.nick', that.$el).text(_kiwi.app.connections.active_connection.get('nick')); }); - _kiwi.gateway.bind('onconnect', function (event) { - $('.nick', that.$el).text(event.nick); - }); // Update our nick view as we flick between connections _kiwi.app.connections.on('active', function(panel, connection) { -- 2.25.1