Files
SHiNE-server/old-frame-v1/shine-UI/js/services/channel-view-state.js
T

26 lines
1.3 KiB
JavaScript

// Состояние чтения живёт только в текущей вкладке и разделено по аккаунтам.
const positions = new Map();
export function rememberChannelPosition(key) {
positions.set(key, document.getElementById('app-screen')?.scrollTop || 0);
}
export function readChannelPosition(key) { return positions.get(key); }
export function restoreChannelPosition(value) {
const root = document.getElementById('app-screen');
if (root && Number.isFinite(value)) root.scrollTop = value;
}
// «Открыть обсуждение» из ленты ведёт сразу в редактор ответа: лента отмечает путь, обсуждение забирает отметку один раз.
let replyOnOpenPath = '';
const normalizePath = (path) => {
const raw = String(path || '').split(/[?#]/)[0];
let decoded = raw;
try { decoded = decodeURIComponent(raw); } catch { /* оставляем как есть */ }
return decoded.replace(/^\/+|\/+$/g, '').toLowerCase();
};
export function requestReplyEditorOnOpen(path) { replyOnOpenPath = normalizePath(path); }
export function consumeReplyEditorOnOpen(path) {
const match = Boolean(replyOnOpenPath) && replyOnOpenPath === normalizePath(path);
replyOnOpenPath = '';
return match;
}