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

170 lines
5.0 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';
2021-03-10 04:52:20 +08:00
import ChatLogger from '/imports/ui/components/chat/chat-logger/ChatLogger';
import { styles } from './styles.scss';
import MessageForm from './message-form/container';
import TimeWindowList from './time-window-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,
title,
messages,
partnerIsLoggedOut,
isChatLocked,
actions,
intl,
shortcuts,
2019-06-27 00:29:34 +08:00
isMeteorConnected,
lastReadMessageTime,
hasUnreadMessages,
scrollPosition,
UnsentMessagesCollection,
minMessageLength,
maxMessageLength,
amIModerator,
meetingIsBreakout,
timeWindowsValues,
dispatch,
count,
2021-03-10 04:52:20 +08:00
syncing,
syncedPercent,
lastTimeWindowValuesBuild,
} = props;
const HIDE_CHAT_AK = shortcuts.hidePrivateChat;
const CLOSE_CHAT_AK = shortcuts.closePrivateChat;
2021-03-10 04:52:20 +08:00
ChatLogger.debug('ChatComponent::render', props);
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}
/>
)
2021-02-13 03:13:21 +08:00
: <ChatDropdownContainer {...{ meetingIsBreakout, isMeteorConnected, amIModerator, timeWindowsValues }} />
}
</header>
<TimeWindowList
id={ELEMENT_ID}
2019-07-31 10:37:50 +08:00
chatId={chatID}
handleScrollUpdate={actions.handleScrollUpdate}
2019-07-31 10:37:50 +08:00
{...{
partnerIsLoggedOut,
lastReadMessageTime,
hasUnreadMessages,
scrollPosition,
messages,
currentUserIsModerator: amIModerator,
timeWindowsValues,
dispatch,
count,
2021-03-10 04:52:20 +08:00
syncing,
syncedPercent,
lastTimeWindowValuesBuild,
2019-07-31 10:37:50 +08:00
}}
/>
<MessageForm
2019-07-31 10:37:50 +08:00
{...{
UnsentMessagesCollection,
2021-02-09 20:44:01 +08:00
title,
2019-07-31 10:37:50 +08:00
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,
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;