MCPcopy
hub / github.com/socketio/socket.io / addChatMessage

Function addChatMessage

examples/chat/public/main.js:75–96  ·  view source on GitHub ↗
(data, options = {})

Source from the content-addressed store, hash-verified

73
74 // Adds the visual chat message to the message list
75 const addChatMessage = (data, options = {}) => {
76 // Don't fade the message in if there is an 'X was typing'
77 const $typingMessages = getTypingMessages(data);
78 if ($typingMessages.length !== 0) {
79 options.fade = false;
80 $typingMessages.remove();
81 }
82
83 const $usernameDiv = $('<span class="username"/>')
84 .text(data.username)
85 .css('color', getUsernameColor(data.username));
86 const $messageBodyDiv = $('<span class="messageBody">')
87 .text(data.message);
88
89 const typingClass = data.typing ? 'typing' : '';
90 const $messageDiv = $('<li class="message"/>')
91 .data('username', data.username)
92 .addClass(typingClass)
93 .append($usernameDiv, $messageBodyDiv);
94
95 addMessageElement($messageDiv, options);
96 }
97
98 // Adds the visual chat typing message
99 const addChatTyping = (data) => {

Callers 3

sendMessageFunction · 0.70
addChatTypingFunction · 0.70
main.jsFile · 0.70

Calls 5

getTypingMessagesFunction · 0.70
getUsernameColorFunction · 0.70
addMessageElementFunction · 0.70
$Function · 0.50
removeMethod · 0.45

Tested by

no test coverage detected