Mercurial Hosting > chat
comparison src/chat.js @ 15:8b8905f63d80
add get_chats
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 03 Nov 2024 17:36:49 -0700 |
parents | 0df3a63a895f |
children | 82b55186a4a0 |
comparison
equal
deleted
inserted
replaced
14:0df3a63a895f | 15:8b8905f63d80 |
---|---|
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 let currentChatId = null; | 3 let currentChatId = null; |
4 let eventSource; | 4 let eventSource; |
5 | |
6 function setUserEventSource(userId) { | |
7 let userEventSource = new EventSource(`${location.origin}/user/${userId}`); | |
8 userEventSource.onmessage = function(event) { | |
9 eval(event.data); | |
10 }; | |
11 } | |
5 | 12 |
6 function selectChat(div) { | 13 function selectChat(div) { |
7 let chatId = div.getAttribute('chat'); | 14 let chatId = div.getAttribute('chat'); |
8 if( chatId === currentChatId ) | 15 if( chatId === currentChatId ) |
9 return; | 16 return; |
68 let input = document.querySelector('div[input]'); | 75 let input = document.querySelector('div[input]'); |
69 input.insertAdjacentHTML('beforebegin',html); | 76 input.insertAdjacentHTML('beforebegin',html); |
70 fixDates(); | 77 fixDates(); |
71 input.scrollIntoView({block: 'end'}); | 78 input.scrollIntoView({block: 'end'}); |
72 } | 79 } |
80 | |
81 function getChats(chatId) { | |
82 let first = document.querySelector('div[chat]'); | |
83 if( !first || first.getAttribute('chat') != chatId ) { | |
84 // console.log('getChats'); | |
85 ajax('get_chats.js'); | |
86 } | |
87 } | |
88 | |
89 function gotChats(html) { | |
90 document.querySelector('div[chats]').innerHTML = html; | |
91 if( currentChatId ) { | |
92 let current = document.querySelector(`div[chat="${currentChatId}"]`); | |
93 current.setAttribute('selected',''); | |
94 current.scrollIntoViewIfNeeded(false); | |
95 } | |
96 } |