changeset 89:3053a4fc10be

spy
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 13 Mar 2025 17:56:39 -0600
parents 7b339b1ccd11
children 5240c054dcd4
files src/active.js.luan src/chat.css src/chat.js src/do_login.html.luan src/get_chat.js.luan src/heartbeat.js.luan src/index.html.luan src/private/tools/users.html.luan
diffstat 8 files changed, 31 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/active.js.luan	Thu Mar 13 16:18:39 2025 -0600
+++ b/src/active.js.luan	Thu Mar 13 17:56:39 2025 -0600
@@ -10,6 +10,10 @@
 
 
 return function()
+	local spy = Http.request.cookies.spy ~= nil
+	if spy then
+		return
+	end
 	local user = current_user() or error()
 	remove_notify(user)
 	local chat = Http.request.parameters.chat
--- a/src/chat.css	Thu Mar 13 16:18:39 2025 -0600
+++ b/src/chat.css	Thu Mar 13 17:56:39 2025 -0600
@@ -80,7 +80,7 @@
 	max-width: 100%;
 }
 
-div[unread] {
+div[up_to] {
 	font-size: 12px;
 	color: grey;
 	text-align: right;
--- 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);
 	}
 }
--- a/src/do_login.html.luan	Thu Mar 13 16:18:39 2025 -0600
+++ b/src/do_login.html.luan	Thu Mar 13 17:56:39 2025 -0600
@@ -35,6 +35,12 @@
 <%
 	else
 		user.login()
+		local spy = Http.request.parameters.spy ~= nil
+		if spy then
+			Http.response.set_cookie("spy","yes")
+		else
+			Http.response.remove_cookie("spy")
+		end
 		local with = Http.request.parameters.with
 		local location
 		if with == nil then
--- a/src/get_chat.js.luan	Thu Mar 13 16:18:39 2025 -0600
+++ b/src/get_chat.js.luan	Thu Mar 13 17:56:39 2025 -0600
@@ -24,7 +24,10 @@
 
 
 local function get_html(user,chat)
-	chat.read(user)
+	local spy = Http.request.cookies.spy ~= nil
+	if not spy then
+		chat.read(user)
+	end
 	local posts = post_search( "post_chat_id:"..chat.id, "id" )
 %>
 	<div top>
--- a/src/heartbeat.js.luan	Thu Mar 13 16:18:39 2025 -0600
+++ b/src/heartbeat.js.luan	Thu Mar 13 17:56:39 2025 -0600
@@ -25,7 +25,10 @@
 
 return function()
 	local user = current_user() or error()
-	set_online(user)
+	local spy = Http.request.cookies.spy ~= nil
+	if not spy then
+		set_online(user)
+	end
 	Io.stdout = Http.response.text_writer()
 
 	local last_update = Http.request.parameters.last_update or error()
--- a/src/index.html.luan	Thu Mar 13 16:18:39 2025 -0600
+++ b/src/index.html.luan	Thu Mar 13 17:56:39 2025 -0600
@@ -130,6 +130,10 @@
 			'use strict';
 
 <%
+	local spy = Http.request.cookies.spy ~= nil
+%>
+			spy = <%=spy%>;
+<%
 	if chat ~= nil then
 %>
 			selectChat('<%=chat.id%>');
--- a/src/private/tools/users.html.luan	Thu Mar 13 16:18:39 2025 -0600
+++ b/src/private/tools/users.html.luan	Thu Mar 13 17:56:39 2025 -0600
@@ -74,7 +74,7 @@
 %>
 				<tr>
 					<td><%= user.id %></td>
-					<td><a href="<%=user.login_url()%>"><%= user.name_html() %></a></td>
+					<td><a href="<%=user.login_url()%>&spy"><%= user.name_html() %></a></td>
 					<td><%= ago %></td>
 				</tr>
 <%