Добавлен канал личных публикаций

This commit is contained in:
AidarKC
2026-11-28 01:18:53 +03:00
parent 7d3f5db206
commit d1ca64d1c1
28 changed files with 325 additions and 473 deletions
+35 -25
View File
@@ -519,8 +519,7 @@ function latestVersionText(versions) {
function isStoriesChannel(channel = null) {
const typeCode = Number(channel?.channelTypeCode ?? channel?.channel?.channelTypeCode ?? 1);
const name = String(channel?.channelName || channel?.channel?.channelName || '').trim().toLowerCase();
return typeCode === CHANNEL_TYPE_STORIES || name === 'stories';
return typeCode === CHANNEL_TYPE_STORIES;
}
function resolveMessageText(message) {
@@ -1085,12 +1084,11 @@ function openRepostModal({ navigate, channels = [], onSubmit, isActive = () => t
const root = document.getElementById('modal-root');
const options = (Array.isArray(channels) ? channels : [])
.filter((item) => item?.selector?.ownerBlockchainName && Number.isFinite(Number(item?.selector?.channelRootBlockNumber)))
.filter((item) => !isStoriesChannel(item))
.map((item, index) => {
const owner = String(item?.ownerLogin || '').trim();
const name = String(item?.channelName || '').trim();
const label = `${owner || 'my'}/${name || 'channel'}`;
return `<option value="${index}">${label}</option>`;
const label = formatChannelAddress({ ownerLogin: owner, channelName: name, channelRootBlockNumber: item.selector.channelRootBlockNumber });
return `<option value="${index}">${escapeHtml(label)}</option>`;
})
.join('');
@@ -1364,11 +1362,13 @@ async function loadFromApi(route, channelId) {
channel = allRows.find((item) => (
String(item?.channel?.ownerBlockchainName || '').trim().toLowerCase() === routeOwnerNormalized
&& String(item?.channel?.channelName || '').trim().toLowerCase() === selector.channelName.toLowerCase()
&& (selector.channelName.toLowerCase() !== 'stories' || Number(item?.channel?.channelRoot?.blockNumber) === 0)
));
if (!channel) {
channel = allRows.find((item) => (
String(item?.channel?.ownerLogin || '').trim().toLowerCase() === routeOwnerNormalized
&& String(item?.channel?.channelName || '').trim().toLowerCase() === selector.channelName.toLowerCase()
&& (selector.channelName.toLowerCase() !== 'stories' || Number(item?.channel?.channelRoot?.blockNumber) === 0)
));
}
if (!channel && !looksLikeBlockchainName(routeOwnerRaw)) {
@@ -1379,6 +1379,7 @@ async function loadFromApi(route, channelId) {
channel = allRows.find((item) => (
String(item?.channel?.ownerBlockchainName || '').trim().toLowerCase() === ownerBch
&& String(item?.channel?.channelName || '').trim().toLowerCase() === selector.channelName.toLowerCase()
&& (selector.channelName.toLowerCase() !== 'stories' || Number(item?.channel?.channelRoot?.blockNumber) === 0)
));
}
} catch {
@@ -1395,6 +1396,7 @@ async function loadFromApi(route, channelId) {
const ownerLoginNormalized = ownerLoginForLookup.toLowerCase();
channel = ownerRows.find((item) => (
String(item?.channel?.channelName || '').trim().toLowerCase() === selector.channelName.toLowerCase()
&& (selector.channelName.toLowerCase() !== 'stories' || Number(item?.channel?.channelRoot?.blockNumber) === 0)
&& (
String(item?.channel?.ownerBlockchainName || '').trim().toLowerCase() === routeOwnerNormalized
|| String(item?.channel?.ownerLogin || '').trim().toLowerCase() === ownerLoginNormalized
@@ -1408,6 +1410,7 @@ async function loadFromApi(route, channelId) {
const profileChannels = await authService.listUserProfileChannels(ownerLoginForLookup, 'owned', 500, 0, true);
const deletedRow = (Array.isArray(profileChannels?.channels) ? profileChannels.channels : []).find((item) => (
String(item?.slug || '').trim().toLowerCase() === selector.channelName.toLowerCase()
&& (selector.channelName.toLowerCase() !== 'stories' || Number(item?.rootBlockNumber) === 0)
&& String(item?.ownerLogin || '').trim().toLowerCase() === ownerLoginForLookup.toLowerCase()
));
if (deletedRow) {
@@ -1468,11 +1471,9 @@ async function loadFromApi(route, channelId) {
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();
if (channelTypeCode === 0 && payload.channel?.channelRoot?.blockHash) selector.channelRootBlockHash = normalizeRouteHash(payload.channel.channelRoot.blockHash);
selector.ownerLogin = ownerLogin; // для человекочитаемых ссылок сохраняем регистр регистрации
selector.publicOrdinalUrlsAllowed = channelTypeCode !== CHANNEL_TYPE_STORIES && channelTypeCode !== CHANNEL_TYPE_PERSONAL;
if (channelTypeCode === CHANNEL_TYPE_STORIES) {
throw new Error(t('screens.channel_view.text_120'));
}
selector.publicOrdinalUrlsAllowed = channelTypeCode !== CHANNEL_TYPE_PERSONAL;
const canResolveReverse = (
channelTypeCode === CHANNEL_TYPE_PERSONAL
&& !!currentLogin
@@ -1507,20 +1508,29 @@ async function loadFromApi(route, channelId) {
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) => (
String(row?.channel?.ownerBlockchainName || '') === String(selector.ownerBlockchainName || '')
const currentFeed = isAuthorized ? await ensureFeed() : {};
const followedRows = [...(currentFeed?.followedUsersChannels || []), ...(currentFeed?.followedChannels || [])];
const matchedSubscription = followedRows.find((row) => (
String(row?.channel?.ownerBlockchainName || '').toLowerCase() === String(selector.ownerBlockchainName || '').toLowerCase()
&& Number(row?.channel?.channelRoot?.blockNumber) === Number(selector.channelRootBlockNumber)
&& normalizeRouteHash(row?.channel?.channelRoot?.blockHash) === normalizeRouteHash(selector.channelRootBlockHash)
&& (Number(selector.channelRootBlockNumber) === 0 || normalizeRouteHash(row?.channel?.channelRoot?.blockHash) === normalizeRouteHash(selector.channelRootBlockHash))
));
const isSubscribed = isAuthorized && !!matchedSubscription;
if (matchedSubscription) {
unreadCount = Number(matchedSubscription.unreadCount || 0);
messagesCount = Number(matchedSubscription.messagesCount ?? messagesCount);
readCount = Number(matchedSubscription.readCount || 0);
readStateInitialized = !!matchedSubscription.readStateInitialized;
}
return {
channel: {
name: payload.channel?.channelName || t('screens.channel_view.text_121'),
ownerLogin,
ownerBlockchainName: String(payload.channel?.ownerBlockchainName || '').trim(),
displayTitle: String(payload.channel?.displayName || payload.channel?.channelName || t('screens.channel_view.text_122')).trim(),
displayName: `${ownerLogin || t('screens.channel_view.text_123')}/${payload.channel?.channelName || t('screens.channel_view.text_124')}`,
channelTypeCode,
displayTitle: channelTypeCode === 0 && isOwnChannel ? t('remaining.channels.my_publications') : String(payload.channel?.displayName || payload.channel?.channelName || t('screens.channel_view.text_122')).trim(),
displayName: formatChannelAddress({ ownerLogin, channelName, channelRootBlockNumber: selector.channelRootBlockNumber }),
description: String(payload.channel?.channelDescription || '').trim(),
avaAr: String(payload.channel?.avaAr || '').trim(),
avaPr: String(payload.channel?.avaPr || '').trim(),
@@ -2398,7 +2408,7 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
composer.className = 'channel-composer';
composer.append(addMessageButton);
handlers.chrome?.setComposer(composer);
} else if (!channelData.isSubscribed && !isStoriesChannel(channelData.channel)) {
} else if (!channelData.isSubscribed) {
screen.append(feed);
const composer = document.createElement('div');
composer.className = 'channel-composer';
@@ -2456,12 +2466,12 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
const feedGroups = ['ownedChannels', 'followedUsersChannels', 'followedChannels'];
for (const group of feedGroups) {
const rows = Array.isArray(state.channelsFeed?.[group]) ? state.channelsFeed[group] : [];
const row = rows.find((item) => (
const matchingRows = rows.filter((item) => (
String(item?.channel?.ownerBlockchainName || '') === String(channelData.selector?.ownerBlockchainName || '')
&& Number(item?.channel?.channelRoot?.blockNumber) === Number(channelData.selector?.channelRootBlockNumber)
&& normalizeRouteHash(item?.channel?.channelRoot?.blockHash) === normalizeRouteHash(channelData.selector?.channelRootBlockHash)
&& (Number(channelData.selector?.channelRootBlockNumber) === 0 || normalizeRouteHash(item?.channel?.channelRoot?.blockHash) === normalizeRouteHash(channelData.selector?.channelRootBlockHash))
));
if (row) {
for (const row of matchingRows) {
row.readCount = persistedReadCount;
row.unreadCount = persistedUnreadCount;
row.readStateInitialized = true;
@@ -2540,7 +2550,7 @@ export function render({ navigate, route, chrome }) {
const channelId = route.params.channelId || '';
const scrollToMessageOrdinal = route.params.scrollToMessageOrdinal || '';
const routeSelector = buildSelectorFromRoute(route, channelId);
const routeKey = `${routeSelector?.ownerBlockchainName || ''}:${routeSelector?.channelRootBlockNumber || ''}:${routeSelector?.channelRootBlockHash || ''}`;
const routeKey = `${routeSelector?.ownerBlockchainName || ''}:${routeSelector?.channelRootBlockNumber ?? routeSelector?.channelName ?? ''}:${routeSelector?.channelRootBlockHash || ''}`;
const screen = document.createElement('section');
screen.className = 'stack channels-screen channels-screen--channel';
@@ -2604,7 +2614,7 @@ export function render({ navigate, route, chrome }) {
const aboutRoute = makeShineChannelAboutRoute(routeArgs);
const donateRoute = makeShineChannelDonateRoute(routeArgs);
const items = [];
items.push({ id: 'channel-about', label: apiData?.isOwnChannel ? t('screens.channel_view.text_106') : t('screens.channel_view.text_107'), iconHtml: iconHtml(apiData?.isOwnChannel ? 'edit' : 'info'), action: () => { if (aboutRoute) navigate(aboutRoute); } });
items.push({ id: 'channel-about', label: apiData?.isOwnChannel && !isStoriesChannel(apiData?.channel) ? t('screens.channel_view.text_106') : t('screens.channel_view.text_107'), iconHtml: iconHtml(apiData?.isOwnChannel && !isStoriesChannel(apiData?.channel) ? 'edit' : 'info'), action: () => { if (aboutRoute) navigate(aboutRoute); } });
if (apiData?.isOwnChannel && !apiData?.isDiary) {
items.push({ label: t('screens.channel_view.text_041'), iconHtml: iconHtml('compose'), action: () => activeAddMessage?.() });
}
@@ -2619,7 +2629,7 @@ export function render({ navigate, route, chrome }) {
if (!apiData?.isOwnChannel) {
items.push({ label: t('screens.channel_view.text_043'), iconHtml: iconHtml('gift'), action: () => { if (donateRoute) navigate(donateRoute); } });
}
if (!apiData?.isOwnChannel && !isStoriesChannel(apiData?.channel)) {
if (!apiData?.isOwnChannel) {
if (apiData?.isSubscribed) {
items.push({
label: t('screens.channel_view.text_044'),
@@ -2828,6 +2838,7 @@ export function render({ navigate, route, chrome }) {
const feed = await authService.listSubscriptionsFeed(login, 1000);
const rows = Array.isArray(feed?.ownedChannels) ? feed.ownedChannels : [];
return rows
.filter((row) => !row?.channel?.deleted)
.map((row) => {
const selector = {
ownerBlockchainName: String(row?.channel?.ownerBlockchainName || '').trim(),
@@ -2844,14 +2855,13 @@ export function render({ navigate, route, chrome }) {
selector,
};
})
.filter(Boolean)
.filter((item) => !isStoriesChannel(item));
.filter(Boolean);
};
const isSameChannelSelector = (a, b) => (
String(a?.ownerBlockchainName || '').trim() === String(b?.ownerBlockchainName || '').trim()
&& Number(a?.channelRootBlockNumber) === Number(b?.channelRootBlockNumber)
&& normalizeRouteHash(a?.channelRootBlockHash) === normalizeRouteHash(b?.channelRootBlockHash)
&& (Number(a?.channelRootBlockNumber) === 0 || normalizeRouteHash(a?.channelRootBlockHash) === normalizeRouteHash(b?.channelRootBlockHash))
);
const onRepost = async (messageRef) => {