SHA256
UI: обновить thread/counters, вкладку Каналы и сценарий просмотра+подписки
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import {
|
||||
authService,
|
||||
getMessageReactionState,
|
||||
setChannelsFeed,
|
||||
setMessageReactionState,
|
||||
state,
|
||||
} from '../state.js';
|
||||
@@ -459,6 +460,13 @@ async function loadFromApi(route, channelId) {
|
||||
const messages = Array.isArray(payload.messages) ? payload.messages : [];
|
||||
const posts = messages.map((message, index) => mapApiMessageToPost(message, selector, index + 1));
|
||||
const ownerLogin = String(payload.channel?.ownerLogin || '').trim();
|
||||
const isOwnChannel = ownerLogin.toLowerCase() === (state.session.login || '').toLowerCase();
|
||||
const followedRows = Array.isArray(state.channelsFeed?.followedChannels) ? state.channelsFeed.followedChannels : [];
|
||||
const isSubscribed = followedRows.some((row) => (
|
||||
String(row?.channel?.ownerBlockchainName || '') === String(selector.ownerBlockchainName || '')
|
||||
&& Number(row?.channel?.channelRoot?.blockNumber) === Number(selector.channelRootBlockNumber)
|
||||
&& normalizeRouteHash(row?.channel?.channelRoot?.blockHash) === normalizeRouteHash(selector.channelRootBlockHash)
|
||||
));
|
||||
|
||||
return {
|
||||
channel: {
|
||||
@@ -468,7 +476,8 @@ async function loadFromApi(route, channelId) {
|
||||
ownerName: ownerLogin || 'неизвестно',
|
||||
},
|
||||
posts,
|
||||
isOwnChannel: ownerLogin.toLowerCase() === (state.session.login || '').toLowerCase(),
|
||||
isOwnChannel,
|
||||
isSubscribed,
|
||||
selector,
|
||||
};
|
||||
}
|
||||
@@ -762,7 +771,7 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
||||
onSubmit: async (bodyText) => handlers.onAddPost(bodyText),
|
||||
});
|
||||
});
|
||||
} else {
|
||||
} else if (!channelData.isSubscribed) {
|
||||
actionButton.addEventListener('click', handlers.onSubscribeChannel);
|
||||
}
|
||||
|
||||
@@ -771,7 +780,11 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
||||
backButton.textContent = 'Назад к каналам';
|
||||
backButton.addEventListener('click', () => navigate('channels-list'));
|
||||
|
||||
screen.append(head, actionButton, feed, backButton);
|
||||
if (channelData.isOwnChannel || !channelData.isSubscribed) {
|
||||
screen.append(head, actionButton, feed, backButton);
|
||||
} else {
|
||||
screen.append(head, feed, backButton);
|
||||
}
|
||||
|
||||
applyPendingScroll(screen, routeKey);
|
||||
return () => {
|
||||
@@ -967,8 +980,11 @@ export function render({ navigate, route }) {
|
||||
unfollow: false,
|
||||
});
|
||||
|
||||
const feed = await authService.listSubscriptionsFeed(login, 200);
|
||||
setChannelsFeed(feed, state.channelsIndex);
|
||||
softHaptic(15);
|
||||
showToast('Подписка на канал выполнена');
|
||||
rerender();
|
||||
} catch (error) {
|
||||
showStatus(toUserMessage(error, 'Не удалось подписаться на канал.'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user