UI: DM список метаданных и Enter/Ctrl+Enter в чате

This commit is contained in:
AidarKC
2026-05-19 15:50:42 +03:00
parent c6d310184b
commit 8325cbec84
5 changed files with 74 additions and 6 deletions
+17 -4
View File
@@ -11,6 +11,17 @@ import { loadCurrentRelations } from '../services/user-connections.js';
export const pageMeta = { id: 'messages-list', title: 'Личные сообщения' };
function formatChatRowTime(ts) {
const value = Number(ts || 0);
if (!Number.isFinite(value) || value <= 0) return '-';
return new Intl.DateTimeFormat('ru-RU', {
day: '2-digit',
month: '2-digit',
hour: '2-digit',
minute: '2-digit',
}).format(new Date(value));
}
export function render({ navigate }) {
const screen = document.createElement('section');
screen.className = 'stack dm-screen dm-list-screen';
@@ -38,9 +49,9 @@ export function render({ navigate }) {
</div>
<p class="meta-muted" style="margin-top:4px;">${item.lastMessage}</p>
</div>
<div style="display:grid; justify-items:end; gap:6px;">
<span class="meta-muted">${item.time}</span>
<div class="dm-row-meta-col">
${item.unread ? `<span class="unread">${item.unread}</span>` : '<span></span>'}
<span class="meta-muted dm-row-time">${item.time}</span>
</div>
`;
row.addEventListener('click', () => navigate(`chat-view/${encodeURIComponent(item.id)}`));
@@ -59,12 +70,13 @@ export function render({ navigate }) {
const chat = getChatMessages(login);
const lastChat = chat[chat.length - 1];
const unread = chat.filter((m) => m?.from === 'in' && m?.unread).length;
const lastTimeMs = Number(lastChat?.createdAtMs || 0);
return {
id: login,
initials: (login[0] || '?').toUpperCase(),
name: preview?.name || login,
lastMessage: lastChat?.text || preview?.lastMessage || 'Диалог пока пуст.',
time: preview?.time || '—',
time: formatChatRowTime(lastTimeMs),
unread,
notInContacts: false,
};
@@ -81,12 +93,13 @@ export function render({ navigate }) {
const chat = getChatMessages(login);
const lastChat = chat[chat.length - 1];
const unread = chat.filter((m) => m?.from === 'in' && m?.unread).length;
const lastTimeMs = Number(lastChat?.createdAtMs || 0);
return {
id: login,
initials: (login[0] || '?').toUpperCase(),
name: login,
lastMessage: lastChat?.text || 'Диалог пока пуст.',
time: 'сейчас',
time: formatChatRowTime(lastTimeMs),
unread,
notInContacts: true,
};