Исправить отображение и учёт поддержки сообщений

This commit is contained in:
AidarKC
2026-12-02 02:13:01 +03:00
parent 7cf0170de7
commit a9fa1cd2a2
11 changed files with 110 additions and 63 deletions
+5 -5
View File
@@ -1,5 +1,5 @@
import { openShineSupportDialog } from '../components/shine-support-dialog.js';
import { hexHash32 } from '../services/shine-support-amount.js';
import { formatStars, hexHash32 } from '../services/shine-support-amount.js';
import { formatDateTime } from '../i18n/format.js';
import { t, th } from '../i18n/index.js';
import { appendShineMessageLinks } from '../services/shine-message-links.js';
@@ -803,7 +803,7 @@ function renderNodeCard(node, heading, handlers, localNumber, { focusPost = fals
likeButton.className = 'ui-button channel-action-item channel-action-like thread-like-btn';
if (isLiked) likeButton.classList.add('is-liked');
likeButton.innerHTML = `
${handlers.viewerShining ? `<span class="channel-action-counter">${Number(node?.shiningLikesCount || 0)}</span>` : ''}
${handlers.viewerShining && Number(node?.shiningLikesCount || 0) > 0 ? `<span class="channel-action-counter">${Number(node.shiningLikesCount)}</span>` : ''}
<span class="channel-action-icon" aria-hidden="true">${iconHtml('heart', isLiked)}</span>
<span class="channel-action-label">${isPending ? t('screens.channel_thread_view.text_062') : t('screens.channel_thread_view.text_063')}</span>
`;
@@ -922,7 +922,7 @@ function renderNodeCard(node, heading, handlers, localNumber, { focusPost = fals
const supportBtn = document.createElement('button');
supportBtn.type = 'button';
supportBtn.className = 'ui-button channel-action-item channel-action-support';
supportBtn.textContent = '♥ SOL';
supportBtn.textContent = formatStars(node?.supportStarCents || '0');
supportBtn.title = t('screens.support_phase2.donate');
supportBtn.addEventListener('click', (event) => { event.stopPropagation(); handlers.onSupport?.(node, target); });
@@ -1170,7 +1170,7 @@ function renderComment({ node, parent, focus, channelOwner, handlers, nested = f
const like = document.createElement('button');
like.type = 'button';
like.className = `channel-action-item thread-comment__like${liked ? ' is-liked' : ''}`;
like.innerHTML = `${handlers.viewerShining ? `<span class="channel-action-counter">${Number(node?.shiningLikesCount || 0)}</span>` : ''}${iconHtml('heart', liked)}`;
like.innerHTML = `${handlers.viewerShining && Number(node?.shiningLikesCount || 0) > 0 ? `<span class="channel-action-counter">${Number(node.shiningLikesCount)}</span>` : ''}${iconHtml('heart', liked)}`;
like.setAttribute('aria-pressed', String(liked));
like.setAttribute('aria-label', `${liked ? t('dialogs.modals.channel_thread_view.label_026') : t('screens.channel_thread_view.text_067')}, ${likes}`);
like.addEventListener('click', async () => {
@@ -1248,7 +1248,7 @@ function renderComment({ node, parent, focus, channelOwner, handlers, nested = f
const supportBtn = document.createElement('button');
supportBtn.type = 'button';
supportBtn.className = 'channel-action-item thread-comment__support';
supportBtn.textContent = '♥ SOL';
supportBtn.textContent = formatStars(node?.supportStarCents || '0');
supportBtn.title = t('screens.support_phase2.donate');
supportBtn.addEventListener('click', (event) => { event.stopPropagation(); handlers.onSupport?.(node, target); });
actions.append(supportBtn);
+5 -11
View File
@@ -1,6 +1,6 @@
import { openShineSupportDialog } from '../components/shine-support-dialog.js';
import { hexHash32 } from '../services/shine-support-amount.js';
import { loadVerifiedSupportTotals, formatVerifiedSupportStars } from '../services/support-totals-service.js';
import { formatVerifiedSupportStars } from '../services/support-totals-service.js';
import { formatDateTime, getIntlLocale } from '../i18n/format.js';
import { t, th } from '../i18n/index.js';
import { appendShineMessageLinks } from '../services/shine-message-links.js';
@@ -1260,6 +1260,7 @@ function mapApiMessageToPost(message, selector, localNumber) {
likesCount: Number(message?.likesCount || 0),
primaryLikesCount: Number(message?.primaryLikesCount || 0),
shiningLikesCount: Number(message?.shiningLikesCount || 0),
supportStarCents: String(message?.supportStarCents || '0'),
repliesCount: Number(message?.repliesCount || 0),
// Кто недавно ответил — для миниатюр у счётчика обсуждения. Сервер пока не отдаёт (см. docs/UI-Design).
recentRepliers: Array.isArray(message?.recentRepliers) ? message.recentRepliers.slice(0, 2) : [],
@@ -1999,7 +2000,7 @@ function renderPostCard(post, {
const isLiked = post.reactionState === 'liked';
if (isLiked) likeButton.classList.add('is-liked');
likeButton.innerHTML = `
${viewerShining ? `<span class="channel-action-counter">${Number(post.shiningLikesCount || 0)}</span>` : ''}
${viewerShining && Number(post.shiningLikesCount || 0) > 0 ? `<span class="channel-action-counter">${Number(post.shiningLikesCount)}</span>` : ''}
<span class="channel-action-icon" aria-hidden="true">${iconHtml('heart', isLiked)}</span>
<span class="channel-action-label">${isPending ? t('screens.channel_view.text_096') : t('screens.channel_view.text_097')}</span>
`;
@@ -2145,15 +2146,8 @@ function renderPostCard(post, {
supportButton.className = 'ui-button channel-action-item channel-action-support';
supportButton.textContent = '⭐';
supportButton.title = t('screens.support_phase2.donate');
// Проверенные сервером суммы; если индексатор не готов, число не показываем.
if (post.messageRef?.blockNumber != null && post.messageRef?.blockHash) {
const messageId = `${String(post.messageRef.blockNumber)}:${String(post.messageRef.blockHash).toLowerCase()}`;
void loadVerifiedSupportTotals(selector).then((totals) => {
if (!totals || !supportButton.isConnected) return;
const formatted = formatVerifiedSupportStars(totals.messages.get(messageId));
if (formatted) supportButton.textContent = formatted;
});
}
const supportCount = formatVerifiedSupportStars(post.supportStarCents);
if (supportCount) supportButton.textContent = supportCount;
supportButton.addEventListener('click', (event) => {
event.stopPropagation();