Chat history.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user