Always create condensed wrapper

This commit is contained in:
Pavel Djundik 2017-09-01 14:43:24 +03:00
parent 77e9cb65d5
commit 94d40256d9
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']")
.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

View file

@ -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,

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">
<span class="date-marker-text" data-label="{{friendlydate msgDate}}"></span>
<span class="date-marker-text" data-label="{{friendlydate time}}"></span>
</div>
</div>