SHA256
Исправить отображение и учёт поддержки сообщений
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -3,27 +3,40 @@ import { formatStars } from './shine-support-amount.js';
|
||||
|
||||
// Один запрос на канал; только сервер проверяет привязку транзакции к блоку.
|
||||
const cache = new Map();
|
||||
const pending = new Map();
|
||||
export function loadVerifiedSupportTotals(selector) {
|
||||
const number = Number(selector?.channelRootBlockNumber);
|
||||
const hash = String(selector?.channelRootBlockHash || '').toLowerCase();
|
||||
if (!Number.isSafeInteger(number) || !/^[0-9a-f]{64}$/.test(hash)) return Promise.resolve(null);
|
||||
const key = `${number}:${hash}`;
|
||||
if (!cache.has(key)) {
|
||||
const promise = authService.getSupportTotals({ channelRootBlockNumber: number, channelRootBlockHash: hash })
|
||||
.then((response) => {
|
||||
const messages = new Map();
|
||||
for (const row of response?.messages || []) {
|
||||
const id = `${String(row.blockNumber)}:${String(row.blockHash).toLowerCase()}`;
|
||||
messages.set(id, String(row.receivedStarCents));
|
||||
}
|
||||
return { channelReceivedStarCents: String(response?.channelReceivedStarCents || '0'), messages };
|
||||
})
|
||||
.catch(() => { cache.delete(key); return null; });
|
||||
cache.set(key, promise);
|
||||
}
|
||||
if (pending.has(key)) return pending.get(key);
|
||||
if (!cache.has(key)) return refreshVerifiedSupportTotals(selector);
|
||||
return cache.get(key);
|
||||
}
|
||||
|
||||
export function refreshVerifiedSupportTotals(selector) {
|
||||
const number = Number(selector?.channelRootBlockNumber);
|
||||
const hash = String(selector?.channelRootBlockHash || '').toLowerCase();
|
||||
if (!Number.isSafeInteger(number) || !/^[0-9a-f]{64}$/.test(hash)) return Promise.resolve(null);
|
||||
const key = `${number}:${hash}`;
|
||||
if (pending.has(key)) return pending.get(key);
|
||||
const promise = authService.getSupportTotals({ channelRootBlockNumber: number, channelRootBlockHash: hash })
|
||||
.then((response) => {
|
||||
const messages = new Map();
|
||||
for (const row of response?.messages || []) {
|
||||
const id = `${String(row.blockNumber)}:${String(row.blockHash).toLowerCase()}`;
|
||||
messages.set(id, String(row.receivedStarCents));
|
||||
}
|
||||
const totals = { channelReceivedStarCents: String(response?.channelReceivedStarCents || '0'), messages };
|
||||
cache.set(key, totals);
|
||||
return totals;
|
||||
})
|
||||
.catch(() => null)
|
||||
.finally(() => pending.delete(key));
|
||||
pending.set(key, promise);
|
||||
return promise;
|
||||
}
|
||||
|
||||
export function formatVerifiedSupportStars(value) {
|
||||
try {
|
||||
const n = BigInt(value);
|
||||
|
||||
Reference in New Issue
Block a user