diff 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
line wrap: on
line diff
--- a/src/chat.js	Thu Mar 13 16:18:39 2025 -0600
+++ b/src/chat.js	Thu Mar 13 17:56:39 2025 -0600
@@ -6,6 +6,7 @@
 let lastUpdate = Date.now();
 let userId;
 let filebinUrl;
+let spy;
 
 function evalEvent(event) {
 	// console.log(event);
@@ -191,7 +192,7 @@
 	if( !first || first.getAttribute('chat') !== chatId ) {
 		// console.log('getChats');
 		ajax('get_chats.js');
-	} else if( first && currentChatId !== chatId ) {
+	} else if( first && (currentChatId !== chatId || spy) ) {
 		incUnread(first);
 	}
 	if( updated )
@@ -278,6 +279,7 @@
 }
 
 function clearUnread() {
+	if( spy )  return;
 	let span = document.querySelector(`div[chat="${currentChatId}"] span[unread]`);
 	span.setAttribute('unread','0');
 	span.textContent = '0';
@@ -381,18 +383,18 @@
 	if( unread >= divs.length )
 		return;
 	let div = divs[divs.length - unread - 1];
-	let old = document.querySelector(`div[unread][user="${userId}"]`);
+	let old = document.querySelector(`div[up_to][user="${userId}"]`);
 	if( old ) {
-		//console.log(`was ${div.getAttribute('unread')}`);
+		//console.log(`was ${div.getAttribute('up_to')}`);
 		if( div == old.parentNode )
 			return;
 		old.outerHTML = '';
 	}
 	//console.log('readUpTo');
-	let html = `<div user="${userId}" unread="${unread}">read by ${userNameHtml}</div>`;
+	let html = `<div user="${userId}" up_to="${unread}">read by ${userNameHtml}</div>`;
 	div.insertAdjacentHTML('beforeend',html);
 	if( !old ) {
-		let dy = document.querySelector('div[unread]').clientHeight;
+		let dy = document.querySelector('div[up_to]').clientHeight;
 		document.querySelector('div[main]').scrollBy(0,dy);
 	}
 }