diff --git a/client/js/lounge.js b/client/js/lounge.js index bd0da92d..4e7590b4 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -789,7 +789,7 @@ $(function() { $(".date-marker-text[data-label='Today'], .date-marker-text[data-label='Yesterday']") .closest(".date-marker-container") .each(function() { - $(this).replaceWith(templates.date_marker({msgDate: $(this).data("timestamp")})); + $(this).replaceWith(templates.date_marker({time: $(this).data("time")})); }); // This should always be 24h later but re-computing exact value just in case diff --git a/client/js/render.js b/client/js/render.js index 748ef771..bb6c4138 100644 --- a/client/js/render.js +++ b/client/js/render.js @@ -35,37 +35,17 @@ function buildChannelMessages(chanId, chanType, messages) { } function appendMessage(container, chanId, chanType, msg) { + let lastChild = container.children(".msg, .date-marker-container").last(); const renderedMessage = buildChatMessage(chanId, msg); // Check if date changed - let lastChild = container.find(".msg").last(); const msgTime = new Date(msg.time); - - // It's the first message in a window, - // then just append the message and do nothing else - if (lastChild.length === 0) { - container - .append(templates.date_marker({msgDate: msgTime})) - .append(renderedMessage); - - return; - } - - const prevMsgTime = new Date(lastChild.attr("data-time")); - const parent = lastChild.parent(); - - // If this message is condensed, we have to work on the wrapper - if (parent.hasClass("condensed")) { - lastChild = parent; - } + const prevMsgTime = new Date(lastChild.data("time")); // Insert date marker if date changed compared to previous message if (prevMsgTime.toDateString() !== msgTime.toDateString()) { - lastChild.after(templates.date_marker({msgDate: msgTime})); - - // If date changed, we don't need to do condensed logic - container.append(renderedMessage); - return; + lastChild = $(templates.date_marker({msgDate: msg.time})); + container.append(lastChild); } // If current window is not a channel or this message is not condensable, @@ -83,6 +63,7 @@ function appendMessage(container, chanId, chanType, msg) { return; } + // Always create a condensed container const newCondensed = buildChatMessage(chanId, { type: "condensed", time: msg.time, diff --git a/client/views/date-marker.tpl b/client/views/date-marker.tpl index 9e67f09f..b1d20be7 100644 --- a/client/views/date-marker.tpl +++ b/client/views/date-marker.tpl @@ -1,5 +1,5 @@ -
+
- +