SHA256
Добавить текстовые ссылки SHiNE
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { mountPublicChannelSidebar } from '../services/public-channel-sidebar.js';
|
||||
import { appendShineMessageLinks } from '../services/shine-message-links.js';
|
||||
import { confirmDialog } from '../components/confirm-dialog.js';
|
||||
import { iconHtml } from '../components/ui-icon.js';
|
||||
import { rememberChannelPosition, readChannelPosition, restoreChannelPosition } from '../services/channel-view-state.js';
|
||||
@@ -47,6 +47,7 @@ import {
|
||||
makeShineChannelDonateRoute,
|
||||
} from '../services/shine-routes.js';
|
||||
import { parseDmTechBlocks } from '../services/dm-tech-blocks.js';
|
||||
import { sortedChannelPublications } from '../services/channel-message-ordinals.js';
|
||||
|
||||
export const pageMeta = { id: 'channel-view', title: 'Канал', hideToolbar: true, shellMode: { scrollbar: 'hidden', topFade: false, contentUnderTopbar: false, contentWidth: 'wide' } };
|
||||
const CHANNEL_TYPE_STORIES = 0;
|
||||
@@ -238,14 +239,16 @@ function buildSelectorFromRoute(route, channelId) {
|
||||
};
|
||||
}
|
||||
|
||||
function buildThreadRoute(messageRef, selector) {
|
||||
function buildThreadRoute(post, selector) {
|
||||
const messageRef = post?.messageRef;
|
||||
if (!messageRef || !selector) return '';
|
||||
const ownerLogin = extractLoginFromBlockchainName(selector.ownerBlockchainName);
|
||||
return makeShineMessageRoute({
|
||||
ownerLogin,
|
||||
messageBlockchainName: messageRef.blockchainName,
|
||||
messageBlockNumber: messageRef.blockNumber,
|
||||
channelName: selector.channelName,
|
||||
messageOrdinal: selector.publicOrdinalUrlsAllowed ? post.localNumber : '',
|
||||
channelName: selector.publicOrdinalUrlsAllowed ? selector.channelName : '',
|
||||
channelOwnerBlockchainName: selector.ownerBlockchainName,
|
||||
});
|
||||
}
|
||||
@@ -1487,6 +1490,9 @@ async function loadFromApi(route, channelId) {
|
||||
const ownerLogin = String(payload.channel?.ownerLogin || '').trim();
|
||||
const channelName = String(payload.channel?.channelName || '').trim();
|
||||
const channelTypeCode = Number(payload.channel?.channelTypeCode ?? 1);
|
||||
// Channel-publication URLs are only unambiguous for public channels, not merged private chats.
|
||||
selector.channelName = String(payload.channel?.channelName || selector.channelName || '').trim();
|
||||
selector.publicOrdinalUrlsAllowed = channelTypeCode !== CHANNEL_TYPE_STORIES && channelTypeCode !== CHANNEL_TYPE_PERSONAL;
|
||||
if (channelTypeCode === CHANNEL_TYPE_STORIES) {
|
||||
throw new Error('Канал stories скрыт из пользовательского интерфейса.');
|
||||
}
|
||||
@@ -1520,16 +1526,9 @@ async function loadFromApi(route, channelId) {
|
||||
}
|
||||
}
|
||||
|
||||
const posts = mergedMessages
|
||||
.map((message, index) => mapApiMessageToPost(message, selector, index + 1))
|
||||
.sort((a, b) => {
|
||||
const byTime = Number(a?.timestampMs || 0) - Number(b?.timestampMs || 0);
|
||||
if (byTime !== 0) return byTime;
|
||||
const aNum = Number(a?.messageRef?.blockNumber || 0);
|
||||
const bNum = Number(b?.messageRef?.blockNumber || 0);
|
||||
return aNum - bNum;
|
||||
})
|
||||
.map((post, index) => ({ ...post, localNumber: index + 1 }));
|
||||
const posts = sortedChannelPublications(
|
||||
mergedMessages.map((message, index) => mapApiMessageToPost(message, selector, index + 1)),
|
||||
).map((post, index) => ({ ...post, localNumber: index + 1 }));
|
||||
const isOwnChannel = ownerLogin.toLowerCase() === currentSessionLogin.toLowerCase();
|
||||
const followedRows = Array.isArray(state.channelsFeed?.followedChannels) ? state.channelsFeed.followedChannels : [];
|
||||
const isSubscribed = isAuthorized && followedRows.some((row) => (
|
||||
@@ -2028,7 +2027,7 @@ function renderPostCard(post, {
|
||||
}
|
||||
const body = document.createElement('p');
|
||||
body.className = 'channel-message-body';
|
||||
body.textContent = parsedBody.text;
|
||||
appendShineMessageLinks(body, parsedBody.text, { navigate, viewMode: 'feed' });
|
||||
card.append(body);
|
||||
}
|
||||
|
||||
@@ -2093,7 +2092,7 @@ function renderPostCard(post, {
|
||||
setActionTitle(discussionButton, `Открыть обсуждение, ответов: ${post.repliesCount || 0}`);
|
||||
discussionButton.addEventListener('click', (event) => {
|
||||
event.stopPropagation();
|
||||
const route = buildThreadRoute(post.messageRef, selector);
|
||||
const route = buildThreadRoute(post, selector);
|
||||
if (route) navigate(route);
|
||||
});
|
||||
|
||||
@@ -2134,17 +2133,17 @@ function renderPostCard(post, {
|
||||
shareButton.addEventListener('click', async (event) => {
|
||||
event.stopPropagation();
|
||||
animatePress(event.currentTarget);
|
||||
const route = buildThreadRoute(post.messageRef, selector);
|
||||
const route = buildThreadRoute(post, selector);
|
||||
await onShare(route);
|
||||
});
|
||||
|
||||
// Порядок как в макете V4: лайк → поделиться → обсуждение; дата и «⋯» — справа
|
||||
actions.append(likeButton, shareButton, discussionButton);
|
||||
if (post.messageRef?.blockNumber != null) {
|
||||
if (selector?.publicOrdinalUrlsAllowed && post.messageRef?.blockNumber != null) {
|
||||
const streamRoute = makeShineChannelStreamRoute({
|
||||
ownerBlockchainName: selector?.ownerBlockchainName,
|
||||
channelName: selector?.channelName || '',
|
||||
messageBlockNumber: post.messageRef.blockNumber,
|
||||
messageOrdinal: post.localNumber,
|
||||
});
|
||||
if (streamRoute) menuItems.unshift({ label: 'Ссылка на сообщение в ленте', iconHtml: iconHtml('share'), action: () => onShare(streamRoute) });
|
||||
}
|
||||
@@ -2264,7 +2263,7 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
||||
const actionButton = document.createElement('button');
|
||||
actionButton.type = 'button';
|
||||
actionButton.className = 'primary-btn channel-main-action';
|
||||
actionButton.innerHTML = `${iconHtml('bell')}<span>${state.session.isAuthorized ? 'Подписаться' : 'Войти и подписаться'}</span>`;
|
||||
actionButton.innerHTML = `${iconHtml('bell')}<span>${state.session.isAuthorized ? 'Подписаться' : 'Войти / зарегистрироваться'}</span>`;
|
||||
|
||||
const addMessageButton = document.createElement('button');
|
||||
addMessageButton.type = 'button';
|
||||
@@ -2380,13 +2379,12 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
||||
screen.append(feed);
|
||||
}
|
||||
|
||||
const requestedBlock = String(handlers.scrollToMessageBlockNumber || '').trim();
|
||||
if (/^[0-9]+$/.test(requestedBlock)) {
|
||||
const card = [...screen.querySelectorAll('.channel-message-card[data-message-key]')].find((el) => {
|
||||
const parts = String(el.dataset.messageKey || '').split(':');
|
||||
return parts.length >= 3 && parts[parts.length - 2] === requestedBlock;
|
||||
});
|
||||
const requestedOrdinal = Number(handlers.scrollToMessageOrdinal);
|
||||
if (Number.isSafeInteger(requestedOrdinal) && requestedOrdinal > 0) {
|
||||
const card = [...screen.querySelectorAll('.channel-message-card[data-local-number]')]
|
||||
.find((el) => Number(el.dataset.localNumber) === requestedOrdinal);
|
||||
if (card) pendingScrollByRoute.set(routeKey, card.dataset.messageKey);
|
||||
else showStatus(`Публикация №${requestedOrdinal} не найдена в канале.`);
|
||||
}
|
||||
const hasPendingScrollTarget = pendingScrollByRoute.has(routeKey);
|
||||
const restorePosition = handlers.restorePosition;
|
||||
@@ -2462,7 +2460,7 @@ function renderSkeleton(screen) {
|
||||
|
||||
export function render({ navigate, route, chrome }) {
|
||||
const channelId = route.params.channelId || '';
|
||||
const scrollToMessageBlockNumber = route.params.scrollToMessageBlockNumber || '';
|
||||
const scrollToMessageOrdinal = route.params.scrollToMessageOrdinal || '';
|
||||
const routeSelector = buildSelectorFromRoute(route, channelId);
|
||||
const routeKey = `${routeSelector?.ownerBlockchainName || ''}:${routeSelector?.channelRootBlockNumber || ''}:${routeSelector?.channelRootBlockHash || ''}`;
|
||||
|
||||
@@ -2507,7 +2505,7 @@ export function render({ navigate, route, chrome }) {
|
||||
|
||||
const header = createTopBar({
|
||||
center: channelHeaderButton,
|
||||
back: { onClick: () => navigate('channels-list') },
|
||||
back: state.session.isAuthorized ? { onClick: () => navigate('channels-list') } : null,
|
||||
className: 'channel-view-topbar topbar--identity',
|
||||
actions: [
|
||||
{
|
||||
@@ -2958,9 +2956,9 @@ export function render({ navigate, route, chrome }) {
|
||||
};
|
||||
activeOpenEntrypointHistory = openEntrypointHistory;
|
||||
if (channelHeaderButton) {
|
||||
// Короткий адрес канала и число подписчиков; владелец и полный путь — в «О канале»
|
||||
// Под названием показываем владельца и короткое название, одинаково для ленты и /s/<номер>.
|
||||
const slug = String(apiData?.channel?.name || '').trim();
|
||||
const subs = Number(apiData?.channel?.subscribersCount || 0);
|
||||
const owner = String(apiData?.channel?.ownerName || extractLoginFromBlockchainName(apiData?.selector?.ownerBlockchainName) || '').trim();
|
||||
channelHeaderButton.replaceChildren();
|
||||
const text = document.createElement('span');
|
||||
text.className = 'topbar-identity__text';
|
||||
@@ -2969,7 +2967,7 @@ export function render({ navigate, route, chrome }) {
|
||||
titleNode.textContent = titleLabel;
|
||||
const subNode = document.createElement('span');
|
||||
subNode.className = 'topbar-identity__sub';
|
||||
subNode.textContent = apiData?.isDiary ? 'Только вам' : [slug ? `@${slug}` : '', subs ? String(subs) : ''].filter(Boolean).join(' · ');
|
||||
subNode.textContent = apiData?.isDiary ? 'Только вам' : `${owner ? `@${owner}` : ''}${owner && slug ? ' / ' : ''}${slug}`;
|
||||
text.append(titleNode, subNode);
|
||||
channelHeaderButton.append(createChannelAvatarElement(apiData?.channel, 40), text);
|
||||
channelHeaderButton.setAttribute('aria-label', `${titleLabel}. О канале`);
|
||||
@@ -3005,7 +3003,7 @@ export function render({ navigate, route, chrome }) {
|
||||
cleanupSeenTracking = renderBody(screen, navigate, routeKey, apiData, {
|
||||
chrome,
|
||||
restorePosition,
|
||||
scrollToMessageBlockNumber,
|
||||
scrollToMessageOrdinal,
|
||||
showStatus,
|
||||
isActive: () => !disposed,
|
||||
onAddMessage: activeAddMessage = async () => {
|
||||
@@ -3096,10 +3094,6 @@ export function render({ navigate, route, chrome }) {
|
||||
},
|
||||
onSubscribeChannel: (event) => subscribeToChannel(apiData, event),
|
||||
});
|
||||
if (!state.session.isAuthorized && !apiData?.isDiary) mountPublicChannelSidebar(screen, {
|
||||
owner: apiData?.channel?.ownerName || extractLoginFromBlockchainName(apiData?.selector?.ownerBlockchainName),
|
||||
channel: titleLabel, subscribers: apiData?.channel?.subscribersCount, navigate,
|
||||
});
|
||||
} catch (error) {
|
||||
if (disposed || seq !== refreshSeq) return;
|
||||
skeleton?.remove();
|
||||
|
||||
Reference in New Issue
Block a user