fix: load users correctly on initial chat load

This commit is contained in:
Andy Burke 2025-07-04 15:38:30 -07:00
parent cfa35f6421
commit 8561b0cce2
2 changed files with 9 additions and 4 deletions

View file

@ -27,7 +27,6 @@
/* check if we are logged in */
(async () => {
try {
console.log( 'hi');
const session_response = await api.fetch("/api/users/me");
if (!session_response.ok) {

View file

@ -190,9 +190,9 @@
return new_room_element;
}
const users = {};
async function append_room_events(events) {
const room_chat_content = document.getElementById("room-chat-content");
const users = {};
let last_message_id = undefined;
for (const event of events) {
// if the last message is undefined, it becomes this event, otherwise, if this event's id is newer,
@ -211,8 +211,12 @@
users[event.creator_id] =
users[event.creator_id] ??
(await api.fetch(`/api/users/${event.creator_id}`));
(await (await api.fetch(`/api/users/${event.creator_id}`)).json());
console.dir({
users,
events,
});
room_chat_content.insertAdjacentHTML(
"beforeend",
render_text_event(event, users[event.creator_id]),
@ -241,9 +245,11 @@
api.fetch(message_polling_url, {
signal: room_polling_request_abort_controller.signal,
})
.then((new_events) => {
.then(async (new_events_response) => {
const new_events = await new_events_response.json();
console.dir({
room_id,
new_events_response,
new_events,
});
append_room_events(new_events);