Добавить user_settings и синхронизацию настроек

This commit is contained in:
AidarKC
2026-08-19 19:45:09 +04:00
parent fac166f186
commit 6a5c20a165
37 changed files with 2079 additions and 3 deletions
+30
View File
@@ -234,6 +234,12 @@ function buildThreadRoute(messageRef, selector) {
});
}
function buildChannelSettingsKey(selector, channelName) {
const ownerBch = String(selector?.ownerBlockchainName || '').trim();
const name = String(channelName || '').trim();
return `${ownerBch}/${name}`;
}
function firstNonEmptyText(...candidates) {
for (const candidate of candidates) {
if (typeof candidate !== 'string') continue;
@@ -1374,6 +1380,8 @@ async function loadFromApi(route, channelId) {
const messages = Array.isArray(payload.messages) ? payload.messages : [];
let reverseChannelMissingWarning = '';
let mergedMessages = [...messages];
const unreadCount = Number(channel?.unreadCount || 0);
const messagesCount = Number(channel?.messagesCount || mergedMessages.length || 0);
const currentLogin = currentSessionLogin;
const ownerLogin = String(payload.channel?.ownerLogin || '').trim();
@@ -1445,6 +1453,8 @@ async function loadFromApi(route, channelId) {
posts,
metaEvents: Array.isArray(payload?.metaEvents) ? payload.metaEvents : [],
reverseChannelMissingWarning,
unreadCount,
messagesCount,
isOwnChannel,
isSubscribed,
selector,
@@ -1905,6 +1915,13 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
screen.append(reverseWarning);
}
if (Number(channelData.unreadCount || 0) > 0) {
const unreadLine = document.createElement('div');
unreadLine.className = 'card channel-unread-line';
unreadLine.textContent = `Не прочитано: ${channelData.unreadCount}`;
screen.append(unreadLine);
}
const actionButton = document.createElement('button');
actionButton.className = 'destructive-btn channel-main-action';
actionButton.textContent = 'Подписаться на канал';
@@ -2294,6 +2311,19 @@ export function render({ navigate, route, chrome }) {
try {
const apiData = await loadFromApi(route, channelId);
activeSelector = apiData?.selector || null;
const lastSeenCount = Number(apiData?.messagesCount || (Array.isArray(apiData?.posts) ? apiData.posts.length : 0) || 0);
const settingKey = buildChannelSettingsKey(apiData?.selector, apiData?.channel?.name);
if (settingKey && state.session.login && state.session.storagePwdInMemory) {
void authService.upsertUserSetting({
login: state.session.login,
settingType: 1,
settingKey,
timeMs: Date.now(),
valueText: '',
valueNum: lastSeenCount,
storagePwd: state.session.storagePwdInMemory,
}).catch(() => {});
}
const titleLabel = apiData?.channel?.displayTitle || apiData?.channel?.name || 'channel';
const entrypointPosts = getEntrypointPosts(apiData?.posts);
const openEntrypointHistory = () => {