Mercurial Hosting > chat
comparison src/chat.js @ 89:3053a4fc10be
spy
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 13 Mar 2025 17:56:39 -0600 |
parents | 7b339b1ccd11 |
children | c41e200c3e76 |
comparison
equal
deleted
inserted
replaced
88:7b339b1ccd11 | 89:3053a4fc10be |
---|---|
4 let currentChatId = null; | 4 let currentChatId = null; |
5 let eventSource; | 5 let eventSource; |
6 let lastUpdate = Date.now(); | 6 let lastUpdate = Date.now(); |
7 let userId; | 7 let userId; |
8 let filebinUrl; | 8 let filebinUrl; |
9 let spy; | |
9 | 10 |
10 function evalEvent(event) { | 11 function evalEvent(event) { |
11 // console.log(event); | 12 // console.log(event); |
12 eval(event.data); | 13 eval(event.data); |
13 } | 14 } |
189 function getChats(chatId,updated) { | 190 function getChats(chatId,updated) { |
190 let first = document.querySelector('div[chat]'); | 191 let first = document.querySelector('div[chat]'); |
191 if( !first || first.getAttribute('chat') !== chatId ) { | 192 if( !first || first.getAttribute('chat') !== chatId ) { |
192 // console.log('getChats'); | 193 // console.log('getChats'); |
193 ajax('get_chats.js'); | 194 ajax('get_chats.js'); |
194 } else if( first && currentChatId !== chatId ) { | 195 } else if( first && (currentChatId !== chatId || spy) ) { |
195 incUnread(first); | 196 incUnread(first); |
196 } | 197 } |
197 if( updated ) | 198 if( updated ) |
198 lastUpdate = updated; | 199 lastUpdate = updated; |
199 if( !document.hasFocus() ) { | 200 if( !document.hasFocus() ) { |
276 span.setAttribute('is_online',isOnline); | 277 span.setAttribute('is_online',isOnline); |
277 } | 278 } |
278 } | 279 } |
279 | 280 |
280 function clearUnread() { | 281 function clearUnread() { |
282 if( spy ) return; | |
281 let span = document.querySelector(`div[chat="${currentChatId}"] span[unread]`); | 283 let span = document.querySelector(`div[chat="${currentChatId}"] span[unread]`); |
282 span.setAttribute('unread','0'); | 284 span.setAttribute('unread','0'); |
283 span.textContent = '0'; | 285 span.textContent = '0'; |
284 } | 286 } |
285 | 287 |
379 //console.log(`readUpTo ${unread}`); | 381 //console.log(`readUpTo ${unread}`); |
380 let divs = document.querySelectorAll('div[post]'); | 382 let divs = document.querySelectorAll('div[post]'); |
381 if( unread >= divs.length ) | 383 if( unread >= divs.length ) |
382 return; | 384 return; |
383 let div = divs[divs.length - unread - 1]; | 385 let div = divs[divs.length - unread - 1]; |
384 let old = document.querySelector(`div[unread][user="${userId}"]`); | 386 let old = document.querySelector(`div[up_to][user="${userId}"]`); |
385 if( old ) { | 387 if( old ) { |
386 //console.log(`was ${div.getAttribute('unread')}`); | 388 //console.log(`was ${div.getAttribute('up_to')}`); |
387 if( div == old.parentNode ) | 389 if( div == old.parentNode ) |
388 return; | 390 return; |
389 old.outerHTML = ''; | 391 old.outerHTML = ''; |
390 } | 392 } |
391 //console.log('readUpTo'); | 393 //console.log('readUpTo'); |
392 let html = `<div user="${userId}" unread="${unread}">read by ${userNameHtml}</div>`; | 394 let html = `<div user="${userId}" up_to="${unread}">read by ${userNameHtml}</div>`; |
393 div.insertAdjacentHTML('beforeend',html); | 395 div.insertAdjacentHTML('beforeend',html); |
394 if( !old ) { | 396 if( !old ) { |
395 let dy = document.querySelector('div[unread]').clientHeight; | 397 let dy = document.querySelector('div[up_to]').clientHeight; |
396 document.querySelector('div[main]').scrollBy(0,dy); | 398 document.querySelector('div[main]').scrollBy(0,dy); |
397 } | 399 } |
398 } | 400 } |
399 | 401 |
400 function replyPost(el) { | 402 function replyPost(el) { |