Files
Joffrey JAFFEUXandGitHub 5cf34ee9c7 FEATURE: implements dates separators for threads (#25335)
This commit creates a shared implementation of the dates computation and moves all the logic (new messages since last visit and dates separator into one single component <ChatMessageSeparator />).

The frontend tests have been removed and only a single system spec has been added for threads as everything is sharing the same implementation and the existing channel specs should catch any regression.
2024-01-19 16:21:48 +01:00

47 lines
1.3 KiB
JavaScript

import { schedule } from "@ember/runloop";
export default class DatesSeparatorsPositioner {
static apply(list) {
schedule("afterRender", () => {
const dates = [
...list.querySelectorAll(".chat-message-separator-date"),
].reverse();
const height = list.querySelector(
".chat-messages-container"
).clientHeight;
dates
.map((date, index) => {
const item = { bottom: 0, date };
const line = date.nextElementSibling;
if (index > 0) {
const prevDate = dates[index - 1];
const prevLine = prevDate.nextElementSibling;
item.bottom = height - prevLine.offsetTop;
}
if (dates.length === 1) {
item.height = height;
} else {
if (index === 0) {
item.height = height - line.offsetTop;
} else {
const prevDate = dates[index - 1];
const prevLine = prevDate.nextElementSibling;
item.height =
height - line.offsetTop - (height - prevLine.offsetTop);
}
}
return item;
})
// group all writes at the end
.forEach((item) => {
item.date.style.bottom = item.bottom + "px";
item.date.style.height = item.height + "px";
});
});
}
}