From 0a1726e359792deb93d3e787642f46b0af5943de Mon Sep 17 00:00:00 2001 From: Patrick Melanson Date: Fri, 20 Nov 2015 17:52:39 -0500 Subject: [PATCH] date change messages are chat_day_change color, multiple messages generated for diff of 1-5 days --- js/handlers.js | 24 ++++++++++++++++++++---- js/weechat.js | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/js/handlers.js b/js/handlers.js index 25ba797..be66ea3 100644 --- a/js/handlers.js +++ b/js/handlers.js @@ -21,11 +21,11 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific // inject a fake buffer line for date change var injectDateChangeMessage = function(message, buffer, date) { - var content = "Date changed to " + date.toDateString(); + var content = "\u001943Date changed to " + date.toDateString(); var line = { buffer: buffer, date: date, - prefix: '—', + prefix: '\u001943\u2500\u2500', tags_array: [], displayed: true, highlight: 0, @@ -47,8 +47,24 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific current_date = new Date(message.date); previous_date.setHours(0, 0, 0, 0); current_date.setHours(0, 0, 0, 0); - if (previous_date.valueOf() !== current_date.valueOf()) { - injectDateChangeMessage(message, buffer, current_date); + var dateDifference = + Math.round((current_date - previous_date)/(24*60*60*1000)); + if (dateDifference !== 0) { + console.log(dateDifference); + // if it's a small, positive number display a message + // for each one. Otherwise, just display one big + // date change message + // The range [1,5] was chosen arbitrarily + if (dateDifference >= 1 && dateDifference <= 5) { + var prev_date_clone = previous_date; + for (var i = 1; i <= dateDifference; ++i) { + prev_date_clone.setDate(prev_date_clone.getDate()+1); + injectDateChangeMessage(message, buffer, + prev_date_clone); + } + } else { + injectDateChangeMessage(message, buffer, current_date); + } } } diff --git a/js/weechat.js b/js/weechat.js index 126eda6..4a6d4f0 100644 --- a/js/weechat.js +++ b/js/weechat.js @@ -290,7 +290,7 @@ var ret = {}; var optionCode = parseInt(m[1]); - if (optionCode > 43) { + if (optionCode >= WeeChatProtocol._colorsOptionsNames.length) { // should never happen return { fgColor: null,