owncast/webroot/js/components/chat/message.js

32 lines
1.1 KiB
JavaScript
Raw Normal View History

import { h } from '/js/web_modules/preact.js';
import htm from '/js/web_modules/htm.js';
const html = htm.bind(h);
2020-10-17 03:36:11 +03:00
import ChatMessageView from './chat-message-view.js';
2020-10-04 05:08:05 +03:00
import { SOCKET_MESSAGE_TYPES } from '../../utils/websocket.js';
2020-10-03 16:29:29 +03:00
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, newName } = message;
return (
html`
<div class="message message-name-change flex items-center justify-start p-3">
<div class="message-content flex flex-row items-center justify-center text-sm w-full">
<div class="text-white text-center opacity-50 overflow-hidden break-words">
<span class="font-bold">${oldName}</span> is now known as <span class="font-bold">${newName}</span>.
</div>
</div>
</div>
`
);
} else {
console.log("Unknown message type:", type);
}
}