Merge pull request #1485 from thelounge/xpaw/always-condense
Always create condensed wrapper
This commit is contained in:
commit
43c8f6fd96
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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">
|
||||
<span class="date-marker-text" data-label="{{friendlydate msgDate}}"></span>
|
||||
<span class="date-marker-text" data-label="{{friendlydate time}}"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user