2020-10-05 04:43:31 +03:00
|
|
|
import { h, Component, createRef } from '/js/web_modules/preact.js';
|
|
|
|
import htm from '/js/web_modules/htm.js';
|
2020-08-13 11:28:25 +03:00
|
|
|
const html = htm.bind(h);
|
|
|
|
|
2020-08-13 12:08:14 +03:00
|
|
|
import Message from './message.js';
|
2020-08-14 14:19:19 +03:00
|
|
|
import ChatInput from './chat-input.js';
|
2020-08-24 05:06:58 +03:00
|
|
|
import { CALLBACKS, SOCKET_MESSAGE_TYPES } from '../../utils/websocket.js';
|
2021-06-08 03:37:20 +03:00
|
|
|
import {
|
|
|
|
jumpToBottom,
|
|
|
|
debounce,
|
|
|
|
getLocalStorage,
|
|
|
|
} from '../../utils/helpers.js';
|
2020-08-24 05:06:58 +03:00
|
|
|
import { extraUserNamesFromMessageHistory } from '../../utils/chat.js';
|
2021-06-08 03:37:20 +03:00
|
|
|
import {
|
|
|
|
URL_CHAT_HISTORY,
|
|
|
|
MESSAGE_JUMPTOBOTTOM_BUFFER,
|
|
|
|
KEY_CUSTOM_USERNAME_SET,
|
|
|
|
} from '../../utils/constants.js';
|
2020-08-13 11:28:25 +03:00
|
|
|
|
|
|
|
export default class Chat extends Component {
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
chatUserNames: [],
|
2020-12-23 04:43:35 +03:00
|
|
|
messages: [],
|
2020-12-07 08:01:52 +03:00
|
|
|
newMessagesReceived: false,
|
2020-12-23 04:43:35 +03:00
|
|
|
webSocketConnected: true,
|
2020-08-16 04:28:29 +03:00
|
|
|
};
|
2020-08-13 11:28:25 +03:00
|
|
|
|
2020-08-24 08:21:42 +03:00
|
|
|
this.scrollableMessagesContainer = createRef();
|
|
|
|
|
2020-08-13 19:28:47 +03:00
|
|
|
this.websocket = null;
|
2020-12-04 09:43:31 +03:00
|
|
|
this.receivedFirstMessages = false;
|
2020-12-30 00:35:33 +03:00
|
|
|
this.receivedMessageUpdate = false;
|
2020-08-13 19:28:47 +03:00
|
|
|
|
2020-12-23 04:43:35 +03:00
|
|
|
this.windowBlurred = false;
|
|
|
|
this.numMessagesSinceBlur = 0;
|
|
|
|
|
2020-08-13 19:28:47 +03:00
|
|
|
this.getChatHistory = this.getChatHistory.bind(this);
|
2020-12-23 04:43:35 +03:00
|
|
|
this.handleNetworkingError = this.handleNetworkingError.bind(this);
|
|
|
|
this.handleWindowBlur = this.handleWindowBlur.bind(this);
|
|
|
|
this.handleWindowFocus = this.handleWindowFocus.bind(this);
|
|
|
|
this.handleWindowResize = debounce(this.handleWindowResize.bind(this), 500);
|
|
|
|
this.messageListCallback = this.messageListCallback.bind(this);
|
2020-08-13 19:28:47 +03:00
|
|
|
this.receivedWebsocketMessage = this.receivedWebsocketMessage.bind(this);
|
2020-12-23 04:43:35 +03:00
|
|
|
this.scrollToBottom = this.scrollToBottom.bind(this);
|
|
|
|
this.submitChat = this.submitChat.bind(this);
|
2020-09-22 11:38:43 +03:00
|
|
|
this.websocketConnected = this.websocketConnected.bind(this);
|
2020-08-13 19:28:47 +03:00
|
|
|
this.websocketDisconnected = this.websocketDisconnected.bind(this);
|
2020-08-13 11:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2021-06-08 03:37:20 +03:00
|
|
|
this.setupWebSocketCallbacks();
|
|
|
|
this.getChatHistory();
|
2020-12-07 08:01:52 +03:00
|
|
|
|
2021-06-08 03:37:20 +03:00
|
|
|
window.addEventListener('resize', this.handleWindowResize);
|
2020-11-18 03:59:27 +03:00
|
|
|
|
2021-06-08 03:37:20 +03:00
|
|
|
if (!this.props.messagesOnly) {
|
|
|
|
window.addEventListener('blur', this.handleWindowBlur);
|
|
|
|
window.addEventListener('focus', this.handleWindowFocus);
|
|
|
|
}
|
2020-12-23 04:43:35 +03:00
|
|
|
|
2021-06-08 03:37:20 +03:00
|
|
|
this.messageListObserver = new MutationObserver(this.messageListCallback);
|
|
|
|
this.messageListObserver.observe(this.scrollableMessagesContainer.current, {
|
|
|
|
childList: true,
|
|
|
|
});
|
2020-08-13 11:28:25 +03:00
|
|
|
}
|
|
|
|
|
2020-12-07 08:01:52 +03:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
|
|
const { username, chatInputEnabled } = this.props;
|
2021-06-08 03:37:20 +03:00
|
|
|
const { username: nextUserName, chatInputEnabled: nextChatEnabled } =
|
|
|
|
nextProps;
|
2020-12-07 08:01:52 +03:00
|
|
|
|
2021-06-08 03:37:20 +03:00
|
|
|
const { webSocketConnected, messages, chatUserNames, newMessagesReceived } =
|
|
|
|
this.state;
|
|
|
|
const {
|
|
|
|
webSocketConnected: nextSocket,
|
|
|
|
messages: nextMessages,
|
|
|
|
chatUserNames: nextUserNames,
|
|
|
|
newMessagesReceived: nextMessagesReceived,
|
|
|
|
} = nextState;
|
2020-12-07 08:01:52 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
username !== nextUserName ||
|
|
|
|
chatInputEnabled !== nextChatEnabled ||
|
|
|
|
webSocketConnected !== nextSocket ||
|
|
|
|
messages.length !== nextMessages.length ||
|
2021-06-08 03:37:20 +03:00
|
|
|
chatUserNames.length !== nextUserNames.length ||
|
|
|
|
newMessagesReceived !== nextMessagesReceived
|
2020-12-07 08:01:52 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-24 08:21:42 +03:00
|
|
|
componentDidUpdate(prevProps, prevState) {
|
2020-08-13 11:28:25 +03:00
|
|
|
const { username: prevName } = prevProps;
|
2020-10-14 14:33:55 +03:00
|
|
|
const { username } = this.props;
|
2020-08-24 08:21:42 +03:00
|
|
|
|
|
|
|
const { messages: prevMessages } = prevState;
|
|
|
|
const { messages } = this.state;
|
|
|
|
|
2020-08-13 11:28:25 +03:00
|
|
|
// if username updated, send a message
|
|
|
|
if (prevName !== username) {
|
2020-10-14 14:33:55 +03:00
|
|
|
this.sendUsernameChange(prevName, username);
|
2020-08-13 11:28:25 +03:00
|
|
|
}
|
2020-11-18 03:59:27 +03:00
|
|
|
|
2020-08-24 08:21:42 +03:00
|
|
|
// scroll to bottom of messages list when new ones come in
|
2020-12-30 00:35:33 +03:00
|
|
|
if (messages.length !== prevMessages.length) {
|
2020-12-07 08:01:52 +03:00
|
|
|
this.setState({
|
|
|
|
newMessagesReceived: true,
|
|
|
|
});
|
2020-08-24 08:21:42 +03:00
|
|
|
}
|
2020-08-13 11:28:25 +03:00
|
|
|
}
|
2020-08-24 22:34:36 +03:00
|
|
|
componentWillUnmount() {
|
2020-09-22 06:11:09 +03:00
|
|
|
window.removeEventListener('resize', this.handleWindowResize);
|
2020-12-23 04:43:35 +03:00
|
|
|
if (!this.props.messagesOnly) {
|
|
|
|
window.removeEventListener('blur', this.handleWindowBlur);
|
|
|
|
window.removeEventListener('focus', this.handleWindowFocus);
|
2021-06-08 03:37:20 +03:00
|
|
|
}
|
2020-11-18 03:59:27 +03:00
|
|
|
this.messageListObserver.disconnect();
|
2020-08-24 22:34:36 +03:00
|
|
|
}
|
|
|
|
|
2020-08-14 14:19:19 +03:00
|
|
|
setupWebSocketCallbacks() {
|
|
|
|
this.websocket = this.props.websocket;
|
|
|
|
if (this.websocket) {
|
2021-06-08 03:37:20 +03:00
|
|
|
this.websocket.addListener(
|
|
|
|
CALLBACKS.RAW_WEBSOCKET_MESSAGE_RECEIVED,
|
|
|
|
this.receivedWebsocketMessage
|
|
|
|
);
|
|
|
|
this.websocket.addListener(
|
|
|
|
CALLBACKS.WEBSOCKET_CONNECTED,
|
|
|
|
this.websocketConnected
|
|
|
|
);
|
|
|
|
this.websocket.addListener(
|
|
|
|
CALLBACKS.WEBSOCKET_DISCONNECTED,
|
|
|
|
this.websocketDisconnected
|
|
|
|
);
|
2020-08-14 14:19:19 +03:00
|
|
|
}
|
2020-08-13 19:28:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// fetch chat history
|
|
|
|
getChatHistory() {
|
|
|
|
fetch(URL_CHAT_HISTORY)
|
2021-06-08 03:37:20 +03:00
|
|
|
.then((response) => {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`Network response was not ok ${response.ok}`);
|
|
|
|
}
|
|
|
|
return response.json();
|
|
|
|
})
|
|
|
|
.then((data) => {
|
|
|
|
// extra user names
|
|
|
|
const chatUserNames = extraUserNamesFromMessageHistory(data);
|
|
|
|
this.setState({
|
|
|
|
messages: this.state.messages.concat(data),
|
|
|
|
chatUserNames,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
this.handleNetworkingError(`Fetch getChatHistory: ${error}`);
|
2020-08-13 19:28:47 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-14 14:33:55 +03:00
|
|
|
sendUsernameChange(oldName, newName) {
|
2021-02-19 10:05:52 +03:00
|
|
|
clearTimeout(this.sendUserJoinedEvent);
|
|
|
|
|
2021-06-08 03:37:20 +03:00
|
|
|
const nameChange = {
|
|
|
|
type: SOCKET_MESSAGE_TYPES.NAME_CHANGE,
|
|
|
|
oldName,
|
|
|
|
newName,
|
|
|
|
};
|
|
|
|
this.websocket.send(nameChange);
|
2020-08-13 19:28:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
receivedWebsocketMessage(message) {
|
2020-12-30 00:35:33 +03:00
|
|
|
this.handleMessage(message);
|
2020-08-13 19:28:47 +03:00
|
|
|
}
|
|
|
|
|
2020-12-07 08:01:52 +03:00
|
|
|
handleNetworkingError(error) {
|
|
|
|
// todo: something more useful
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
|
2020-12-30 00:35:33 +03:00
|
|
|
// handle any incoming message
|
|
|
|
handleMessage(message) {
|
|
|
|
const {
|
|
|
|
id: messageId,
|
|
|
|
type: messageType,
|
|
|
|
timestamp: messageTimestamp,
|
|
|
|
visible: messageVisible,
|
|
|
|
} = message;
|
2020-08-13 19:28:47 +03:00
|
|
|
const { messages: curMessages } = this.state;
|
2020-12-23 04:43:35 +03:00
|
|
|
const { messagesOnly } = this.props;
|
2020-08-26 10:51:40 +03:00
|
|
|
|
2021-06-08 03:37:20 +03:00
|
|
|
const existingIndex = curMessages.findIndex(
|
|
|
|
(item) => item.id === messageId
|
|
|
|
);
|
2020-08-26 10:51:40 +03:00
|
|
|
|
2020-12-30 00:35:33 +03:00
|
|
|
// If the message already exists and this is an update event
|
|
|
|
// then update it.
|
|
|
|
if (messageType === 'VISIBILITY-UPDATE') {
|
|
|
|
const updatedMessageList = [...curMessages];
|
|
|
|
const convertedMessage = {
|
|
|
|
...message,
|
|
|
|
type: 'CHAT',
|
|
|
|
};
|
|
|
|
// if message exists and should now hide, take it out.
|
|
|
|
if (existingIndex >= 0 && !messageVisible) {
|
|
|
|
this.setState({
|
2021-06-08 03:37:20 +03:00
|
|
|
messages: curMessages.filter((item) => item.id !== messageId),
|
2020-12-30 00:35:33 +03:00
|
|
|
});
|
|
|
|
} else if (existingIndex === -1 && messageVisible) {
|
|
|
|
// insert message at timestamp
|
|
|
|
const insertAtIndex = curMessages.findIndex((item, index) => {
|
|
|
|
const time = item.timestamp || messageTimestamp;
|
2021-06-08 03:37:20 +03:00
|
|
|
const nextMessage =
|
|
|
|
index < curMessages.length - 1 && curMessages[index + 1];
|
2020-12-30 00:35:33 +03:00
|
|
|
const nextTime = nextMessage.timestamp || messageTimestamp;
|
|
|
|
const messageTimestampDate = new Date(messageTimestamp);
|
2021-06-08 03:37:20 +03:00
|
|
|
return (
|
|
|
|
messageTimestampDate > new Date(time) &&
|
|
|
|
messageTimestampDate <= new Date(nextTime)
|
|
|
|
);
|
2020-12-30 00:35:33 +03:00
|
|
|
});
|
|
|
|
updatedMessageList.splice(insertAtIndex + 1, 0, convertedMessage);
|
|
|
|
this.setState({
|
|
|
|
messages: updatedMessageList,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (existingIndex === -1) {
|
|
|
|
// else if message doesn't exist, add it and extra username
|
2020-08-14 14:19:19 +03:00
|
|
|
const newState = {
|
2020-08-13 19:28:47 +03:00
|
|
|
messages: [...curMessages, message],
|
2020-08-14 14:19:19 +03:00
|
|
|
};
|
|
|
|
const updatedChatUserNames = this.updateAuthorList(message);
|
|
|
|
if (updatedChatUserNames.length) {
|
|
|
|
newState.chatUserNames = [...updatedChatUserNames];
|
|
|
|
}
|
|
|
|
this.setState(newState);
|
2020-08-13 19:28:47 +03:00
|
|
|
}
|
2020-12-23 04:43:35 +03:00
|
|
|
|
|
|
|
// if window is blurred and we get a new message, add 1 to title
|
2020-12-30 00:35:33 +03:00
|
|
|
if (!messagesOnly && messageType === 'CHAT' && this.windowBlurred) {
|
2020-12-23 04:43:35 +03:00
|
|
|
this.numMessagesSinceBlur += 1;
|
|
|
|
}
|
2020-08-13 19:28:47 +03:00
|
|
|
}
|
2020-09-22 11:22:49 +03:00
|
|
|
|
2020-09-22 11:38:43 +03:00
|
|
|
websocketConnected() {
|
|
|
|
this.setState({
|
|
|
|
webSocketConnected: true,
|
|
|
|
});
|
2021-02-19 10:05:52 +03:00
|
|
|
|
2021-06-08 03:37:20 +03:00
|
|
|
const hasPreviouslySetCustomUsername = getLocalStorage(
|
|
|
|
KEY_CUSTOM_USERNAME_SET
|
|
|
|
);
|
2021-02-19 10:05:52 +03:00
|
|
|
if (hasPreviouslySetCustomUsername && !this.props.ignoreClient) {
|
|
|
|
this.sendJoinedMessage();
|
|
|
|
}
|
2020-09-22 11:38:43 +03:00
|
|
|
}
|
|
|
|
|
2020-08-13 19:28:47 +03:00
|
|
|
websocketDisconnected() {
|
2020-09-22 11:22:49 +03:00
|
|
|
this.setState({
|
2020-09-22 11:38:43 +03:00
|
|
|
webSocketConnected: false,
|
2020-09-22 11:22:49 +03:00
|
|
|
});
|
2020-08-14 14:19:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
submitChat(content) {
|
2021-06-08 03:37:20 +03:00
|
|
|
if (!content) {
|
|
|
|
return;
|
2020-08-14 14:19:19 +03:00
|
|
|
}
|
2020-10-14 14:33:55 +03:00
|
|
|
const { username } = this.props;
|
2020-08-16 04:28:29 +03:00
|
|
|
const message = {
|
|
|
|
body: content,
|
2021-06-08 03:37:20 +03:00
|
|
|
author: username,
|
|
|
|
type: SOCKET_MESSAGE_TYPES.CHAT,
|
2020-08-16 04:28:29 +03:00
|
|
|
};
|
2021-06-08 03:37:20 +03:00
|
|
|
this.websocket.send(message);
|
2020-08-14 14:19:19 +03:00
|
|
|
}
|
|
|
|
|
2021-02-19 10:05:52 +03:00
|
|
|
sendJoinedMessage() {
|
|
|
|
const { username } = this.props;
|
|
|
|
const message = {
|
2021-06-08 03:37:20 +03:00
|
|
|
username: username,
|
|
|
|
type: SOCKET_MESSAGE_TYPES.USER_JOINED,
|
2021-02-19 10:05:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Artificial delay so people who join and immediately
|
|
|
|
// leave don't get counted.
|
2021-06-08 03:37:20 +03:00
|
|
|
this.sendUserJoinedEvent = setTimeout(
|
|
|
|
function () {
|
|
|
|
this.websocket.send(message);
|
|
|
|
}.bind(this),
|
|
|
|
5000
|
|
|
|
);
|
2021-02-19 10:05:52 +03:00
|
|
|
}
|
|
|
|
|
2020-08-14 14:19:19 +03:00
|
|
|
updateAuthorList(message) {
|
|
|
|
const { type } = message;
|
|
|
|
const nameList = this.state.chatUserNames;
|
|
|
|
|
|
|
|
if (
|
|
|
|
type === SOCKET_MESSAGE_TYPES.CHAT &&
|
|
|
|
!nameList.includes(message.author)
|
|
|
|
) {
|
|
|
|
return nameList.push(message.author);
|
|
|
|
} else if (type === SOCKET_MESSAGE_TYPES.NAME_CHANGE) {
|
|
|
|
const { oldName, newName } = message;
|
|
|
|
const oldNameIndex = nameList.indexOf(oldName);
|
|
|
|
return nameList.splice(oldNameIndex, 1, newName);
|
|
|
|
}
|
|
|
|
return [];
|
2020-08-13 19:28:47 +03:00
|
|
|
}
|
2020-08-13 11:28:25 +03:00
|
|
|
|
2020-09-14 08:02:04 +03:00
|
|
|
scrollToBottom() {
|
|
|
|
jumpToBottom(this.scrollableMessagesContainer.current);
|
|
|
|
}
|
2020-08-14 14:19:19 +03:00
|
|
|
|
2020-09-22 06:11:09 +03:00
|
|
|
checkShouldScroll() {
|
2021-06-08 03:37:20 +03:00
|
|
|
const { scrollTop, scrollHeight, clientHeight } =
|
|
|
|
this.scrollableMessagesContainer.current;
|
2020-09-22 06:11:09 +03:00
|
|
|
const fullyScrolled = scrollHeight - clientHeight;
|
2021-06-08 03:37:20 +03:00
|
|
|
const shouldScroll =
|
|
|
|
scrollHeight >= clientHeight &&
|
|
|
|
fullyScrolled - scrollTop < MESSAGE_JUMPTOBOTTOM_BUFFER;
|
2020-12-04 09:43:31 +03:00
|
|
|
return shouldScroll;
|
2020-09-22 06:11:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
handleWindowResize() {
|
|
|
|
this.scrollToBottom();
|
|
|
|
}
|
|
|
|
|
2020-12-23 04:43:35 +03:00
|
|
|
handleWindowBlur() {
|
|
|
|
this.windowBlurred = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleWindowFocus() {
|
|
|
|
this.windowBlurred = false;
|
|
|
|
this.numMessagesSinceBlur = 0;
|
|
|
|
window.document.title = this.props.instanceTitle;
|
|
|
|
}
|
|
|
|
|
2020-11-18 03:59:27 +03:00
|
|
|
// if the messages list grows in number of child message nodes due to new messages received, scroll to bottom.
|
|
|
|
messageListCallback(mutations) {
|
|
|
|
const numMutations = mutations.length;
|
|
|
|
if (numMutations) {
|
|
|
|
const item = mutations[numMutations - 1];
|
|
|
|
if (item.type === 'childList' && item.addedNodes.length) {
|
2020-12-07 08:01:52 +03:00
|
|
|
if (this.state.newMessagesReceived) {
|
2020-12-04 09:43:31 +03:00
|
|
|
if (!this.receivedFirstMessages) {
|
|
|
|
this.scrollToBottom();
|
|
|
|
this.receivedFirstMessages = true;
|
|
|
|
} else if (this.checkShouldScroll()) {
|
|
|
|
this.scrollToBottom();
|
|
|
|
}
|
2020-12-07 08:01:52 +03:00
|
|
|
this.setState({
|
|
|
|
newMessagesReceived: false,
|
|
|
|
});
|
2020-11-18 03:59:27 +03:00
|
|
|
}
|
|
|
|
}
|
2020-12-23 04:43:35 +03:00
|
|
|
// update document title if window blurred
|
2021-06-08 03:37:20 +03:00
|
|
|
if (
|
|
|
|
this.numMessagesSinceBlur &&
|
|
|
|
!this.props.messagesOnly &&
|
|
|
|
this.windowBlurred
|
|
|
|
) {
|
2020-12-23 04:43:35 +03:00
|
|
|
this.updateDocumentTitle();
|
|
|
|
}
|
2020-11-18 03:59:27 +03:00
|
|
|
}
|
2021-06-08 03:37:20 +03:00
|
|
|
}
|
2020-11-18 03:59:27 +03:00
|
|
|
|
2020-12-23 04:43:35 +03:00
|
|
|
updateDocumentTitle() {
|
2021-06-08 03:37:20 +03:00
|
|
|
const num =
|
|
|
|
this.numMessagesSinceBlur > 10 ? '10+' : this.numMessagesSinceBlur;
|
2020-12-23 04:43:35 +03:00
|
|
|
window.document.title = `${num} 💬 :: ${this.props.instanceTitle}`;
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:08:14 +03:00
|
|
|
render(props, state) {
|
2020-09-13 04:46:08 +03:00
|
|
|
const { username, messagesOnly, chatInputEnabled } = props;
|
2020-09-22 11:38:43 +03:00
|
|
|
const { messages, chatUserNames, webSocketConnected } = state;
|
2020-09-14 08:02:04 +03:00
|
|
|
|
2021-06-08 03:37:20 +03:00
|
|
|
const messageList = messages
|
|
|
|
.filter((message) => message.visible !== false)
|
|
|
|
.map(
|
|
|
|
(message) =>
|
|
|
|
html`<${Message}
|
|
|
|
message=${message}
|
|
|
|
username=${username}
|
|
|
|
key=${message.id}
|
|
|
|
/>`
|
|
|
|
);
|
2020-09-14 08:02:04 +03:00
|
|
|
|
2020-08-19 10:16:35 +03:00
|
|
|
if (messagesOnly) {
|
2020-09-14 08:02:04 +03:00
|
|
|
return html`
|
|
|
|
<div
|
|
|
|
id="messages-container"
|
|
|
|
ref=${this.scrollableMessagesContainer}
|
2020-09-22 06:11:09 +03:00
|
|
|
class="scrollbar-hidden py-1 overflow-auto"
|
2020-09-14 08:02:04 +03:00
|
|
|
>
|
|
|
|
${messageList}
|
|
|
|
</div>
|
|
|
|
`;
|
2020-08-19 10:16:35 +03:00
|
|
|
}
|
|
|
|
|
2020-09-13 04:46:08 +03:00
|
|
|
return html`
|
|
|
|
<section id="chat-container-wrap" class="flex flex-col">
|
|
|
|
<div
|
|
|
|
id="chat-container"
|
|
|
|
class="bg-gray-800 flex flex-col justify-end overflow-auto"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
id="messages-container"
|
|
|
|
ref=${this.scrollableMessagesContainer}
|
2020-09-22 06:11:09 +03:00
|
|
|
class="scrollbar-hidden py-1 overflow-auto z-10"
|
2020-09-13 04:46:08 +03:00
|
|
|
>
|
|
|
|
${messageList}
|
2020-08-13 11:28:25 +03:00
|
|
|
</div>
|
2020-09-13 04:46:08 +03:00
|
|
|
<${ChatInput}
|
|
|
|
chatUserNames=${chatUserNames}
|
2020-09-22 11:38:43 +03:00
|
|
|
inputEnabled=${webSocketConnected && chatInputEnabled}
|
2020-09-13 04:46:08 +03:00
|
|
|
handleSendMessage=${this.submitChat}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
`;
|
2020-08-13 11:28:25 +03:00
|
|
|
}
|
|
|
|
}
|