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

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
+8 -7
View File
@@ -567,7 +567,8 @@ export function render({ navigate, route, chrome }) {
};
const renderContent = ({ channel, selector, ownerUser, ownerProfile, isOwnChannel, isSubscribed }) => {
const cleanName = String(channel?.displayTitle || channel?.displayName || channel?.channelName || t('dialogs.modals.channel_about_view.channel_fallback')).trim();
const isRoot = Number(selector?.channelRootBlockNumber) === 0;
const cleanName = isRoot && isOwnChannel ? t('remaining.channels.my_publications') : String(channel?.displayTitle || channel?.displayName || channel?.channelName || t('dialogs.modals.channel_about_view.channel_fallback')).trim();
const ownerLogin = String(channel?.ownerLogin || extractLoginFromBlockchainName(selector?.ownerBlockchainName) || '').trim();
const channelName = String(channel?.channelName || '').trim();
const description = String(channel?.channelDescription || channel?.description || '').trim();
@@ -603,7 +604,7 @@ export function render({ navigate, route, chrome }) {
<div class="channel-about-tiles">
${cameFromChannel ? '' : `<button class="channel-about-tile" id="channel-about-open" type="button">${iconHtml('open')}<span>${th('screens.channel_about_view.text_035')}</span></button>`}
${isOwnChannel ? `<button class="channel-about-tile" id="channel-about-edit" type="button">${iconHtml('edit')}<span>${th('screens.channel_about_view.text_036')}</span></button>` : ''}
${isOwnChannel && !isRoot ? `<button class="channel-about-tile" id="channel-about-edit" type="button">${iconHtml('edit')}<span>${th('screens.channel_about_view.text_036')}</span></button>` : ''}
${subscriptionTile}
${isOwnChannel ? '' : `<button class="channel-about-tile" id="channel-about-support" type="button">${iconHtml('gift')}<span>${th('screens.channel_about_view.text_037')}</span></button>`}
</div>
@@ -624,7 +625,7 @@ export function render({ navigate, route, chrome }) {
</span>
<span class="channel-about-row-chevron">${iconHtml('chevron')}</span>
</button>
${isOwnChannel && !isDeleted ? `<button class="channel-about-row" id="channel-about-delete" type="button">
${isOwnChannel && !isRoot && !isDeleted ? `<button class="channel-about-row" id="channel-about-delete" type="button">
<span class="channel-about-row-main"><span class="channel-about-row-label">${th('screens.channel_about_view.text_038')}</span><span class="meta-muted">${th('screens.channel_about_view.text_039')}</span></span>
<span class="channel-about-row-chevron" aria-hidden="true">${iconHtml('trash')}</span>
</button>` : ''}
@@ -738,6 +739,7 @@ export function render({ navigate, route, chrome }) {
if (disposed || seq !== refreshSeq) return;
const channel = payload?.channel || {};
if (Number(selector.channelRootBlockNumber) === 0 && channel.channelRoot?.blockHash) selector.channelRootBlockHash = normalizeHash(channel.channelRoot.blockHash);
const ownerLogin = String(channel?.ownerLogin || extractLoginFromBlockchainName(selector.ownerBlockchainName) || '').trim();
const currentLogin = String(state.session.login || '').trim();
const isOwnChannel = Boolean(ownerLogin && currentLogin && ownerLogin.toLowerCase() === currentLogin.toLowerCase());
@@ -753,10 +755,9 @@ export function render({ navigate, route, chrome }) {
const ownerProfile = ownerProfileResult.status === 'fulfilled' ? ownerProfileResult.value : null;
const feed = feedResult.status === 'fulfilled' ? feedResult.value : null;
if (feed) setChannelsFeed(feed, state.channelsIndex);
const followedRows = Array.isArray(feed?.followedChannels)
? feed.followedChannels
: (Array.isArray(state.channelsFeed?.followedChannels) ? state.channelsFeed.followedChannels : []);
const isSubscribed = !isOwnChannel && followedRows.some((row) => isSelectorMatch(row, selector));
const currentFeed = feed || state.channelsFeed || {};
const followedRows = [...(currentFeed.followedUsersChannels || []), ...(currentFeed.followedChannels || [])];
const isSubscribed = !isOwnChannel && followedRows.some((row) => isSelectorMatch(row, selector) || (Number(selector.channelRootBlockNumber) === 0 && Number(row?.channel?.channelRoot?.blockNumber) === 0 && String(row?.channel?.ownerLogin || '').toLowerCase() === ownerLogin.toLowerCase()));
renderContent({
channel,
+8 -11
View File
@@ -215,11 +215,7 @@ function allFeedSummaries() {
...(feed.ownedChannels || []),
...(feed.followedUsersChannels || []),
...(feed.followedChannels || []),
].filter((summary) => {
const typeCode = Number(summary?.channel?.channelTypeCode ?? 1);
const channelName = String(summary?.channel?.channelName || '').trim().toLowerCase();
return typeCode !== 0 && channelName !== 'stories';
});
].filter((summary) => summary?.channel && !summary.channel.deleted);
}
const channelTitleByLabel = new Map();
@@ -240,7 +236,7 @@ function resolveChannelDisplayName(channelSelector) {
const found = allFeedSummaries().find((summary) => (
String(summary?.channel?.ownerBlockchainName || '') === ownerBch
&& Number(summary?.channel?.channelRoot?.blockNumber) === rootNo
&& normalizeRouteHash(summary?.channel?.channelRoot?.blockHash) === rootHash
&& (rootNo === 0 || normalizeRouteHash(summary?.channel?.channelRoot?.blockHash) === rootHash)
));
if (!found) return '';
const label = `${found.channel?.ownerLogin || t('screens.channel_thread_view.text_078')}/${found.channel?.channelName || t('screens.channel_thread_view.text_079')}`;
@@ -253,7 +249,7 @@ function resolveChannelHeadingFromNode(node) {
const ownerBch = String(info?.ownerBlockchainName || '').trim();
const rootBlockNumber = Number(info?.channelRoot?.blockNumber);
if (!ownerBch || !Number.isFinite(rootBlockNumber) || rootBlockNumber < 0) return '';
if (rootBlockNumber === 0) return t('screens.channel_thread_view.text_058');
if (rootBlockNumber === 0) return t('remaining.channels.publications');
const label = resolveChannelDisplayName({
ownerBlockchainName: ownerBch,
@@ -496,8 +492,8 @@ function openRepostModal({ navigate, channels = [], onSubmit, isActive = () => t
.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('');
@@ -1539,6 +1535,7 @@ async function loadThreadData(sel, cacheKey, isCurrent) {
});
}
const meta = channelPayload?.channel || {};
if (Number(sel.channel.channelRootBlockNumber) === 0 && meta.channelRoot?.blockHash) sel.channel.channelRootBlockHash = normalizeRouteHash(meta.channelRoot.blockHash);
title = String(meta.displayName || meta.channelName || title).trim();
avatarAr = String(meta.avaAr || '').trim();
avatarPr = String(meta.avaPr || '').trim();
@@ -1737,6 +1734,7 @@ export function render({ navigate, route, chrome }) {
const feed = await authService.listSubscriptionsFeed(login, 1000);
if (disposed) return;
const channels = (Array.isArray(feed?.ownedChannels) ? feed.ownedChannels : [])
.filter((row) => !row?.channel?.deleted)
.map((row) => {
const selectorRow = {
ownerBlockchainName: String(row?.channel?.ownerBlockchainName || '').trim(),
@@ -1753,8 +1751,7 @@ export function render({ navigate, route, chrome }) {
selector: selectorRow,
};
})
.filter(Boolean)
.filter((item) => Number(item.channelTypeCode) !== 0 && String(item.channelName || '').trim().toLowerCase() !== 'stories');
.filter(Boolean);
if (!channels.length) throw new Error(t('screens.channel_thread_view.text_091'));
openRepostModal({
+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) => {
+14 -366
View File
@@ -86,14 +86,6 @@ function normalizeHash(hash) {
return normalized || '0';
}
function encodeRoutePart(value = '') {
return encodeURIComponent(String(value));
}
function normalizeLoginInput(value) {
return String(value || '').trim().replace(/^@+/, '');
}
function buildChannelRouteFromSummary(summary, fallbackId) {
const ownerBch = String(summary?.channel?.ownerBlockchainName || '').trim();
const ownerLogin = String(summary?.channel?.ownerLogin || '').trim();
@@ -107,14 +99,13 @@ function buildChannelRouteFromSummary(summary, fallbackId) {
function isStoriesChannel(summaryOrChannel = null) {
const typeCode = Number(summaryOrChannel?.channel?.channelTypeCode ?? summaryOrChannel?.channelTypeCode ?? 1);
const channelName = String(summaryOrChannel?.channel?.channelName || summaryOrChannel?.channelName || '').trim().toLowerCase();
return typeCode === CHANNEL_TYPE_STORIES || channelName === 'stories';
return typeCode === CHANNEL_TYPE_STORIES;
}
function isVisibleChannelSummary(summary) {
if (!summary?.channel) return false;
if (isStoriesChannel(summary)) return false;
if (summary?.channel?.deleted) return false;
if (!isStoriesChannel(summary) && String(summary.channel.channelName || '').toLowerCase() === 'stories') return false;
const ownerLogin = String(summary.channel.ownerLogin || '').trim();
const channelName = String(summary.channel.channelName || '').trim();
return !!ownerLogin && !!channelName;
@@ -137,148 +128,6 @@ function createChannelAvatar(channel = {}) {
});
}
function allFeedSummaries() {
const feed = state.channelsFeed || {};
return [
...(feed.ownedChannels || []),
...(feed.followedUsersChannels || []),
...(feed.followedChannels || []),
].filter(isVisibleChannelSummary);
}
function uniqueBy(items, keySelector) {
const seen = new Set();
const out = [];
for (const item of items) {
const key = keySelector(item);
if (!key || seen.has(key)) continue;
seen.add(key);
out.push(item);
}
return out;
}
function createDebounced(fn, delayMs = 250) {
let timer = null;
return (...args) => {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
timer = null;
fn(...args);
}, delayMs);
};
}
async function resolveChannelTargetFromInput(rawInput) {
const input = String(rawInput || '').trim();
if (!input) throw new Error(t('screens.channels_list.text_028'));
const byOwnerAndName = input.match(/^@?([^/#\s]+)\s*\/\s*#?(.+)$/);
if (byOwnerAndName) {
const ownerLogin = normalizeLoginInput(byOwnerAndName[1]);
const channelName = String(byOwnerAndName[2] || '').trim().toLowerCase();
if (!ownerLogin || !channelName) {
throw new Error(t('screens.channels_list.text_029'));
}
const user = await authService.getUser(ownerLogin);
if (!user?.exists || !user?.blockchainName) {
throw new Error(t('screens.channels_list.text_030'));
}
const ownerFeed = await authService.listSubscriptionsFeed(ownerLogin, 500);
const ownChannels = Array.isArray(ownerFeed?.ownedChannels) ? ownerFeed.ownedChannels.filter(isVisibleChannelSummary) : [];
const matches = ownChannels.filter((item) => (
String(item?.channel?.channelName || '').trim().toLowerCase() === channelName
));
if (!matches.length) {
throw new Error(t('screens.channels_list.text_031'));
}
const primaryMatches = matches.filter((item) => (
String(item?.channel?.ownerBlockchainName || '') === String(user.blockchainName || '')
));
const pool = primaryMatches.length ? primaryMatches : matches;
const match = [...pool].sort((a, b) => (
Number(b?.channel?.channelRoot?.blockNumber || -1) - Number(a?.channel?.channelRoot?.blockNumber || -1)
))[0];
return {
ownerBlockchainName: String(match?.channel?.ownerBlockchainName || user.blockchainName),
rootBlockNumber: Number(match?.channel?.channelRoot?.blockNumber),
rootBlockHash: normalizeHash(match?.channel?.channelRoot?.blockHash),
};
}
const byNameOnly = input.replace(/^#/, '').trim().toLowerCase();
const summaries = allFeedSummaries();
const matches = summaries.filter((summary) => (
String(summary?.channel?.channelName || '').trim().toLowerCase() === byNameOnly
));
if (!matches.length) {
throw new Error(t('screens.channels_list.text_032'));
}
if (matches.length > 1) {
throw new Error(t('screens.channels_list.text_033'));
}
const one = matches[0];
return {
ownerBlockchainName: String(one?.channel?.ownerBlockchainName || ''),
rootBlockNumber: Number(one?.channel?.channelRoot?.blockNumber),
rootBlockHash: normalizeHash(one?.channel?.channelRoot?.blockHash),
};
}
function channelSuggestionsByInput(rawInput) {
const q = String(rawInput || '').trim().toLowerCase();
if (q.length < 1) return [];
const rows = allFeedSummaries().map((summary) => {
const owner = String(summary?.channel?.ownerLogin || '').trim();
const channel = String(summary?.channel?.channelName || '').trim();
if (!owner || !channel) return null;
return {
key: `${owner.toLowerCase()}/${channel.toLowerCase()}`,
label: formatChannelAddress({ ownerLogin: owner, channelName: channel }),
owner,
channel,
};
}).filter(Boolean);
return uniqueBy(rows, (it) => it.key)
.filter((it) => (
it.channel.toLowerCase().includes(q) ||
formatChannelAddress({ ownerLogin: it.owner.toLowerCase(), channelName: it.channel.toLowerCase() }).includes(normalizeLoginInput(q))
))
.slice(0, 7)
.map((it) => it.label);
}
function renderSuggestions(container, values, onPick) {
container.innerHTML = '';
if (!values.length) {
container.style.display = 'none';
return;
}
container.style.display = '';
values.forEach((value) => {
const btn = document.createElement('button');
btn.type = 'button';
btn.className = 'ui-button channel-search-item';
btn.textContent = value;
btn.addEventListener('click', () => onPick(value));
container.append(btn);
});
}
function normalizeComparableLogin(value) {
return normalizeLoginInput(value).toLowerCase();
}
function normalizeChannelsViewMode(route = null) {
const mode = String(route?.params?.mode || '').trim().toLowerCase();
const scope = String(route?.params?.scope || '').trim().toLowerCase();
@@ -302,211 +151,6 @@ const CHANNEL_FILTERS = () => [
[CHANNELS_VIEW_DELETED, t('screens.channels_list.text_045')],
];
function isFollowedUserVisible(targetLogin) {
const expected = normalizeComparableLogin(targetLogin);
if (!expected) return false;
const rows = Array.isArray(state.channelsFeed?.followedUsersChannels)
? state.channelsFeed.followedUsersChannels
: [];
return rows
.filter(isVisibleChannelSummary)
.some((row) => normalizeComparableLogin(row?.channel?.ownerLogin) === expected);
}
function isFollowedChannelVisible(target) {
const rows = Array.isArray(state.channelsFeed?.followedChannels)
? state.channelsFeed.followedChannels
: [];
const expectedBch = String(target?.ownerBlockchainName || '');
const expectedNo = Number(target?.rootBlockNumber);
const expectedHash = normalizeHash(target?.rootBlockHash);
if (!expectedBch || !Number.isFinite(expectedNo)) return false;
return rows.filter(isVisibleChannelSummary).some((row) => {
const rowBch = String(row?.channel?.ownerBlockchainName || '');
const rowNo = Number(row?.channel?.channelRoot?.blockNumber);
const rowHash = normalizeHash(row?.channel?.channelRoot?.blockHash);
return rowBch === expectedBch && rowNo === expectedNo && rowHash === expectedHash;
});
}
function openSimpleSubscribeModal({ kind, kindLabel, submitLabel, unfollow = false, onSuccess }) {
const targetHint = kind === 'channel'
? `<p class="meta-muted">${t('dialogs.remaining.pages.channels_list.markup.kanal_alice_free_channel_ili_imya_kanala')}</p>`
: `<p class="meta-muted">${t('dialogs.remaining.pages.channels_list.markup.avtor_alice_free_staryy_vvod_s_tozhe_prinimaetsya')}</p>`;
const submitText = submitLabel || (unfollow ? t('dialogs.remaining.pages.channels_list.opensimplesubscribemodal.otpisatsya') : t('dialogs.remaining.pages.channels_list.opensimplesubscribemodal.podpisatsya'));
const placeholder = kind === 'channel' ? 'Alice@free/channel' : 'Alice@free';
const root = document.getElementById('modal-root');
root.innerHTML = `
<div class="modal" id="channels-subscribe-modal">
<div class="modal-card stack">
<h3 class="modal-title">${kindLabel}</h3>
${targetHint}
<label class="meta-muted" for="subscribe-input">${t('dialogs.modals.channels_list.label_001')}</label>
<input id="subscribe-input" class="input" placeholder="${placeholder}" autocomplete="off" />
<div id="subscribe-suggest" class="channels-search-suggest" style="display:none"></div>
<div id="subscribe-error" class="meta-muted inline-error"></div>
<div class="form-actions-grid">
<button class="secondary-btn" id="sub-cancel" type="button">${t('dialogs.modals.channels_list.label_002')}</button>
<button class="primary-btn" id="sub-submit" type="button">${submitText}</button>
</div>
</div>
</div>
`;
const inputEl = root.querySelector('#subscribe-input');
const suggestEl = root.querySelector('#subscribe-suggest');
const errorEl = root.querySelector('#subscribe-error');
const submitEl = root.querySelector('#sub-submit');
let inFlight = false;
const setBusy = (busy) => {
inFlight = !!busy;
submitEl.disabled = inFlight;
if (inputEl) inputEl.disabled = inFlight;
submitEl.textContent = inFlight ? t('dialogs.modals.channels_list.label_003') : submitText;
};
const close = () => {
root.innerHTML = '';
};
const applySuggestion = (value) => {
if (!inputEl) return;
inputEl.value = value;
if (suggestEl) suggestEl.style.display = 'none';
inputEl.focus();
};
const refreshSuggestions = createDebounced(async () => {
if (!inputEl || !suggestEl || inFlight) return;
const raw = String(inputEl.value || '').trim();
if (!raw) {
suggestEl.style.display = 'none';
suggestEl.innerHTML = '';
return;
}
try {
if (kind === 'user') {
const prefix = normalizeLoginInput(raw);
if (prefix.length < 2) {
suggestEl.style.display = 'none';
suggestEl.innerHTML = '';
return;
}
const logins = await authService.searchUsers(prefix);
const suggestions = (Array.isArray(logins) ? logins : []).slice(0, 8).map((login) => normalizeLoginInput(login));
renderSuggestions(suggestEl, suggestions, applySuggestion);
return;
}
const suggestions = channelSuggestionsByInput(raw);
renderSuggestions(suggestEl, suggestions, applySuggestion);
} catch {
suggestEl.style.display = 'none';
suggestEl.innerHTML = '';
}
}, 240);
root.querySelector('#sub-cancel')?.addEventListener('click', close);
inputEl?.addEventListener('input', () => {
if (!errorEl) return;
errorEl.textContent = '';
refreshSuggestions();
});
submitEl?.addEventListener('click', async () => {
if (inFlight) return;
const login = state.session.login;
const storagePwd = state.session.storagePwdInMemory;
const value = String(inputEl?.value || '').trim();
if (!login || !storagePwd) {
errorEl.textContent = t('dialogs.modals.channels_list.label_004');
return;
}
if (!value) {
errorEl.textContent = t('dialogs.modals.channels_list.label_005');
return;
}
setBusy(true);
errorEl.textContent = '';
try {
let channelTarget = null;
let userTargetLogin = '';
if (kind === 'user') {
userTargetLogin = normalizeLoginInput(value);
await authService.addBlockFollowUser({
login,
targetLogin: userTargetLogin,
storagePwd,
unfollow,
});
} else if (kind === 'channel') {
channelTarget = await resolveChannelTargetFromInput(value);
if (!channelTarget?.ownerBlockchainName || !Number.isFinite(channelTarget.rootBlockNumber)) {
throw new Error(t('dialogs.remaining.pages.channels_list.opensimplesubscribemodal.kanal_ne_nayden'));
}
await authService.addBlockFollowChannel({
login,
storagePwd,
targetBlockchainName: channelTarget.ownerBlockchainName,
targetBlockNumber: channelTarget.rootBlockNumber,
targetBlockHashHex: channelTarget.rootBlockHash,
unfollow,
});
} else {
throw new Error(t('dialogs.remaining.pages.channels_list.opensimplesubscribemodal.nepodderzhivaemyy_tip_podpiski'));
}
if (typeof onSuccess === 'function') {
await onSuccess();
}
if (kind === 'user') {
const visible = isFollowedUserVisible(userTargetLogin);
if (!unfollow && !visible) {
throw new Error(t('dialogs.remaining.pages.channels_list.opensimplesubscribemodal.podpiska_ne_podtverdilas_posle_obnovleniya_spiska'));
}
if (unfollow && visible) {
throw new Error(t('dialogs.remaining.pages.channels_list.opensimplesubscribemodal.otpiska_ne_podtverdilas_posle_obnovleniya_spiska'));
}
}
if (kind === 'channel') {
const visible = isFollowedChannelVisible(channelTarget);
if (!unfollow && !visible) {
throw new Error(t('dialogs.remaining.pages.channels_list.opensimplesubscribemodal.podpiska_na_kanal_ne_podtverdilas_posle_obnovleniya_sp'));
}
if (unfollow && visible) {
throw new Error(t('dialogs.remaining.pages.channels_list.opensimplesubscribemodal.otpiska_ot_kanala_ne_podtverdilas_posle_obnovleniya_sp'));
}
}
softHaptic(15);
showToast(unfollow ? t('dialogs.remaining.pages.channels_list.opensimplesubscribemodal.otpiska_vypolnena') : t('dialogs.remaining.pages.channels_list.opensimplesubscribemodal.podpiska_vypolnena'));
close();
} catch (error) {
errorEl.textContent = toUserMessage(error, t('dialogs.remaining.pages.channels_list.opensimplesubscribemodal.value1_ne_udalos', { value1: submitText }));
setBusy(false);
}
});
if (inputEl) inputEl.focus();
}
function mapMockGroups() {
const mapRow = (channel) => ({
...channel,
@@ -551,18 +195,18 @@ function mapMockGroups() {
}
function mapApiChannelRow(summary, bucketKey, idx, index, notificationsState) {
const rowId = `${bucketKey}-${idx}`;
const rowId = isStoriesChannel(summary) ? `${bucketKey}-publications-${String(summary?.channel?.ownerLogin || '').toLowerCase()}` : `${bucketKey}-${idx}`;
index[rowId] = summary;
const ownerLogin = summary?.channel?.ownerLogin || t('screens.channels_list.text_035');
const channelName = summary?.channel?.channelName || t('screens.channels_list.text_036');
const displayTitle = String(summary?.channel?.displayName || channelName).trim();
const displayTitle = isStoriesChannel(summary) && bucketKey === 'own' ? t('remaining.channels.my_publications') : String(summary?.channel?.displayName || channelName).trim();
const channelDescription = String(summary?.channel?.channelDescription || '').trim();
const channelTypeCode = Number(summary?.channel?.channelTypeCode ?? 1);
const channelTypeVersion = Number(summary?.channel?.channelTypeVersion ?? 1);
const isOwn = bucketKey === 'own';
const title = displayTitle || channelName;
const technicalLabel = formatChannelAddress({ ownerLogin, channelName });
const technicalLabel = formatChannelAddress({ ownerLogin, channelName, channelRootBlockNumber: Number(summary?.channel?.channelRoot?.blockNumber) });
const lastMessage = resolveChannelLastMessage(summary);
return {
@@ -698,15 +342,19 @@ function buildDiaryChannelRow(diaryPayload, ownRows = [], notificationsState = {
function mapApiFeed(feed, notificationsState, diaryPayload = null) {
const index = {};
const ownChannels = (feed?.ownedChannels || [])
.filter(isVisibleChannelSummary)
.map((it, idx) => mapApiChannelRow(it, 'own', idx, index, notificationsState));
const ownRows = (feed?.ownedChannels || []).filter(isVisibleChannelSummary);
const ownChannels = [
...ownRows.filter(isStoriesChannel).map(it => mapApiChannelRow(it, 'own', 0, index, notificationsState)),
...ownRows.filter(it => !isStoriesChannel(it)).map((it, idx) => mapApiChannelRow(it, 'own', idx, index, notificationsState)),
];
const diaryChannel = diaryPayload
? buildDiaryChannelRow(diaryPayload, feed?.ownedChannels || [], notificationsState, index)
: null;
if (diaryChannel) ownChannels.unshift(diaryChannel);
if (diaryChannel) ownChannels.splice(ownChannels[0]?.channelTypeCode === 0 ? 1 : 0, 0, diaryChannel);
const seenRoots = new Set();
const followedUserChannels = (feed?.followedUsersChannels || [])
.filter(isVisibleChannelSummary)
.filter(it => { const key = String(it.channel.ownerLogin).toLowerCase(); if (seenRoots.has(key)) return false; seenRoots.add(key); return true; })
.map((it, idx) => mapApiChannelRow(it, 'followedUsers', idx, index, notificationsState));
const subscribedChannels = (feed?.followedChannels || [])
.filter(isVisibleChannelSummary)
@@ -887,7 +535,7 @@ function renderListContent({ screen, container, listState, navigate, refreshFeed
const allChannels = listState.channels || [];
const filtered = allChannels.filter((channel) => {
if (listState.viewMode === CHANNELS_VIEW_OWNED) return channel.isOwnChannel === true && channel.isDeleted !== true;
if (listState.viewMode === CHANNELS_VIEW_FOLLOWING) return channel.sourceBucket === 'followedChannels';
if (listState.viewMode === CHANNELS_VIEW_FOLLOWING) return channel.isSubscribed === true && !channel.isOwnChannel;
if (listState.viewMode === CHANNELS_VIEW_DELETED) return channel.isDeleted === true;
return channel.isDeleted !== true;
}).filter((channel) => {
+2
View File
@@ -58,6 +58,7 @@ export function render({ navigate, chrome }) {
card,
login,
tilesHtml: [
profileTileHtml({ icon: 'channels', label: t('remaining.channels.my_publications'), attrs: 'data-self-profile-action="publications"' }),
profileTileHtml({ icon: 'edit', label: t('screens.profile_view.text_007'), attrs: 'data-self-profile-action="edit"' }),
profileTileHtml({ icon: 'wallet', label: t('screens.profile_view.text_008'), attrs: 'data-self-profile-action="wallet"' }),
profileTileHtml({ icon: 'settings', label: t('screens.profile_view.text_009'), attrs: 'data-self-profile-action="settings"' }),
@@ -83,6 +84,7 @@ export function render({ navigate, chrome }) {
const actionButton = event.target.closest('[data-self-profile-action]');
if (actionButton) {
const action = actionButton.dataset.selfProfileAction;
if (action === 'publications') navigate(`SHiNE/${encodeURIComponent(card.login)}/stories`);
if (action === 'edit') navigate('profile-edit-view');
if (action === 'wallet') navigate('wallet-view');
if (action === 'settings') navigate('settings-view');
+7 -3
View File
@@ -5,7 +5,7 @@ import { renderAvatar } from '../components/avatar-image.js';
import { createPersonRow } from '../components/person-row.js';
import { createLoadingState, createStateMessage } from '../components/feedback.js';
import { iconHtml } from '../components/ui-icon.js';
import { formatChannelAddress, makeShineChannelRoute, makeProfileRoute } from '../services/shine-routes.js';
import { formatChannelAddress, makeShineChannelRoute, makeProfileRoute, makeShineChannelShortRoute } from '../services/shine-routes.js';
export const pageMeta = {
id: 'search-view',
@@ -40,7 +40,7 @@ function channelRow(item, navigate) {
title.textContent = displayName;
const address = document.createElement('span');
address.className = 'shine-search-result__address';
address.textContent = t('screens.search_view.text_020', { value1: formatChannelAddress({ ownerLogin, channelName: slug }), value2: Number(item.subscribersCount || 0) });
address.textContent = item.isRootPublications ? formatChannelAddress({ ownerLogin, channelName: slug }) : t('screens.search_view.text_020', { value1: formatChannelAddress({ ownerLogin, channelName: slug }), value2: Number(item.subscribersCount || 0) });
text.append(title, address);
const description = String(item.description || '').trim();
if (description) {
@@ -51,7 +51,7 @@ function channelRow(item, navigate) {
}
row.append(text);
row.addEventListener('click', () => {
const route = makeShineChannelRoute({
const route = (item.isRootPublications ? makeShineChannelShortRoute : makeShineChannelRoute)({
ownerLogin,
ownerBlockchainName: String(item.ownerBlockchainName || '').trim(),
channelName: slug,
@@ -176,6 +176,10 @@ export function render({ navigate, chrome }) {
if (disposed || currentSeq !== seq) return;
channels = results[0].status === 'fulfilled' ? results[0].value : [];
people = results[1]?.status === 'fulfilled' ? results[1].value : [];
channels = [...people.filter(person => person?.login).map(person => ({
isRootPublications: true, ownerLogin: person.login, slug: 'stories',
displayName: person.displayName || person.login, avatarAr: person.avatarAr, avatarPr: person.avatarPr,
})), ...channels];
error = results.every((result) => result.status === 'rejected')
? t('screens.search_view.text_017')
: '';
+2 -1
View File
@@ -1,3 +1,4 @@
import { formatChannelAddress } from '../services/shine-routes.js';
import { t, th } from '../i18n/index.js';
import { createTopBar } from '../components/topbar.js';
import { renderUserAvatar } from '../components/avatar-image.js';
@@ -149,7 +150,7 @@ export function render({ navigate, route, chrome }) {
const title = document.createElement('b');
title.textContent = `${String(row.displayName || row.slug || '')}${row.deleted ? t('screens.user_profile_list_view.text_013') : ''}`;
const sub = document.createElement('small');
sub.textContent = `${String(row.ownerLogin || '')} / ${String(row.slug || '')}`;
sub.textContent = formatChannelAddress({ ownerLogin: row.ownerLogin, channelName: row.slug, channelRootBlockNumber: Number(row.rootBlockNumber) });
text.append(title, sub);
el.append(text);
el.addEventListener('click', () => navigate(`channel/${encodeURIComponent(row.ownerBlockchainName)}/${Number(row.rootBlockNumber || 0)}/${encodeURIComponent(row.rootBlockHashHex || '')}/about`));
+5 -2
View File
@@ -59,12 +59,14 @@ export function render({ navigate, route, chrome }) {
card,
login: requestedLogin,
isSelf,
tilesHtml: isSelf ? '' : [
tilesHtml: [
profileTileHtml({ icon: 'channels', label: t('remaining.channels.publications'), attrs: 'data-profile-action="publications"' }),
...(isSelf ? [] : [
profileTileHtml({ icon: 'user-plus', label: t('screens.user_profile_view.text_004'), attrs: 'data-profile-action="add"' }),
profileTileHtml({ label: t('screens.user_profile_view.text_005'), attrs: 'data-profile-action="links"', iconMarkup: `<img class="pf-tile-mandala" src="${SHINE_CONNECTIONS_LOGO_SRC}" alt="" aria-hidden="true">` }),
profileTileHtml({ icon: 'message', label: t('screens.user_profile_view.text_006'), attrs: 'data-profile-action="chat"' }),
profileTileHtml({ icon: 'heart', label: t('screens.support_phase2.donate'), attrs: 'data-profile-action="support"' }),
].join(''),
])].join(''),
});
attachSupportStats(body, { login: card.login, isActive: () => !disposed });
@@ -117,6 +119,7 @@ export function render({ navigate, route, chrome }) {
const actionButton = event.target.closest('[data-profile-action]');
const action = actionButton?.dataset.profileAction;
if (action === 'publications') { navigate(`SHiNE/${encodeURIComponent(card.login)}/stories`); return; }
if (action === 'add') {
navigate(`SHiNE/${encodeURIComponent(card.login)}/manage`);
return;