message:new & message:display plugin hooks
authorDarren <darren@darrenwhitlen.com>
Fri, 27 Jun 2014 22:05:31 +0000 (23:05 +0100)
committerDarren <darren@darrenwhitlen.com>
Fri, 27 Jun 2014 22:05:31 +0000 (23:05 +0100)
client/src/models/network.js
client/src/views/channel.js

index b71ab57724caf9b6a8de34a6600ee678daa30191..9362a10d14237e6d5ee5b0572a3c7e8ef2b2cef4 100644 (file)
 
 
     function onMessage(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;
-        }
+        _kiwi.global.events.emit('message:new', {network: this, message: event})
+        .done(_.bind(function() {
+            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 (event.type == 'notice') {
-            if (event.from_server) {
-                panel = this.panels.server;
+            if (event.type == 'notice') {
+                if (event.from_server) {
+                    panel = this.panels.server;
 
-            } else {
-                panel = this.panels.getByName(event.target) || this.panels.getByName(event.nick);
+                } 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];
+                    // 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);
+                            panel = this.panels.getByName(channel_name);
+                        }
                     }
-                }
 
-            }
+                }
 
-            if (!panel) {
-                panel = this.panels.server;
-            }
+                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) {
-                panel = new _kiwi.model.Query({name: event.nick, network: this});
-                this.panels.add(panel);
-            }
+            } else 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.Query({name: event.nick, network: this});
+                    this.panels.add(panel);
+                }
 
-        } else {
-            // If a panel isn't found for this target, reroute to the
-            // server panel
-            panel = this.panels.getByName(event.target);
-            if (!panel) {
-                panel = this.panels.server;
+            } else {
+                // If a panel isn't found for this target, reroute to the
+                // server panel
+                panel = this.panels.getByName(event.target);
+                if (!panel) {
+                    panel = this.panels.server;
+                }
             }
-        }
 
-        switch (event.type){
-        case 'message':
-            panel.addMsg(event.nick, styleText('privmsg', {text: event.msg}), 'privmsg', {time: event.time});
-            break;
+            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 '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});
+            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;
+                // 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});
+                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;
             }
-            break;
-        }
+        }, this));
     }
 
 
index 5c83320ed24ee4c84391ea6317913ae894fe4a57..b38c66a8d8b10eec7a0e0e28d0d71a17010b5c68 100644 (file)
@@ -166,83 +166,87 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
                 msg.time_string = _kiwi.global.i18n.translate('client_views_panel_timestamp_am').fetch(hour + ":" + msg.time.getMinutes().toString().lpad(2, "0") + ":" + msg.time.getSeconds().toString().lpad(2, "0"));
             }
         }
-        line_msg = '<div class="msg <%= type %> <%= msg_css_classes %>"><div class="time"><%- time_string %></div><div class="nick" style="<%= nick_style %>"><%- nick %></div><div class="text" style="<%= style %>"><%= msg %> </div></div>';
-        this.$messages.append(_.template(line_msg, msg));
 
