Mercurial Hosting > chat
comparison src/chat.js @ 59:8270106644db
add chat.luan
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Tue, 04 Mar 2025 08:22:45 -0700 |
| parents | 323ddacc1593 |
| children | 3521166513b3 |
comparison
equal
deleted
inserted
replaced
| 58:7b6691bd65c3 | 59:8270106644db |
|---|---|
| 14 function setUserEventSource(userId) { | 14 function setUserEventSource(userId) { |
| 15 let userEventSource = new EventSource(`${location.origin}/user/${userId}`); | 15 let userEventSource = new EventSource(`${location.origin}/user/${userId}`); |
| 16 userEventSource.onmessage = evalEvent; | 16 userEventSource.onmessage = evalEvent; |
| 17 } | 17 } |
| 18 | 18 |
| 19 function selectChat(div,email) { | 19 function selectChat(chatId) { |
| 20 document.querySelector('div[chat_content]').setAttribute('show','posts'); | 20 document.querySelector('div[chat_content]').setAttribute('show','posts'); |
| 21 let chatId = div.getAttribute('chat'); | |
| 22 if( chatId === currentChatId ) | 21 if( chatId === currentChatId ) |
| 23 return; | 22 return; |
| 23 let div = document.querySelector(`div[chat="${chatId}"]`); | |
| 24 let selected = div.parentNode.querySelector('[selected]'); | 24 let selected = div.parentNode.querySelector('[selected]'); |
| 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,`?chat=${chatId}`); |
| 30 clearUnread(); | 30 clearUnread(); |
| 31 | 31 |
| 32 if(eventSource) eventSource.close(); | 32 if(eventSource) eventSource.close(); |
| 33 eventSource = new EventSource(`${location.origin}/chat/${chatId}`); | 33 eventSource = new EventSource(`${location.origin}/chat/${chatId}`); |
| 34 eventSource.onmessage = evalEvent; | 34 eventSource.onmessage = evalEvent; |
