Spaces:
Running
Running
Update chat.html
Browse files
chat.html
CHANGED
|
@@ -244,23 +244,28 @@ async function clearChat() {
|
|
| 244 |
}
|
| 245 |
|
| 246 |
function renderMessages(msgs, clear = true) {
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
}
|
| 263 |
|
|
|
|
| 264 |
setInterval(loadNewMessages, 2000);
|
| 265 |
loadMessages();
|
| 266 |
</script>
|
|
|
|
| 244 |
}
|
| 245 |
|
| 246 |
function renderMessages(msgs, clear = true) {
|
| 247 |
+
if (clear) messagesDiv.innerHTML = '';
|
| 248 |
+
msgs.forEach(m => {
|
| 249 |
+
// если это уже было добавлено — пропускаем
|
| 250 |
+
if (document.getElementById('msg-' + m.id)) return;
|
| 251 |
+
|
| 252 |
+
lastId = Math.max(lastId, m.id);
|
| 253 |
+
let decrypted = '[🔒 Сообщение зашифровано]';
|
| 254 |
+
if (encryptionKey) {
|
| 255 |
+
try {
|
| 256 |
+
decrypted = CryptoJS.AES.decrypt(m.encrypted_text, encryptionKey).toString(CryptoJS.enc.Utf8) || decrypted;
|
| 257 |
+
} catch {}
|
| 258 |
+
}
|
| 259 |
+
const div = document.createElement('div');
|
| 260 |
+
div.id = 'msg-' + m.id; // уникальный ID для проверки
|
| 261 |
+
div.className = 'message ' + (m.user_id === userId ? 'own' : 'other');
|
| 262 |
+
div.innerHTML = `<div><b>${m.username}</b> • ${m.timestamp}</div><div>${decrypted}</div>`;
|
| 263 |
+
messagesDiv.appendChild(div);
|
| 264 |
+
});
|
| 265 |
+
messagesDiv.scrollTop = messagesDiv.scrollHeight;
|
| 266 |
}
|
| 267 |
|
| 268 |
+
|
| 269 |
setInterval(loadNewMessages, 2000);
|
| 270 |
loadMessages();
|
| 271 |
</script>
|