From: Darren Date: Sat, 31 May 2014 13:01:18 +0000 (+0100) Subject: privmsg/action/notice events combined into a 'message' event X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6b2eb06b63ff2c655e44d1c56e452dc871104cf7;p=KiwiIRC.git privmsg/action/notice events combined into a 'message' event --- diff --git a/client/src/models/network.js b/client/src/models/network.js index 793a26b..f183fdd 100644 --- a/client/src/models/network.js +++ b/client/src/models/network.js @@ -129,12 +129,10 @@ this.gateway.on('part', onPart, this); this.gateway.on('quit', onQuit, this); this.gateway.on('kick', onKick, this); - this.gateway.on('msg', onMsg, this); + this.gateway.on('message', onMessage, this); this.gateway.on('nick', onNick, this); this.gateway.on('ctcp_request', onCtcpRequest, this); this.gateway.on('ctcp_response', onCtcpResponse, this); - this.gateway.on('notice', onNotice, this); - this.gateway.on('action', onAction, this); this.gateway.on('topic', onTopic, this); this.gateway.on('topicsetby', onTopicSetBy, this); this.gateway.on('userlist', onUserlist, this); @@ -399,16 +397,39 @@ - function onMsg(event) { + function onMessage(event) { var panel, - is_pm = (event.target.toLowerCase() == this.get('nick').toLowerCase()); + is_pm = ((event.target || '').toLowerCase() == this.get('nick').toLowerCase()); // An ignored user? don't do anything with it if (this.isNickIgnored(event.nick)) { return; } - if (is_pm) { + if (event.type == 'notice') { + if (event.from_server) { + panel = this.panels.server; + + } else { + panel = this.panels.getByName(event.target) || this.panels.getByName(event.nick); + + // Forward ChanServ messages to its associated channel + if (event.nick && event.nick.toLowerCase() == 'chanserv' && event.msg.charAt(0) == '[') { + channel_name = /\[([^ \]]+)\]/gi.exec(event.msg); + if (channel_name && channel_name[1]) { + channel_name = channel_name[1]; + + panel = this.panels.getByName(channel_name); + } + } + + } + + if (!panel) { + panel = this.panels.server; + } + + } else if (is_pm) { // If a panel isn't found for this PM, create one panel = this.panels.getByName(event.nick); if (!panel) { @@ -417,7 +438,7 @@ } } else { - // If a panel isn't found for this channel, reroute to the + // If a panel isn't found for this target, reroute to the // server panel panel = this.panels.getByName(event.target); if (!panel) { @@ -425,7 +446,27 @@ } } - panel.addMsg(event.nick, styleText('privmsg', {text: event.msg}), 'privmsg', {time: event.time}); + switch (event.type){ + case 'message': + panel.addMsg(event.nick, styleText('privmsg', {text: event.msg}), 'privmsg', {time: event.time}); + break; + + case 'action': + panel.addMsg('', styleText('action', {nick: event.nick, text: event.msg}), 'action', {time: event.time}); + break; + + case 'notice': + panel.addMsg('[' + (event.nick||'') + ']', styleText('notice', {text: event.msg}), 'notice', {time: event.time}); + + // Show this notice to the active panel if it didn't have a set target, but only in an active channel or query window + active_panel = _kiwi.app.panels().active; + + if (!event.from_server && panel === this.panels.server && active_panel !== this.panels.server) { + if (active_panel.get('network') === this && (active_panel.isChannel() || active_panel.isQuery())) + active_panel.addMsg('[' + (event.nick||'') + ']', styleText('notice', {text: event.msg}), 'notice', {time: event.time}); + } + break; + } } @@ -474,79 +515,6 @@ - function onNotice(event) { - var panel, active_panel, channel_name; - - // An ignored user? don't do anything with it - if (!event.from_server && event.nick && this.isNickIgnored(event.nick)) { - return; - } - - // Find a panel for the destination(channel) or who its from - if (!event.from_server) { - panel = this.panels.getByName(event.target) || this.panels.getByName(event.nick); - - // Forward ChanServ messages to its associated channel - if (event.nick && event.nick.toLowerCase() == 'chanserv' && event.msg.charAt(0) == '[') { - channel_name = /\[([^ \]]+)\]/gi.exec(event.msg); - if (channel_name && channel_name[1]) { - channel_name = channel_name[1]; - - panel = this.panels.getByName(channel_name); - } - } - - if (!panel) { - panel = this.panels.server; - } - } else { - panel = this.panels.server; - } - - panel.addMsg('[' + (event.nick||'') + ']', styleText('notice', {text: event.msg}), 'notice', {time: event.time}); - - // Show this notice to the active panel if it didn't have a set target, but only in an active channel or query window - active_panel = _kiwi.app.panels().active; - - if (!event.from_server && panel === this.panels.server && active_panel !== this.panels.server) { - if (active_panel.isChannel() || active_panel.isQuery()) - _kiwi.app.panels().active.addMsg('[' + (event.nick||'') + ']', styleText('notice', {text: event.msg}), 'notice', {time: event.time}); - } - } - - - - function onAction(event) { - var panel, - is_pm = (event.target.toLowerCase() == this.get('nick').toLowerCase()); - - // An ignored user? don't do anything with it - if (this.isNickIgnored(event.nick)) { - return; - } - - if (is_pm) { - // If a panel isn't found for this PM, create one - panel = this.panels.getByName(event.nick); - if (!panel) { - panel = new _kiwi.model.Channel({name: event.nick, network: this}); - this.panels.add(panel); - } - - } else { - // If a panel isn't found for this channel, reroute to the - // server panel - panel = this.panels.getByName(event.target); - if (!panel) { - panel = this.panels.server; - } - } - - panel.addMsg('', styleText('action', {nick: event.nick, text: event.msg}), 'action', {time: event.time}); - } - - - function onTopic(event) { var c; c = this.panels.getByName(event.channel); diff --git a/server/irc/channel.js b/server/irc/channel.js index f2a93d3..30d53ca 100644 --- a/server/irc/channel.js +++ b/server/irc/channel.js @@ -137,7 +137,8 @@ function onMsg(event) { irc_event: event }) .done(function() { - that.irc_connection.clientEvent('msg', { + that.irc_connection.clientEvent('message', { + type: 'message', nick: event.nick, ident: event.ident, hostname: event.hostname, @@ -158,7 +159,8 @@ function onAction(event) { irc_event: event }) .done(function() { - that.irc_connection.clientEvent('action', { + that.irc_connection.clientEvent('message', { + type: 'action', nick: event.nick, ident: event.ident, hostname: event.hostname, @@ -179,7 +181,8 @@ function onNotice(event) { irc_event: event }) .done(function() { - that.irc_connection.clientEvent('notice', { + that.irc_connection.clientEvent('message', { + type: 'notice', from_server: event.from_server, nick: event.nick, ident: event.ident, diff --git a/server/irc/user.js b/server/irc/user.js index 13b8297..89f8035 100755 --- a/server/irc/user.js +++ b/server/irc/user.js @@ -236,7 +236,8 @@ function onNotice(event) { irc_event: event }) .done(function() { - that.irc_connection.clientEvent('notice', { + that.irc_connection.clientEvent('message', { + type: 'notice', from_server: event.from_server, nick: event.nick, ident: event.ident, @@ -267,7 +268,8 @@ function onPrivmsg(event) { irc_event: event }) .done(function() { - that.irc_connection.clientEvent('msg', { + that.irc_connection.clientEvent('message', { + type: 'message', nick: event.nick, ident: event.ident, hostname: event.hostname, @@ -286,7 +288,8 @@ function onAction(event) { irc_event: event }) .done(function() { - that.irc_connection.clientEvent('action', { + that.irc_connection.clientEvent('message', { + type: 'action', nick: event.nick, ident: event.ident, hostname: event.hostname,