SHA256
Улучшить ссылки и прокрутку личных чатов
This commit is contained in:
@@ -285,6 +285,43 @@ function openChatConfirmModal({
|
||||
});
|
||||
}
|
||||
|
||||
function openExternalLinkModal(href) {
|
||||
const root = document.getElementById('modal-root');
|
||||
const url = String(href || '').trim();
|
||||
if (!root || !/^https?:\/\//i.test(url)) return;
|
||||
root.innerHTML = `
|
||||
<div class="modal" id="chat-external-link-modal">
|
||||
<div class="modal-card stack" role="dialog" aria-modal="true" aria-labelledby="chat-external-link-title">
|
||||
<h3 class="modal-title" id="chat-external-link-title">${t('chat_links.title')}</h3>
|
||||
<p class="meta-muted">${t('chat_links.description')}</p>
|
||||
<p class="chat-external-link-url"></p>
|
||||
<div class="form-actions-grid">
|
||||
<button class="secondary-btn" type="button" id="chat-external-link-copy">${t('chat_links.copy')}</button>
|
||||
<button class="primary-btn" type="button" id="chat-external-link-open">${t('chat_links.open')}</button>
|
||||
<button class="secondary-btn" type="button" id="chat-external-link-cancel">${t('chat_links.cancel')}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
root.querySelector('.chat-external-link-url').textContent = url;
|
||||
const close = () => { root.innerHTML = ''; };
|
||||
root.querySelector('#chat-external-link-cancel')?.addEventListener('click', close);
|
||||
root.querySelector('#chat-external-link-open')?.addEventListener('click', () => {
|
||||
window.open(url, '_blank', 'noopener,noreferrer');
|
||||
close();
|
||||
});
|
||||
root.querySelector('#chat-external-link-copy')?.addEventListener('click', async () => {
|
||||
try {
|
||||
if (!navigator?.clipboard?.writeText) throw new Error('clipboard_unavailable');
|
||||
await navigator.clipboard.writeText(url);
|
||||
close();
|
||||
showToast(t('chat_links.copied'), { timeoutMs: 1200 });
|
||||
} catch {
|
||||
showToast(t('chat_links.copy_failed'), { kind: 'error', timeoutMs: 1600 });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Календарь «перейти к дате»: активны только дни, в которые была переписка.
|
||||
// days – Map dayKey → { timeMs, count }; список можно обновить, пока догружается история.
|
||||
// «октябрь 2026 г.» → «Октябрь 2026 г.» (CSS capitalize сделал бы «Г.»)
|
||||
@@ -965,6 +1002,7 @@ function renderMessageText(textNode, messageText, chatNavigate) {
|
||||
}
|
||||
appendShineMessageLinks(textNode, text, {
|
||||
navigate: chatNavigate,
|
||||
onExternalLink: ({ href }) => openExternalLinkModal(href),
|
||||
appendText: (root, part) => {
|
||||
const fragment = document.createDocumentFragment();
|
||||
if (appendTwemojiText(fragment, part, { className: 'chat-twemoji chat-twemoji--inline' })) {
|
||||
@@ -2811,18 +2849,30 @@ export function render({ navigate, route, chrome }) {
|
||||
// Вся история уже в памяти (её загрузил поиск или «Медиа и файлы») – листать сервер дальше незачем.
|
||||
if (isDmHistoryFullyLoaded(chatId)) historyHasMore = false;
|
||||
else if (!historyHasMore) markDmHistoryFullyLoaded(chatId);
|
||||
let scrollModeAfterLoad = isBootstrap ? 'latest' : (preserveScroll ? 'preserve' : 'latest');
|
||||
if (isBootstrap) {
|
||||
const firstUnread = getChatMessages(chatId).find((msg) => msg?.from === 'in' && msg?.unread);
|
||||
if (firstUnread?.messageKey) {
|
||||
unreadSeparatorVisible = true;
|
||||
unreadSeparatorAnchorMessageKey = String(firstUnread.messageKey);
|
||||
stickToBottom = false;
|
||||
scrollModeAfterLoad = 'unread';
|
||||
}
|
||||
}
|
||||
// Страница уже была в памяти: перерисовка не нужна, лента не дёргается.
|
||||
if (messagesBefore === JSON.stringify(getChatMessages(chatId))) {
|
||||
pageAddedNothing = true;
|
||||
void sendReadReceiptsForVisible(chatId);
|
||||
return;
|
||||
}
|
||||
renderChatLog({ markAsRead: false, scrollMode: preserveScroll ? 'preserve' : 'latest' });
|
||||
if (preserveScroll) {
|
||||
renderChatLog({ markAsRead: false, scrollMode: scrollModeAfterLoad });
|
||||
if (scrollModeAfterLoad === 'preserve') {
|
||||
window.requestAnimationFrame(() => {
|
||||
const nextHeight = Number(scrollContainer?.scrollHeight || 0);
|
||||
scrollContainer.scrollTop = Math.max(0, prevScrollTop + (nextHeight - prevScrollHeight));
|
||||
});
|
||||
} else if (scrollModeAfterLoad === 'unread') {
|
||||
window.requestAnimationFrame(() => scrollToUnreadSeparator(log));
|
||||
} else {
|
||||
window.requestAnimationFrame(() => scrollToLatestMessage(log));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user