bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/chat/component.jsx

159 lines
4.7 KiB
React
Raw Normal View History

import React, { memo } from 'react';
import PropTypes from 'prop-types';
import { defineMessages, injectIntl } from 'react-intl';
import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component';
import Button from '/imports/ui/components/button/component';
import { Session } from 'meteor/session';
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
import { styles } from './styles.scss';
import MessageForm from './message-form/container';
import MessageList from './message-list/container';
import ChatDropdownContainer from './chat-dropdown/container';
2016-06-02 00:33:19 +08:00
const ELEMENT_ID = 'chat-messages';
2016-04-29 03:02:51 +08:00
const intlMessages = defineMessages({
closeChatLabel: {
id: 'app.chat.closeChatLabel',
2017-04-10 23:50:03 +08:00
description: 'aria-label for closing chat button',
},
hideChatLabel: {
id: 'app.chat.hideChatLabel',
description: 'aria-label for hiding chat button',
},
});
const Chat = (props) => {
const {
chatID,
chatName,
title,
messages,
partnerIsLoggedOut,
isChatLocked,
actions,
intl,
shortcuts,
2019-06-27 00:29:34 +08:00
isMeteorConnected,
lastReadMessageTime,
hasUnreadMessages,
scrollPosition,
UnsentMessagesCollection,
minMessageLength,
maxMessageLength,
amIModerator,
meetingIsBreakout,
} = props;
2016-06-02 00:33:19 +08:00
const HIDE_CHAT_AK = shortcuts.hidePrivateChat;
const CLOSE_CHAT_AK = shortcuts.closePrivateChat;
return (
2018-01-09 10:43:34 +08:00
<div
data-test={chatID !== 'public' ? 'privateChat' : 'publicChat'}
2018-01-09 10:43:34 +08:00
className={styles.chat}
>
<header className={styles.header}>
<div
data-test="chatTitle"
className={styles.title}
>
<Button
onClick={() => {
2019-01-14 21:23:35 +08:00
Session.set('idChatOpen', '');
2018-11-20 07:29:48 +08:00
Session.set('openPanel', 'userlist');
window.dispatchEvent(new Event('panelChanged'));
}}
aria-label={intl.formatMessage(intlMessages.hideChatLabel, { 0: title })}
accessKey={HIDE_CHAT_AK}
label={title}
icon="left_arrow"
2018-10-16 22:33:42 +08:00
className={styles.hideBtn}
/>
</div>
{
2018-12-18 23:15:51 +08:00
chatID !== 'public'
? (
<Button
icon="close"
size="sm"
ghost
color="dark"
2018-12-18 23:15:51 +08:00
hideLabel
onClick={() => {
actions.handleClosePrivateChat(chatID);
2019-01-14 21:23:35 +08:00
Session.set('idChatOpen', '');
2018-12-18 23:15:51 +08:00
Session.set('openPanel', 'userlist');
window.dispatchEvent(new Event('panelChanged'));
2018-12-18 23:15:51 +08:00
}}
aria-label={intl.formatMessage(intlMessages.closeChatLabel, { 0: title })}
label={intl.formatMessage(intlMessages.closeChatLabel, { 0: title })}
accessKey={CLOSE_CHAT_AK}
/>
)
: <ChatDropdownContainer {...{ meetingIsBreakout, isMeteorConnected, amIModerator }} />
}
</header>
<MessageList
id={ELEMENT_ID}
2019-07-31 10:37:50 +08:00
chatId={chatID}
handleScrollUpdate={actions.handleScrollUpdate}
handleReadMessage={actions.handleReadMessage}
2019-07-31 10:37:50 +08:00
{...{
partnerIsLoggedOut,
lastReadMessageTime,
hasUnreadMessages,
scrollPosition,
messages,
}}
/>
<MessageForm
2019-07-31 10:37:50 +08:00
{...{
UnsentMessagesCollection,
chatName,
minMessageLength,
maxMessageLength,
}}
2019-02-01 20:13:45 +08:00
chatId={chatID}
chatTitle={title}
2019-07-31 10:37:50 +08:00
chatAreaId={ELEMENT_ID}
disabled={isChatLocked || !isMeteorConnected}
connected={isMeteorConnected}
locked={isChatLocked}
handleSendMessage={actions.handleSendMessage}
partnerIsLoggedOut={partnerIsLoggedOut}
/>
</div>
);
};
export default withShortcutHelper(injectWbResizeEvent(injectIntl(memo(Chat))), ['hidePrivateChat', 'closePrivateChat']);
2017-10-11 06:08:51 +08:00
const propTypes = {
chatID: PropTypes.string.isRequired,
chatName: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
messages: PropTypes.arrayOf(PropTypes.objectOf(PropTypes.oneOfType([
PropTypes.array,
PropTypes.string,
PropTypes.number,
PropTypes.object,
])).isRequired).isRequired,
2019-02-15 23:32:41 +08:00
shortcuts: PropTypes.objectOf(PropTypes.string),
partnerIsLoggedOut: PropTypes.bool.isRequired,
isChatLocked: PropTypes.bool.isRequired,
2019-06-27 00:29:34 +08:00
isMeteorConnected: PropTypes.bool.isRequired,
actions: PropTypes.shape({
handleClosePrivateChat: PropTypes.func.isRequired,
}).isRequired,
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
};
2017-10-11 06:08:51 +08:00
const defaultProps = {
shortcuts: [],
};
2017-10-11 06:08:51 +08:00
Chat.propTypes = propTypes;
Chat.defaultProps = defaultProps;