feature: favicon
fix: partial attempt to clean up room loading
This commit is contained in:
parent
5d244f65c7
commit
be84aef1e0
10 changed files with 25 additions and 6 deletions
|
@ -2,7 +2,7 @@
|
|||
window.addEventListener("locationchange", () => {
|
||||
const hash = window.location.hash?.slice(1);
|
||||
if (hash) {
|
||||
const target_tab_url = hash.slice(0, hash.slice(1).indexOf("/"));
|
||||
const target_tab_url = hash.slice(0, hash.slice(1).indexOf("/") + 1);
|
||||
const target_tab = document.querySelector(`[data-hash="${target_tab_url}"]`);
|
||||
console.dir({
|
||||
hash,
|
||||
|
|
|
@ -229,12 +229,23 @@
|
|||
const room_id = room_chat_content.dataset.room_id;
|
||||
const last_message_id = room_chat_content.dataset.last_message_id;
|
||||
|
||||
if (!room_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
const message_polling_url = `/rooms/${room_id}/events?type=chat&limit=100&sort=newest&wait=true${last_message_id ? `&after_id=${last_message_id}` : ""}`;
|
||||
|
||||
room_polling_request_abort_controller =
|
||||
room_polling_request_abort_controller || new AbortController();
|
||||
|
||||
api.fetch(message_polling_url, {
|
||||
signal: room_polling_request_abort_controller.signal,
|
||||
})
|
||||
.then((new_events) => {
|
||||
console.dir({
|
||||
room_id,
|
||||
new_events,
|
||||
});
|
||||
append_room_events(new_events);
|
||||
poll_for_new_events(room_id);
|
||||
})
|
||||
|
@ -245,6 +256,8 @@
|
|||
}
|
||||
|
||||
async function load_room(room_id) {
|
||||
const room_chat_content = document.getElementById("room-chat-content");
|
||||
|
||||
if (room_polling_request_abort_controller) {
|
||||
room_polling_request_abort_controller.abort();
|
||||
room_polling_request_abort_controller = null;
|
||||
|
@ -259,7 +272,6 @@
|
|||
}
|
||||
|
||||
const room = await room_response.json();
|
||||
const room_chat_content = document.getElementById("room-chat-content");
|
||||
|
||||
room_chat_content.dataset.room_id = room.id;
|
||||
room_chat_content.innerHTML = "";
|
||||
|
@ -328,14 +340,15 @@
|
|||
const room_id = hash.substring(12) || first_room_id;
|
||||
|
||||
if (!room_id) {
|
||||
alert("failed to load chat room!");
|
||||
return;
|
||||
}
|
||||
|
||||
const room_chat_container = document.getElementById("room-chat-container");
|
||||
room_chat_container.dataset.room_id = room_id;
|
||||
|
||||
load_room(room_id);
|
||||
if (room_chat_container.dataset.room_id !== room_id) {
|
||||
room_chat_container.dataset.room_id = room_id;
|
||||
load_room(room_id);
|
||||
}
|
||||
}
|
||||
window.addEventListener("locationchange", check_for_room_in_url);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue