From 3c4887776ecacb4cf6cb6e1fd61223aecbdc3ea0 Mon Sep 17 00:00:00 2001 From: Vlad Chernushevich Date: Fri, 21 Jun 2013 00:30:07 +0200 Subject: [PATCH] Show nick if time difference between messages is 1min+ --- client/assets/src/models/panel.js | 4 ++-- client/assets/src/views/panel.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/client/assets/src/models/panel.js b/client/assets/src/models/panel.js index 2efbe5a..fe41308 100644 --- a/client/assets/src/models/panel.js +++ b/client/assets/src/models/panel.js @@ -16,7 +16,7 @@ _kiwi.model.Panel = Backbone.Model.extend({ // Time defaults to now if (!opts || typeof opts.time === 'undefined') { - d = new Date(); + d = opts.date = new Date(); opts.time = d.getHours().toString().lpad(2, "0") + ":" + d.getMinutes().toString().lpad(2, "0") + ":" + d.getSeconds().toString().lpad(2, "0"); } @@ -26,7 +26,7 @@ _kiwi.model.Panel = Backbone.Model.extend({ } // Run through the plugins - message_obj = {"msg": msg, "time": opts.time, "nick": nick, "chan": this.get("name"), "type": type, "style": opts.style}; + message_obj = {"msg": msg, "date": opts.date, "time": opts.time, "nick": nick, "chan": this.get("name"), "type": type, "style": opts.style}; //tmp = _kiwi.plugs.run('addmsg', message_obj); if (!message_obj) { return; diff --git a/client/assets/src/views/panel.js b/client/assets/src/views/panel.js index 5d0644f..af8d171 100644 --- a/client/assets/src/views/panel.js +++ b/client/assets/src/views/panel.js @@ -44,8 +44,9 @@ _kiwi.view.Panel = Backbone.View.extend({ }, newMsg: function (msg) { - var template_vars, re, line_msg, $this = this.$el, + var re, line_msg, $this = this.$el, nick_colour_hex, nick_hex, is_highlight, msg_css_classes = '', + template_vars, time_difference, sb = this.model.get('scrollback'), prev_msg = sb[sb.length-2]; @@ -115,8 +116,12 @@ _kiwi.view.Panel = Backbone.View.extend({ } template_vars = _.clone(msg); - if (prev_msg && prev_msg.nick === template_vars.nick) { - template_vars.nick = ''; + + if (prev_msg) { + time_difference = (template_vars.date.getTime() - prev_msg.date.getTime())/1000/60; + if (prev_msg.nick === template_vars.nick && time_difference < 1) { + template_vars.nick = ''; + } } // Build up and add the line -- 2.25.1