Created
May 12, 2020 14:57
-
-
Save dongido001/d1c593d2203cf0bf12d65e156a34c3f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function appendMessage(message) { | |
const messageContainer = document.getElementById("messages") | |
// Create and append the message div | |
const messageDiv = document.createElement("div") | |
messageDiv.className = `message ${ message.user.id === username ? 'message-right' : 'message-left' }` | |
// Create the username div | |
const usernameDiv = document.createElement("div") | |
usernameDiv.className = "message-username" | |
usernameDiv.textContent = `${message.user.id}:` | |
// Append the username div to the MessageDiv | |
messageDiv.append(usernameDiv) | |
let messageContent | |
if (message.attachments.length) { | |
// we have an attachment - audio message | |
messageContent = getAudioElement(message.attachments[0].asset_url) | |
} else { | |
// Create the main message text div | |
const messageTextDiv = document.createElement("div") | |
messageTextDiv.textContent = message.text | |
messageContent = messageTextDiv | |
} | |
// Append the username div to the MessageDiv | |
messageDiv.append(messageContent) | |
// Then append the messageDiv to the "messages" div | |
messageContainer.appendChild(messageDiv) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment