mirror of
https://github.com/owncast/owncast.git
synced 2024-12-29 20:48:35 +03:00
661eedc03a
* only consider short-heights when not smallscreen; hide status bar when small screen, but leave shadow; * fix max char counting bugs with paste, yet be still be able to use modifier keys even when max chars reached * rmeove 'chat' button; move into textarea * use image for emoji picker for sizing consitency * cleanup unused things * - totally unecessary emoji picker style improvements - totally necessary doctype added to emoji picker so it shows up more stable-y on mobile views * more stable layout positioning for chat panel without hacky margins, so that the bottom of the message list will always be on top of the form input, and not behind it at any point. * hide header on touch screens when screns are small and screen height is short (possibly when keyboard is up), so that there's more visibliity to see messages. this only works on chrome, not ios safari right now, due to the position: fixed of things. * move char counting to keyup instead * address message text horiz overflow (#157) * dont jumpToBottom if user has scrolled about 200px from the bottom (#101) * scroll to bottom on resize too * cleanup * revert test bool * typo * re-readjust short-wide case again * - add focus to input field after emoji is selected, put cursor at end - instead of smooth scrolling to bottom, just jump there.
66 lines
2.4 KiB
JavaScript
66 lines
2.4 KiB
JavaScript
import { h, Component } from 'https://unpkg.com/preact?module';
|
|
import htm from 'https://unpkg.com/htm?module';
|
|
const html = htm.bind(h);
|
|
|
|
import { messageBubbleColorForString } from '../../utils/user-colors.js';
|
|
import { formatMessageText } from '../../utils/chat.js';
|
|
import { generateAvatar } from '../../utils/helpers.js';
|
|
import { SOCKET_MESSAGE_TYPES } from '../../utils/websocket.js';
|
|
|
|
export default class Message extends Component {
|
|
render(props) {
|
|
const { message, username } = props;
|
|
const { type } = message;
|
|
|
|
if (type === SOCKET_MESSAGE_TYPES.CHAT) {
|
|
const { image, author, body } = message;
|
|
const formattedMessage = formatMessageText(body, username);
|
|
const avatar = image || generateAvatar(author);
|
|
|
|
const authorColor = messageBubbleColorForString(author);
|
|
const avatarBgColor = { backgroundColor: authorColor };
|
|
const authorTextColor = { color: authorColor };
|
|
return (
|
|
html`
|
|
<div class="message flex flex-row items-start p-3">
|
|
<div
|
|
class="message-avatar rounded-full flex items-center justify-center mr-3"
|
|
style=${avatarBgColor}
|
|
>
|
|
<img src=${avatar} class="p-1" />
|
|
</div>
|
|
<div class="message-content text-sm break-words w-full">
|
|
<div class="message-author text-white font-bold" style=${authorTextColor}>
|
|
${author}
|
|
</div>
|
|
<div
|
|
class="message-text text-gray-300 font-normal overflow-y-hidden"
|
|
dangerouslySetInnerHTML=${
|
|
{ __html: formattedMessage }
|
|
}
|
|
></div>
|
|
</div>
|
|
</div>
|
|
`);
|
|
} else if (type === SOCKET_MESSAGE_TYPES.NAME_CHANGE) {
|
|
const { oldName, newName, image } = 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="message-avatar rounded-full mr-3 bg-gray-900"
|
|
>
|
|
<img class="mr-2 p-1" src=${image} />
|
|
</div>
|
|
|
|
<div class="text-white text-center opacity-50">
|
|
<span class="font-bold">${oldName}</span> is now known as <span class="font-bold">${newName}</span>.
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`
|
|
);
|
|
}
|
|
}
|
|
}
|