2020-10-05 04:43:31 +03:00
|
|
|
import { h, Component } from '/js/web_modules/preact.js';
|
|
|
|
import htm from '/js/web_modules/htm.js';
|
2020-10-04 05:01:46 +03:00
|
|
|
const html = htm.bind(h);
|
2020-08-13 11:28:25 +03:00
|
|
|
|
2020-10-17 03:36:11 +03:00
|
|
|
import ChatMessageView from './chat-message-view.js';
|
|
|
|
|
2020-10-04 05:08:05 +03:00
|
|
|
import { messageBubbleColorForString } from '../../utils/user-colors.js';
|
|
|
|
import { SOCKET_MESSAGE_TYPES } from '../../utils/websocket.js';
|
2020-10-03 16:29:29 +03:00
|
|
|
|
2020-10-04 05:08:05 +03:00
|
|
|
export default class Message extends Component {
|
2020-08-13 11:28:25 +03:00
|
|
|
render(props) {
|
2020-10-17 03:36:11 +03:00
|
|
|
const { message } = props;
|
2020-08-13 11:49:10 +03:00
|
|
|
const { type } = message;
|
2020-10-17 03:36:11 +03:00
|
|
|
if (type === SOCKET_MESSAGE_TYPES.CHAT || type === SOCKET_MESSAGE_TYPES.SYSTEM) {
|
|
|
|
return html`<${ChatMessageView} ...${props} />`;
|
2020-08-13 11:49:10 +03:00
|
|
|
} else if (type === SOCKET_MESSAGE_TYPES.NAME_CHANGE) {
|
2020-10-14 14:33:55 +03:00
|
|
|
const { oldName, newName } = message;
|
2020-08-13 11:49:10 +03:00
|
|
|
return (
|
|
|
|
html`
|
2020-08-24 07:49:26 +03:00
|
|
|
<div class="message message-name-change flex items-center justify-start p-3">
|
2020-08-27 22:25:46 +03:00
|
|
|
<div class="message-content flex flex-row items-center justify-center text-sm w-full">
|
2020-08-24 07:49:26 +03:00
|
|
|
<div class="text-white text-center opacity-50">
|
2020-08-22 01:55:52 +03:00
|
|
|
<span class="font-bold">${oldName}</span> is now known as <span class="font-bold">${newName}</span>.
|
|
|
|
</div>
|
2020-08-13 11:49:10 +03:00
|
|
|
</div>
|
2020-08-13 11:28:25 +03:00
|
|
|
</div>
|
2020-08-22 09:44:10 +03:00
|
|
|
`
|
|
|
|
);
|
2020-10-14 02:45:52 +03:00
|
|
|
} else {
|
2020-10-17 03:36:11 +03:00
|
|
|
console.log("Unknown message type:", type);
|
2020-10-14 02:45:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|