-        // Activity/alerts based on the type of new message
-        if (msg.type.match(/^action /)) {
-            this.alert('action');
+        _kiwi.global.events.emit('message:display', {panel: this.model, message: msg})
+        .done(_.bind(function() {
+            line_msg = '<div class="msg <%= type %> <%= msg_css_classes %>"><div class="time"><%- time_string %></div><div class="nick" style="<%= nick_style %>"><%- nick %></div><div class="text" style="<%= style %>"><%= msg %> </div></div>';
+            this.$messages.append(_.template(line_msg, msg));
 
-        } else if (is_highlight) {
-            _kiwi.app.view.alertWindow('* ' + _kiwi.global.i18n.translate('client_views_panel_activity').fetch());
-            _kiwi.app.view.favicon.newHighlight();
-            _kiwi.app.view.playSound('highlight');
-            _kiwi.app.view.showNotification(this.model.get('name'), msg.msg);
-            this.alert('highlight');
+            // Activity/alerts based on the type of new message
+            if (msg.type.match(/^action /)) {
+                this.alert('action');
 
-        } else {
-            // If this is the active panel, send an alert out
-            if (this.model.isActive()) {
+            } else if (is_highlight) {
                 _kiwi.app.view.alertWindow('* ' + _kiwi.global.i18n.translate('client_views_panel_activity').fetch());
+                _kiwi.app.view.favicon.newHighlight();
+                _kiwi.app.view.playSound('highlight');
+                _kiwi.app.view.showNotification(this.model.get('name'), msg.msg);
+                this.alert('highlight');
+
+            } else {
+                // If this is the active panel, send an alert out
+                if (this.model.isActive()) {
+                    _kiwi.app.view.alertWindow('* ' + _kiwi.global.i18n.translate('client_views_panel_activity').fetch());
+                }
+                this.alert('activity');
             }
-            this.alert('activity');
-        }
 
-        if (this.model.isQuery() && !this.model.isActive()) {
-            _kiwi.app.view.alertWindow('* ' + _kiwi.global.i18n.translate('client_views_panel_activity').fetch());
+            if (this.model.isQuery() && !this.model.isActive()) {
+                _kiwi.app.view.alertWindow('* ' + _kiwi.global.i18n.translate('client_views_panel_activity').fetch());
 
-            // Highlights have already been dealt with above
-            if (!is_highlight) {
-                _kiwi.app.view.favicon.newHighlight();
-            }
+                // Highlights have already been dealt with above
+                if (!is_highlight) {
+                    _kiwi.app.view.favicon.newHighlight();
+                }
 
-            _kiwi.app.view.showNotification(this.model.get('name'), msg.msg);
-            _kiwi.app.view.playSound('highlight');
-        }
+                _kiwi.app.view.showNotification(this.model.get('name'), msg.msg);
+                _kiwi.app.view.playSound('highlight');
+            }
 
-        // Update the activity counters
-        (function () {
-            // Only inrement the counters if we're not the active panel
-            if (this.model.isActive()) return;
+            // Update the activity counters
+            (function () {
+                // Only inrement the counters if we're not the active panel
+                if (this.model.isActive()) return;
 
-            var $act = this.model.tab.find('.activity'),
-                count_all_activity = _kiwi.global.settings.get('count_all_activity'),
-                exclude_message_types;
+                var $act = this.model.tab.find('.activity'),
+                    count_all_activity = _kiwi.global.settings.get('count_all_activity'),
+                    exclude_message_types;
 
-            // Set the default config value
-            if (typeof count_all_activity === 'undefined') {
-                count_all_activity = false;
-            }
+                // Set the default config value
+                if (typeof count_all_activity === 'undefined') {
+                    count_all_activity = false;
+                }
 
-            // Do not increment the counter for these message types
-            exclude_message_types = [
-                'action join',
-                'action quit',
-                'action part',
-                'action kick',
-                'action nick',
-                'action mode'
-            ];
-
-            if (count_all_activity || _.indexOf(exclude_message_types, msg.type) === -1) {
-                $act.text((parseInt($act.text(), 10) || 0) + 1);
-            }
+                // Do not increment the counter for these message types
+                exclude_message_types = [
+                    'action join',
+                    'action quit',
+                    'action part',
+                    'action kick',
+                    'action nick',
+                    'action mode'
+                ];
+
+                if (count_all_activity || _.indexOf(exclude_message_types, msg.type) === -1) {
+                    $act.text((parseInt($act.text(), 10) || 0) + 1);
+                }
 
-            if ($act.text() === '0') {
-                $act.addClass('zero');
-            } else {
-                $act.removeClass('zero');
-            }
-        }).apply(this);
+                if ($act.text() === '0') {
+                    $act.addClass('zero');
+                } else {
+                    $act.removeClass('zero');
+                }
+            }).apply(this);
 
-        if(this.model.isActive()) this.scrollToBottom();
+            if(this.model.isActive()) this.scrollToBottom();
 
-        // Make sure our DOM isn't getting too large (Acts as scrollback)
-        this.msg_count++;
-        if (this.msg_count > (parseInt(_kiwi.global.settings.get('scrollback'), 10) || 250)) {
-            $('.msg:first', this.$messages).remove();
-            this.msg_count--;
-        }
+            // Make sure our DOM isn't getting too large (Acts as scrollback)
+            this.msg_count++;
+            if (this.msg_count > (parseInt(_kiwi.global.settings.get('scrollback'), 10) || 250)) {
+                $('.msg:first', this.$messages).remove();
+                this.msg_count--;
+            }
+        }, this));
     },