Merge pull request #1485 from thelounge/xpaw/always-condense

Always create condensed wrapper
This commit is contained in:
Pavel Djundik 2017-09-03 11:26:31 +03:00 committed by GitHub
commit 43c8f6fd96
3 changed files with 8 additions and 27 deletions

View File

@ -789,7 +789,7 @@ $(function() {
$(".date-marker-text[data-label='Today'], .date-marker-text[data-label='Yesterday']") $(".date-marker-text[data-label='Today'], .date-marker-text[data-label='Yesterday']")
.closest(".date-marker-container") .closest(".date-marker-container")
.each(function() { .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 // This should always be 24h later but re-computing exact value just in case

View File

@ -35,37 +35,17 @@ function buildChannelMessages(chanId, chanType, messages) {
} }
function appendMessage(container, chanId, chanType, msg) { function appendMessage(container, chanId, chanType, msg) {
let lastChild = container.children(".msg, .date-marker-container").last();
const renderedMessage = buildChatMessage(chanId, msg); const renderedMessage = buildChatMessage(chanId, msg);
// Check if date changed // Check if date changed
let lastChild = container.find(".msg").last();
const msgTime = new Date(msg.time); const msgTime = new Date(msg.time);
const prevMsgTime = new Date(lastChild.data("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;
}
// Insert date marker if date changed compared to previous message // Insert date marker if date changed compared to previous message
if (prevMsgTime.toDateString() !== msgTime.toDateString()) { if (prevMsgTime.toDateString() !== msgTime.toDateString()) {
lastChild.after(templates.date_marker({msgDate: msgTime})); lastChild = $(templates.date_marker({msgDate: msg.time}));
container.append(lastChild);
// If date changed, we don't need to do condensed logic
container.append(renderedMessage);
return;
} }
// If current window is not a channel or this message is not condensable, // If current window is not a channel or this message is not condensable,
@ -83,6 +63,7 @@ function appendMessage(container, chanId, chanType, msg) {
return; return;
} }
// Always create a condensed container
const newCondensed = buildChatMessage(chanId, { const newCondensed = buildChatMessage(chanId, {
type: "condensed", type: "condensed",
time: msg.time, time: msg.time,

View File

@ -1,5 +1,5 @@
<div class="date-marker-container tooltipped tooltipped-s" data-timestamp="{{msgDate}}" aria-label="{{localedate msgDate}}"> <div class="date-marker-container tooltipped tooltipped-s" data-time="{{time}}" aria-label="{{localedate time}}">
<div class="date-marker"> <div class="date-marker">
<span class="date-marker-text" data-label="{{friendlydate msgDate}}"></span> <span class="date-marker-text" data-label="{{friendlydate time}}"></span>
</div> </div>
</div> </div>