diff src/chat.js @ 40:7ea33179592a

email notification
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 27 Feb 2025 16:44:20 -0700
parents 471b13e6ce2c
children e09747b199e9
line wrap: on
line diff
--- a/src/chat.js	Sun Nov 17 12:06:08 2024 -0700
+++ b/src/chat.js	Thu Feb 27 16:44:20 2025 -0700
@@ -4,7 +4,6 @@
 let currentChatId = null;
 let eventSource;
 let lastUpdate;
-let hasUnseen = false;
 let userId;
 
 function evalEvent(event) {
@@ -153,6 +152,8 @@
 	input.insertAdjacentHTML('beforebegin',html);
 	fixPosts();
 	input.scrollIntoView({block: 'end'});
+	if( document.hasFocus() )
+		ajax('active.js');
 }
 
 function getChats(chatId,updated) {
@@ -163,10 +164,8 @@
 	}
 	if( updated )
 		lastUpdate = updated;
-	if( !document.hasFocus() && !hasUnseen ) {
+	if( !document.hasFocus() ) {
 		document.title = title + ' *';
-		notify();
-		hasUnseen = true;
 	}
 }
 
@@ -187,13 +186,13 @@
 window.onfocus = function() {
 	// console.log('onfocus');
 	document.title = title;
-	hasUnseen = false;
+	ajax('active.js');
 };
 
 let urlRegex = /(^|\s)(https?:\/\/\S+)/g;
 
 function urlsToLinks(text) {
-	return text.replace( urlRegex, '$1<a href="$2">$2</a>' );
+	return text.replace( urlRegex, '$1<a target="_blank" href="$2">$2</a>' );
 }
 
 let currentPulldown = null;
@@ -224,11 +223,6 @@
 	ajax(`heartbeat.js?last_update=${lastUpdate}`);
 }, 10000 );
 
-let sound = new Audio('/images/notify.mp3');
-function notify() {
-	sound.play();
-}
-
 let online = {};
 
 function setOnline(userId) {