diff --git a/springChatRoom/src/main/resources/static/js/main.js b/springChatRoom/src/main/resources/static/js/main.js index c69f4ee6c..71d72a5ac 100644 --- a/springChatRoom/src/main/resources/static/js/main.js +++ b/springChatRoom/src/main/resources/static/js/main.js @@ -176,19 +176,38 @@ function updateOnlineUsers(users) { // Function to handle chat initiation function startChat(username) { - // Add your logic here to start a private chat with the selected user - console.log('>>> Start chat with ' + username); - // Open a popup window for the chat const popupWindow = window.open('', '_blank', 'width=400,height=300'); - // Add your logic to customize the popup window content - popupWindow.document.write('Chat with ' + username + ''); - popupWindow.document.write('

Chat with ' + username + '

'); - popupWindow.document.write('

This is the chat content. Customize it as needed.

'); - popupWindow.document.write(''); + // Add your logic to customize the popup window content + popupWindow.document.write('Chat with ' + username + ''); + popupWindow.document.write('

Chat with ' + username + '

'); + popupWindow.document.write('
'); + popupWindow.document.write(''); + popupWindow.document.write(''); + popupWindow.document.write(''); + + // Function to send a message from the popup window + popupWindow.sendMessage = function() { + const messageInput = popupWindow.document.getElementById('messageInput'); + const chatMessages = popupWindow.document.getElementById('chatMessages'); + + const message = messageInput.value.trim(); + if (message !== '') { + // Customize the way messages are displayed in the popup window + chatMessages.innerHTML += '

You: ' + message + '

'; + + // Add your logic to send the message to the other user + // Example: stompClient.send('/app/private/' + username, {}, JSON.stringify({ sender: 'You', content: message, type: 'CHAT' })); + + // Clear the input field + messageInput.value = ''; + } + }; } + + // Call the fetchUserList function to initially populate the user list fetchUserList();