Mercurial Hosting > chat
diff src/chat.js @ 30:f4708943f29e
add heartbeat
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 09 Nov 2024 19:17:21 -0700 |
parents | 809193524522 |
children | a0820965ba04 |
line wrap: on
line diff
--- a/src/chat.js Wed Nov 06 23:05:45 2024 -0700 +++ b/src/chat.js Sat Nov 09 19:17:21 2024 -0700 @@ -3,6 +3,7 @@ let title = document.title; let currentChatId = null; let eventSource; +let lastUpdate; function evalEvent(event) { // console.log(event); @@ -143,12 +144,14 @@ document.title = title + ' *'; } -function getChats(chatId) { +function getChats(chatId,updated) { let first = document.querySelector('div[chat]'); if( !first || first.getAttribute('chat') != chatId ) { // console.log('getChats'); ajax('get_chats.js'); } + if( updated ) + lastUpdate = updated; } function gotChats(html) { @@ -197,3 +200,14 @@ pulldown.scrollIntoViewIfNeeded(false); } } + +setInterval(function(){ + ajax(`heartbeat.js?last_update=${lastUpdate}`); +}, 60000 ); + +function resync(updated) { + lastUpdate = updated; + currentChatId = null; + document.querySelector('div[posts]').innerHTML = ''; + ajax('get_chats.js'); +}