Skip to content

Commit

Permalink
feat: improve message display in chat by separating username and mess…
Browse files Browse the repository at this point in the history
…age text
  • Loading branch information
milyin committed Dec 13, 2024
1 parent 471f364 commit e8242bb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions zenoh-ts/examples/chat/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ document.addEventListener('DOMContentLoaded', () => {
});
chatSession.onNewMessage((chatSession, user, message) => {
const messageElement = document.createElement('div');
const usernameElement = document.createElement('span');
const messageTextElement = document.createElement('span');
if (user.username === chatSession.getUser().username) {
messageElement.innerHTML = `<strong>${user.toString()}</strong>: ${message}`;
usernameElement.innerHTML = `<strong>${user.toString()}</strong>: `;
} else {
messageElement.textContent = `${user.toString()}: ${message}`;
usernameElement.textContent = `${user.toString()}: `;
}
messageTextElement.textContent = message;
messageElement.appendChild(usernameElement);
messageElement.appendChild(messageTextElement);
chatLog.appendChild(messageElement);
chatLog.scrollTop = chatLog.scrollHeight; // Scroll to the latest message
});
Expand Down

0 comments on commit e8242bb

Please sign in to comment.