From: Andrew Colden Date: Tue, 10 Sep 2013 18:23:48 +0000 (-0400) Subject: Merge branch 'pr/374' into notificationsMerge2 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3aecdb798a9b5e95383128ef3e26ed5e0621885e;p=KiwiIRC.git Merge branch 'pr/374' into notificationsMerge2 Conflicts: client/assets/src/views/panel.js --- 3aecdb798a9b5e95383128ef3e26ed5e0621885e diff --cc client/assets/src/translations/de-de.po index 2b0985b,705cd10..5776256 mode 100644,100755..100644 --- a/client/assets/src/translations/de-de.po +++ b/client/assets/src/translations/de-de.po diff --cc client/assets/src/views/channel.js index c041f02,106ede3..4f4012b --- a/client/assets/src/views/channel.js +++ b/client/assets/src/views/channel.js @@@ -37,148 -28,13 +37,149 @@@ _kiwi.view.Channel = _kiwi.view.Panel.e if (this.model.isChannel()) { this.$el.append('
' + _kiwi.global.i18n.translate('client_views_channel_joining').fetch() + '
'); } + + this.model.bind('msg', this.newMsg, this); + this.msg_count = 0; }, - // Override the existing newMsg() method to remove the joining channel loader - newMsg: function () { - return this.constructor.__super__.newMsg.apply(this, arguments); + + newMsg: function (msg) { + var re, line_msg, + nick_colour_hex, nick_hex, is_highlight, msg_css_classes = '', + time_difference, + sb = this.model.get('scrollback'), + prev_msg = sb[sb.length-2]; + + // Nick highlight detecting + if ((new RegExp('(^|\\W)(' + escapeRegex(_kiwi.app.connections.active_connection.get('nick')) + ')(\\W|$)', 'i')).test(msg.msg)) { + is_highlight = true; + msg_css_classes += ' highlight'; + } + + // Escape any HTML that may be in here + msg.msg = $('
').text(msg.msg).html(); + + // Make the channels clickable + re = new RegExp('(?:^|\\s)([' + escapeRegex(_kiwi.gateway.get('channel_prefix')) + '][^ ,\\007]+)', 'g'); + msg.msg = msg.msg.replace(re, function (match) { + return '' + match + ''; + }); + + + // Parse any links found + msg.msg = msg.msg.replace(/(([A-Za-z][A-Za-z0-9\-]*\:\/\/)|(www\.))([\w.\-]+)([a-zA-Z]{2,6})(:[0-9]+)?(\/[\w#!:.?$'()[\]*,;~+=&%@!\-\/]*)?/gi, function (url) { + var nice = url, + extra_html = ''; + + // Add the http if no protoocol was found + if (url.match(/^www\./)) { + url = 'http://' + url; + } + + // Shorten the displayed URL if it's going to be too long + if (nice.length > 100) { + nice = nice.substr(0, 100) + '...'; + } + + // Get any media HTML if supported + extra_html = _kiwi.view.MediaMessage.buildHtml(url); + + // Make the link clickable + return '' + nice + '' + extra_html; + }); + + + // Convert IRC formatting into HTML formatting + msg.msg = formatIRCMsg(msg.msg); + + + // Add some colours to the nick (Method based on IRSSIs nickcolor.pl) + nick_colour_hex = (function (nick) { + var nick_int = 0, rgb; + + _.map(nick.split(''), function (i) { nick_int += i.charCodeAt(0); }); + rgb = hsl2rgb(nick_int % 255, 70, 35); + rgb = rgb[2] | (rgb[1] << 8) | (rgb[0] << 16); + + return '#' + rgb.toString(16); + })(msg.nick); + + msg.nick_style = 'color:' + nick_colour_hex + ';'; + + // Generate a hex string from the nick to be used as a CSS class name + nick_hex = msg.nick_css_class = ''; + if (msg.nick) { + _.map(msg.nick.split(''), function (char) { + nick_hex += char.charCodeAt(0).toString(16); + }); + msg_css_classes += ' nick_' + nick_hex; + } + + if (prev_msg) { + // Time difference between this message and the last (in minutes) + time_difference = (msg.date.getTime() - prev_msg.date.getTime())/1000/60; + if (prev_msg.nick === msg.nick && time_difference < 1) { + msg_css_classes += ' repeated_nick'; + } + } + + // Build up and add the line + msg.msg_css_classes = msg_css_classes; + line_msg = '
<%- time %>
<%- nick %>
<%= msg %>
'; + this.$messages.append(_.template(line_msg, msg)); + + // Activity/alerts based on the type of new message + if (msg.type.match(/^action /)) { + this.alert('action'); + + } 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(msg.nick, 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'); + } + + if (this.model.isQuery() && !this.model.isActive()) { + _kiwi.app.view.alertWindow('* ' + _kiwi.global.i18n.translate('client_views_panel_activity').fetch()); + if (!is_highlight) { + _kiwi.app.view.favicon.newHighlight(); + } + _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; + + var $act = this.model.tab.find('.activity'); + $act.text((parseInt($act.text(), 10) || 0) + 1); + if ($act.text() === '0') { + $act.addClass('zero'); + } else { + $act.removeClass('zero'); + } + }).apply(this); + + 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--; + } }, + topic: function (topic) { if (typeof topic !== 'string' || !topic) { topic = this.model.get("topic");