Mercurial Hosting > chat
comparison src/chat.js @ 53:9298b04607ae
add unread
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Mon, 03 Mar 2025 19:39:30 -0700 |
| parents | 7628fd0e3560 |
| children | 1d724f187cff |
comparison
equal
deleted
inserted
replaced
| 52:c3fabb21b6c4 | 53:9298b04607ae |
|---|---|
| 25 if( selected ) selected.removeAttribute('selected'); | 25 if( selected ) selected.removeAttribute('selected'); |
| 26 div.setAttribute('selected',''); | 26 div.setAttribute('selected',''); |
| 27 ajax(`get_chat.js?chat=${chatId}`); | 27 ajax(`get_chat.js?chat=${chatId}`); |
| 28 currentChatId = chatId; | 28 currentChatId = chatId; |
| 29 history.replaceState(null,null,`?with=${email}`); | 29 history.replaceState(null,null,`?with=${email}`); |
| 30 clearUnread(); | |
| 30 | 31 |
| 31 if(eventSource) eventSource.close(); | 32 if(eventSource) eventSource.close(); |
| 32 eventSource = new EventSource(`${location.origin}/chat/${chatId}`); | 33 eventSource = new EventSource(`${location.origin}/chat/${chatId}`); |
| 33 eventSource.onmessage = evalEvent; | 34 eventSource.onmessage = evalEvent; |
| 34 } | 35 } |
| 155 ajax('active.js'); | 156 ajax('active.js'); |
| 156 } | 157 } |
| 157 | 158 |
| 158 function getChats(chatId,updated) { | 159 function getChats(chatId,updated) { |
| 159 let first = document.querySelector('div[chat]'); | 160 let first = document.querySelector('div[chat]'); |
| 160 if( !first || first.getAttribute('chat') != chatId ) { | 161 if( !first || first.getAttribute('chat') !== chatId ) { |
| 161 // console.log('getChats'); | 162 // console.log('getChats'); |
| 162 ajax('get_chats.js'); | 163 ajax('get_chats.js'); |
| 164 } else if( first && currentChatId !== chatId ) { | |
| 165 incUnread(first); | |
| 163 } | 166 } |
| 164 if( updated ) | 167 if( updated ) |
| 165 lastUpdate = updated; | 168 lastUpdate = updated; |
| 166 if( !document.hasFocus() ) { | 169 if( !document.hasFocus() ) { |
| 167 document.title = title + ' *'; | 170 document.title = title + ' *'; |
| 249 background-color: green; | 252 background-color: green; |
| 250 } | 253 } |
| 251 ` ; | 254 ` ; |
| 252 } | 255 } |
| 253 } | 256 } |
| 257 | |
| 258 function clearUnread() { | |
| 259 let span = document.querySelector(`div[chat="${currentChatId}"] span[unread]`); | |
| 260 span.setAttribute('unread','0'); | |
| 261 span.textContent = '0'; | |
| 262 } | |
| 263 | |
| 264 function incUnread(div) { | |
| 265 let span = div.querySelector('span[unread]'); | |
| 266 let n = parseInt(span.getAttribute('unread')) + 1; | |
| 267 span.setAttribute('unread',n); | |
| 268 span.textContent = n; | |
| 269 } |
