Attempt four of making the webclient work with message history.
This commit is contained in:
parent
9e8158a5c0
commit
72c6735cba
1 changed files with 10 additions and 3 deletions
|
|
@ -160,10 +160,17 @@
|
||||||
socket.emit('join', { username: username, chat_room: chatRoom });
|
socket.emit('join', { username: username, chat_room: chatRoom });
|
||||||
|
|
||||||
// Fetch message history for the initial chat room
|
// Fetch message history for the initial chat room
|
||||||
fetch(`/get_history?chat_room=${chatRoom}`)
|
const serverBaseUrl = `${window.location.protocol}//${window.location.hostname}:5000`;
|
||||||
.then(response => response.json())
|
fetch(`${serverBaseUrl}/get_history?chat_room=${encodeURIComponent(chatRoom)}`)
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.messages) {
|
if (data.messages && data.messages.length > 0) {
|
||||||
|
// Display each message in the chat history
|
||||||
data.messages.forEach(message => {
|
data.messages.forEach(message => {
|
||||||
const messageElement = document.createElement('div');
|
const messageElement = document.createElement('div');
|
||||||
messageElement.textContent = message;
|
messageElement.textContent = message;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue