privmsg/action/notice events combined into a 'message' event
authorDarren <darren@darrenwhitlen.com>
Sat, 31 May 2014 13:01:18 +0000 (14:01 +0100)
committerDarren <darren@darrenwhitlen.com>
Sat, 31 May 2014 13:01:18 +0000 (14:01 +0100)
client/src/models/network.js
server/irc/channel.js
server/irc/user.js

index 793a26b1f3198c7df326802cfdcd891a06b9c2d0..f183fddfc595a5a606a17c341d3d1a3aad6e72d4 100644 (file)
             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);
 
 
 
-    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) {
             }
 
         } 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) {
             }
         }
 
-        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;
+        }
     }
 
 
 
 
 
-    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);
index f2a93d36a6f5992c4094c8a3f912318d54a8f1eb..30d53ca1037777e3a398f48f03bc826be3952a69 100644 (file)
@@ -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,
index 13b8297d2a6a68e202c40468b13af93da3c6c9bc..89f8035830ffc99d8d17c503eb5b18f0a33c033e 100755 (executable)
@@ -236,7 +236,8 @@ function onNotice(event) {
        irc_event: event\r
     })\r
     .done(function() {\r
-        that.irc_connection.clientEvent('notice', {\r
+        that.irc_connection.clientEvent('message', {\r
+            type: 'notice',\r
             from_server: event.from_server,\r
             nick: event.nick,\r
             ident: event.ident,\r
@@ -267,7 +268,8 @@ function onPrivmsg(event) {
         irc_event: event\r
     })\r
     .done(function() {\r
-        that.irc_connection.clientEvent('msg', {\r
+        that.irc_connection.clientEvent('message', {\r
+            type: 'message',\r
             nick: event.nick,\r
             ident: event.ident,\r
             hostname: event.hostname,\r
@@ -286,7 +288,8 @@ function onAction(event) {
         irc_event: event\r
     })\r
     .done(function() {\r
-        that.irc_connection.clientEvent('action', {\r
+        that.irc_connection.clientEvent('message', {\r
+            type: 'action',\r
             nick: event.nick,\r
             ident: event.ident,\r
             hostname: event.hostname,\r