SHA256
Исправить отображение веток комментариев
This commit is contained in:
@@ -1110,6 +1110,10 @@ function replyCountOf(node) {
|
||||
return Number(node?.totalReplies ?? node?.repliesCount ?? 0);
|
||||
}
|
||||
|
||||
function directReplyCountOf(node) {
|
||||
return Number(node?.repliesCount || 0);
|
||||
}
|
||||
|
||||
function nodeKey(node) {
|
||||
return messageRefKey(buildTargetFromNode(node));
|
||||
}
|
||||
@@ -1209,7 +1213,7 @@ function renderComment({ node, parent, focus, channelOwner, handlers, nested = f
|
||||
commentLikeStats.setAttribute('aria-label', t('screens.channel_thread_view.text_107', { value1: likes }));
|
||||
commentLikeStats.addEventListener('click', () => { void showLikeStatistics({ counts: node }); });
|
||||
|
||||
const replies = replyCountOf(node);
|
||||
const replies = directReplyCountOf(node);
|
||||
const reply = document.createElement('button');
|
||||
reply.type = 'button';
|
||||
reply.className = 'channel-action-item thread-comment__reply';
|
||||
@@ -1287,46 +1291,27 @@ function renderComment({ node, parent, focus, channelOwner, handlers, nested = f
|
||||
return item;
|
||||
}
|
||||
|
||||
// Сколько ответов внутри ветки видно сразу; остальные – по «Ещё N ответов».
|
||||
// Ветка прямого ответа: сам комментарий и не более одного вложенного уровня.
|
||||
// Ответы глубже открываются как отдельное обсуждение вложенного комментария.
|
||||
const THREAD_GROUP_VISIBLE_REPLIES = 2;
|
||||
|
||||
// Ветка ответа верхнего уровня: сам ответ и всё дерево под ним одной колонкой с линией, как в Threads.
|
||||
// Ответы глубже, чем отдал сервер, открываются отдельным обсуждением этого ответа.
|
||||
function renderReplyGroup(branch, { focus, channelOwner, handlers }) {
|
||||
const group = document.createElement('div');
|
||||
group.className = 'thread-group';
|
||||
group.append(renderComment({ node: branch.node, parent: focus, focus, channelOwner, handlers }));
|
||||
|
||||
const nested = [];
|
||||
const walk = (children, parent) => {
|
||||
(Array.isArray(children) ? children : []).forEach((child) => {
|
||||
if (!child?.node) return;
|
||||
nested.push({ node: child.node, parent, loaded: Array.isArray(child.children) ? child.children.length : 0 });
|
||||
walk(child.children, child.node);
|
||||
});
|
||||
};
|
||||
walk(branch.children, branch.node);
|
||||
const nested = (Array.isArray(branch.children) ? branch.children : [])
|
||||
.filter((child) => child?.node)
|
||||
.map((child) => ({ node: child.node, parent: branch.node }));
|
||||
if (!nested.length) return group;
|
||||
|
||||
group.classList.add('has-replies');
|
||||
const list = document.createElement('div');
|
||||
list.className = 'thread-replies';
|
||||
let previous = branch.node;
|
||||
nested.forEach(({ node, parent, loaded }, index) => {
|
||||
const comment = renderComment({ node, parent, focus, channelOwner, handlers, nested: true, mention: parent !== previous });
|
||||
nested.forEach(({ node, parent }, index) => {
|
||||
const comment = renderComment({ node, parent, focus, channelOwner, handlers, nested: true });
|
||||
if (index >= THREAD_GROUP_VISIBLE_REPLIES) comment.classList.add('is-collapsed');
|
||||
list.append(comment);
|
||||
const unloaded = Number(node?.repliesCount || 0) - loaded;
|
||||
if (unloaded > 0) {
|
||||
const deeper = document.createElement('button');
|
||||
deeper.type = 'button';
|
||||
deeper.className = 'thread-more thread-more--deeper';
|
||||
if (index >= THREAD_GROUP_VISIBLE_REPLIES) deeper.classList.add('is-collapsed');
|
||||
deeper.textContent = t('screens.channel_thread_view.text_110', { value1: unloaded });
|
||||
deeper.addEventListener('click', () => handlers.onOpenThread(buildTargetFromNode(node)));
|
||||
list.append(deeper);
|
||||
}
|
||||
previous = node;
|
||||
});
|
||||
const hidden = nested.length - THREAD_GROUP_VISIBLE_REPLIES;
|
||||
if (hidden > 0) {
|
||||
@@ -1352,7 +1337,6 @@ function pluralRu(n, one, few, many) {
|
||||
return many;
|
||||
}
|
||||
|
||||
|
||||
function renderDescendants(items, handlers, nextNumber, depth = 0, parent = null) {
|
||||
const wrap = document.createElement('div');
|
||||
wrap.className = 'stack';
|
||||
@@ -1427,8 +1411,8 @@ function setThreadMuted(key, muted) {
|
||||
try { localStorage.setItem(THREAD_MUTE_KEY, JSON.stringify(all)); } catch { /* приватный режим */ }
|
||||
}
|
||||
|
||||
// Глубина дерева ответов за один запрос; что глубже – открывается обсуждением конкретного ответа.
|
||||
const THREAD_LOAD_DEPTH = 8;
|
||||
// Фокус, его прямые ответы и один вложенный уровень для каждой ветки.
|
||||
const THREAD_LOAD_DEPTH = 2;
|
||||
|
||||
// Загрузка обсуждения без привязки к экрану: её же использует подгрузка заранее, по касанию записи.
|
||||
async function loadThreadData(sel, cacheKey, isCurrent) {
|
||||
|
||||
Reference in New Issue
Block a user