import { h } from '/js/web_modules/preact.js'; import htm from '/js/web_modules/htm.js'; const html = htm.bind(h); import ChatMessageView from './chat-message-view.js'; import { SOCKET_MESSAGE_TYPES } from '../../utils/websocket.js'; export default function Message(props) { const { message } = props; const { type } = message; if ( type === SOCKET_MESSAGE_TYPES.CHAT || type === SOCKET_MESSAGE_TYPES.SYSTEM ) { return html`<${ChatMessageView} ...${props} />`; } else if (type === SOCKET_MESSAGE_TYPES.NAME_CHANGE) { const { oldName, user } = message; const { displayName } = user; return html`
${oldName} is now known as ${displayName}.
`; } else if (type === SOCKET_MESSAGE_TYPES.USER_JOINED) { const { user } = message; const { displayName } = user; return html`
${displayName} joined the chat.
`; } else if (type === SOCKET_MESSAGE_TYPES.CHAT_ACTION) { const { body } = message; const formattedMessage = `${body}`; return html`
`; } else if (type === SOCKET_MESSAGE_TYPES.CONNECTED_USER_INFO) { // noop for now } else { console.log('Unknown message type:', type); } }