From 9a808b58e95c6c05c89a68e2d2867bccdf65ef95 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 17 Jun 2018 11:46:31 +0300 Subject: [PATCH] Do not remove date marker when loading history if date changes Fixes #2566 --- client/js/socket-events/more.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/client/js/socket-events/more.js b/client/js/socket-events/more.js index 220f8a3f..1fcfd976 100644 --- a/client/js/socket-events/more.js +++ b/client/js/socket-events/more.js @@ -21,17 +21,24 @@ socket.on("more", function(data) { return; } - // Remove the date-change marker we put at the top, because it may - // not actually be a date change now + // Remove the date marker at the top if date does not change const children = $(chan).children(); - if (children.eq(0).hasClass("date-marker-container")) { // Check top most child - children.eq(0).remove(); - } else if (children.eq(1).hasClass("date-marker-container")) { - // The unread-marker could be at index 0, which will cause the date-marker to become "stuck" - children.eq(1).remove(); - } else if (children.eq(0).hasClass("condensed") && children.eq(0).children(".date-marker-container").eq(0).hasClass("date-marker-container")) { - children.eq(0).children(".date-marker-container").eq(0).remove(); + // Check the top-most element and the one after because + // unread and date markers may switch positions + for (let i = 0; i <= 1; i++) { + const marker = children.eq(i); + + if (marker.hasClass("date-marker-container")) { + const msgTime = new Date(data.messages[data.messages.length - 1].time); + const prevMsgTime = new Date(marker.data("time")); + + if (prevMsgTime.toDateString() === msgTime.toDateString()) { + marker.remove(); + } + + break; + } } // Add the older messages