From 19c408ba13cd3da965b8d013134dc65087c366ba Mon Sep 17 00:00:00 2001 From: Patrick Melanson Date: Thu, 7 Jan 2016 18:03:48 -0500 Subject: [PATCH 1/2] #705 bugfix datechange injected under read marker after #708 was merged, if a date change message is injected underneath the read marker the read marker would be one line too low. Now, the read marker will adjust properly when a date change message is injected above and below the read marker. thanks lorenzhs for spotting that --- js/handlers.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/handlers.js b/js/handlers.js index 0b3ea2f..ceab76e 100644 --- a/js/handlers.js +++ b/js/handlers.js @@ -50,7 +50,11 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific new_date.setHours(0, 0, 0, 0); // Check if the date changed if (old_date.valueOf() !== new_date.valueOf()) { - ++buffer.lastSeen; + if (buffer.lastSeen + 1 < buffer.lines.length) { + // if the date change should be injected below the read marker, + // adjust the read marker up to make sure it stays under the read marker + ++buffer.lastSeen; + } var old_date_plus_one = old_date; old_date_plus_one.setDate(old_date.getDate() + 1); // it's not always true that a date with time 00:00:00 From a06f567770ca2c97ef85ae42f9b16d785a56fd02 Mon Sep 17 00:00:00 2001 From: Patrick Melanson Date: Sat, 9 Jan 2016 00:39:33 -0500 Subject: [PATCH 2/2] #705 date change msg now moves read marker only if accompanying msg would --- js/handlers.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/js/handlers.js b/js/handlers.js index ceab76e..c1b3228 100644 --- a/js/handlers.js +++ b/js/handlers.js @@ -41,7 +41,7 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific }; // inject a fake buffer line for date change if needed - var injectDateChangeMessageIfNeeded = function(buffer, old_date, new_date) { + var injectDateChangeMessageIfNeeded = function(buffer, manually, old_date, new_date) { if (buffer.bufferType === 1) { // Don't add date change messages to free buffers return; @@ -50,9 +50,10 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific new_date.setHours(0, 0, 0, 0); // Check if the date changed if (old_date.valueOf() !== new_date.valueOf()) { - if (buffer.lastSeen + 1 < buffer.lines.length) { - // if the date change should be injected below the read marker, - // adjust the read marker up to make sure it stays under the read marker + if (manually) { + // if the message that caused this date change to be sent + // would increment buffer.lastSeen, we should increment as + // well. ++buffer.lastSeen; } var old_date_plus_one = old_date; @@ -145,7 +146,7 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific if (buffer.lines.length > 0) { var old_date = new Date(buffer.lines[buffer.lines.length - 1].date), new_date = new Date(message.date); - injectDateChangeMessageIfNeeded(buffer, old_date, new_date); + injectDateChangeMessageIfNeeded(buffer, manually, old_date, new_date); } message = plugins.PluginManager.contentForMessage(message); @@ -330,7 +331,7 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific var buffer = models.getBuffer(last_line.buffer); if (buffer.lines.length > 0) { var last_date = new Date(buffer.lines[buffer.lines.length - 1].date); - injectDateChangeMessageIfNeeded(buffer, last_date, new Date()); + injectDateChangeMessageIfNeeded(buffer, true, last_date, new Date()); } } };