Mercurial Hosting > chat
comparison src/chat.js @ 46:42b741a1d5c6
add username
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Fri, 28 Feb 2025 19:25:12 -0700 |
| parents | e09747b199e9 |
| children | 7628fd0e3560 |
comparison
equal
deleted
inserted
replaced
| 45:e138343b2c76 | 46:42b741a1d5c6 |
|---|---|
| 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) { | 19 function selectChat(div,email) { |
| 20 document.querySelector('div[content]').setAttribute('show','posts'); | 20 document.querySelector('div[content]').setAttribute('show','posts'); |
| 21 let chatId = div.getAttribute('chat'); | 21 let chatId = div.getAttribute('chat'); |
| 22 if( chatId === currentChatId ) | 22 if( chatId === currentChatId ) |
| 23 return; | 23 return; |
| 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 let email = div.querySelector('[email]').textContent; | |
| 30 history.replaceState(null,null,`?with=${email}`); | 29 history.replaceState(null,null,`?with=${email}`); |
| 31 | 30 |
| 32 if(eventSource) eventSource.close(); | 31 if(eventSource) eventSource.close(); |
| 33 eventSource = new EventSource(`${location.origin}/chat/${chatId}`); | 32 eventSource = new EventSource(`${location.origin}/chat/${chatId}`); |
| 34 eventSource.onmessage = evalEvent; | 33 eventSource.onmessage = evalEvent; |
