Chat history.

This commit is contained in:
2026-02-14 22:29:32 -05:00
parent 766510132b
commit 2e8672fc9e
3 changed files with 47 additions and 2 deletions

View File

@@ -31,8 +31,8 @@
<div id="bottom_text">
<i>COMS</i> by Jacob Signorovitch.
<a href="#" id="help">Help</a> |
<a href="//signorovitch.org">Code</a> |
<a href="//signorovitch.org">API</a>
<a href="//git.signorovitch.org/jacob/coms">Code</a> |
<a href="#">API</a>
</div>
</div>
</div>

View File

@@ -12,6 +12,7 @@ import {
updateUser,
getGroupedUsers,
setMyId,
clearData,
users,
setFocused,
setReplyTo,
@@ -49,11 +50,25 @@ export function initWebSocket(username, chatEl, inputContainer, usersListEl) {
case "welcome": {
// Initial user list.
const myId = packet.data.you;
clearData();
setMyId(myId);
const users = packet.data.users || [];
users.forEach(({ id, username }) => addUser(id, username));
const groups = getGroupedUsers();
usersListEl.innerHTML = "Online: " + groups.join(", ");
// Replay chat history.
const history = packet.data.history || [];
history.forEach((raw) => {
try {
const histPkt = JSON.parse(raw);
if (histPkt.type === "msg-event") {
const { id, username: u, content, ts, parent } = histPkt.data;
addMessage({ id, username: u, content, ts, parent });
}
} catch (e) {
console.error("Invalid history entry", raw);
}
});
//addNotice(`<i>Users online: ${groups.join(", ")}</i>`);
break;
}