comparison src/chat.js @ 30:f4708943f29e

add heartbeat
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 09 Nov 2024 19:17:21 -0700 (4 months ago)
parents 809193524522
children a0820965ba04
comparison
equal deleted inserted replaced
29:5beadcd541aa 30:f4708943f29e
1 'use strict'; 1 'use strict';
2 2
3 let title = document.title; 3 let title = document.title;
4 let currentChatId = null; 4 let currentChatId = null;
5 let eventSource; 5 let eventSource;
6 let lastUpdate;
6 7
7 function evalEvent(event) { 8 function evalEvent(event) {
8 // console.log(event); 9 // console.log(event);
9 eval(event.data); 10 eval(event.data);
10 } 11 }
141 input.scrollIntoView({block: 'end'}); 142 input.scrollIntoView({block: 'end'});
142 if( !document.hasFocus() ) 143 if( !document.hasFocus() )
143 document.title = title + ' *'; 144 document.title = title + ' *';
144 } 145 }
145 146
146 function getChats(chatId) { 147 function getChats(chatId,updated) {
147 let first = document.querySelector('div[chat]'); 148 let first = document.querySelector('div[chat]');
148 if( !first || first.getAttribute('chat') != chatId ) { 149 if( !first || first.getAttribute('chat') != chatId ) {
149 // console.log('getChats'); 150 // console.log('getChats');
150 ajax('get_chats.js'); 151 ajax('get_chats.js');
151 } 152 }
153 if( updated )
154 lastUpdate = updated;
152 } 155 }
153 156
154 function gotChats(html) { 157 function gotChats(html) {
155 document.querySelector('div[chats]').innerHTML = html; 158 document.querySelector('div[chats]').innerHTML = html;
156 if( currentChatId ) { 159 if( currentChatId ) {
195 newPulldown = null; 198 newPulldown = null;
196 }; 199 };
197 pulldown.scrollIntoViewIfNeeded(false); 200 pulldown.scrollIntoViewIfNeeded(false);
198 } 201 }
199 } 202 }
203
204 setInterval(function(){
205 ajax(`heartbeat.js?last_update=${lastUpdate}`);
206 }, 60000 );
207
208 function resync(updated) {
209 lastUpdate = updated;
210 currentChatId = null;
211 document.querySelector('div[posts]').innerHTML = '';
212 ajax('get_chats.js');
213 }