feat: дата и время сообщений в чате
Каждое сообщение показывает timestamp (дд.мм.гг, чч:мм). Новые сообщения — текущее время, история — из БД. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+14
-5
@@ -43,7 +43,8 @@ body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Robo
|
||||
.header-actions button:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); }
|
||||
|
||||
#messages { flex: 1; overflow-y: auto; padding: 1.2rem 1rem; display: flex; flex-direction: column; gap: .7rem; max-width: 900px; width: 100%; margin: 0 auto; }
|
||||
.msg { max-width: 85%; padding: .8rem 1.1rem; border-radius: var(--radius-lg); line-height: 1.6; white-space: pre-wrap; word-break: break-word; font-size: .9rem; box-shadow: var(--shadow-sm); }
|
||||
.msg { max-width: 85%; padding: .8rem 1.1rem; border-radius: var(--radius-lg); line-height: 1.6; white-space: pre-wrap; word-break: break-word; font-size: .9rem; box-shadow: var(--shadow-sm); position: relative; }
|
||||
.msg-time { display: block; font-size: .65rem; color: var(--text-muted, #999); margin-bottom: .3rem; opacity: .7; }
|
||||
.msg-user { align-self: flex-end; background: var(--user-bg); color: var(--user-text); border-bottom-right-radius: 4px; }
|
||||
.msg-ai { align-self: flex-start; background: var(--ai-bg); border: 1px solid var(--ai-border); border-bottom-left-radius: 4px; }
|
||||
|
||||
@@ -210,15 +211,23 @@ function authHeaders() {
|
||||
|
||||
// --- Messages ---
|
||||
const msgs = document.getElementById('messages');
|
||||
function addMsg(type, text) {
|
||||
function addMsg(type, text, ts) {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'msg msg-' + type;
|
||||
// Timestamp
|
||||
const time = document.createElement('span');
|
||||
time.className = 'msg-time';
|
||||
const d = ts ? new Date(ts < 1e12 ? ts * 1000 : ts) : new Date();
|
||||
time.textContent = d.toLocaleString('ru-RU', {day:'2-digit',month:'2-digit',year:'2-digit',hour:'2-digit',minute:'2-digit'});
|
||||
div.appendChild(time);
|
||||
// Store raw text for copy and streaming
|
||||
div._rawText = text;
|
||||
if (type === 'ai') {
|
||||
div.innerHTML = renderMarkdown(text);
|
||||
div.prepend(time);
|
||||
} else {
|
||||
div.textContent = text;
|
||||
div.prepend(time);
|
||||
}
|
||||
if (type !== 'system') {
|
||||
const btn = document.createElement('button');
|
||||
@@ -446,9 +455,9 @@ async function loadHistory() {
|
||||
if (history.length === 0) return;
|
||||
msgs.innerHTML = '';
|
||||
for (const m of history) {
|
||||
if (m.role === 'user') addMsg('user', m.content);
|
||||
else if (m.role === 'assistant') addMsg('ai', m.content);
|
||||
else if (m.role === 'system') addMsg('system', m.content);
|
||||
if (m.role === 'user') addMsg('user', m.content, m.timestamp);
|
||||
else if (m.role === 'assistant') addMsg('ai', m.content, m.timestamp);
|
||||
else if (m.role === 'system') addMsg('system', m.content, m.timestamp);
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user