2018-12-17 19:48:34 +08:00
|
|
|
import React, { memo } from 'react';
|
2017-09-26 07:45:44 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-03-29 23:35:07 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-09-26 07:45:44 +08:00
|
|
|
import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component';
|
2017-12-05 03:43:08 +08:00
|
|
|
import Button from '/imports/ui/components/button/component';
|
2018-10-12 04:41:37 +08:00
|
|
|
import { Session } from 'meteor/session';
|
2018-11-01 02:51:56 +08:00
|
|
|
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
|
2019-05-14 21:15:54 +08:00
|
|
|
import { styles } from './styles.scss';
|
2019-08-09 02:53:08 +08:00
|
|
|
import MessageForm from './message-form/container';
|
|
|
|
import MessageList from './message-list/container';
|
2017-08-08 22:52:26 +08:00
|
|
|
import ChatDropdown from './chat-dropdown/component';
|
2016-06-02 00:33:19 +08:00
|
|
|
|
|
|
|
const ELEMENT_ID = 'chat-messages';
|
2016-04-29 03:02:51 +08:00
|
|
|
|
2017-03-29 23:35:07 +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',
|
2017-03-29 23:35:07 +08:00
|
|
|
},
|
2017-04-15 07:18:40 +08:00
|
|
|
hideChatLabel: {
|
|
|
|
id: 'app.chat.hideChatLabel',
|
|
|
|
description: 'aria-label for hiding chat button',
|
|
|
|
},
|
2017-03-29 23:35:07 +08:00
|
|
|
});
|
2017-09-26 07:45:44 +08:00
|
|
|
const Chat = (props) => {
|
|
|
|
const {
|
|
|
|
chatID,
|
|
|
|
chatName,
|
|
|
|
title,
|
|
|
|
messages,
|
|
|
|
partnerIsLoggedOut,
|
|
|
|
isChatLocked,
|
|
|
|
actions,
|
|
|
|
intl,
|
2018-11-01 02:51:56 +08:00
|
|
|
shortcuts,
|
2019-06-27 00:29:34 +08:00
|
|
|
isMeteorConnected,
|
2019-08-10 02:29:56 +08:00
|
|
|
lastReadMessageTime,
|
|
|
|
hasUnreadMessages,
|
|
|
|
scrollPosition,
|
|
|
|
UnsentMessagesCollection,
|
|
|
|
minMessageLength,
|
|
|
|
maxMessageLength,
|
2019-09-06 23:15:42 +08:00
|
|
|
amIModerator,
|
2020-08-15 01:13:51 +08:00
|
|
|
meetingIsBreakout,
|
2017-09-26 07:45:44 +08:00
|
|
|
} = props;
|
2016-06-02 00:33:19 +08:00
|
|
|
|
2018-11-01 02:51:56 +08:00
|
|
|
const HIDE_CHAT_AK = shortcuts.hidePrivateChat;
|
|
|
|
const CLOSE_CHAT_AK = shortcuts.closePrivateChat;
|
|
|
|
|
2017-09-26 07:45:44 +08:00
|
|
|
return (
|
2018-01-09 10:43:34 +08:00
|
|
|
<div
|
|
|
|
data-test="publicChat"
|
|
|
|
className={styles.chat}
|
|
|
|
>
|
2018-10-12 04:41:37 +08:00
|
|
|
<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');
|
2018-10-12 04:41:37 +08:00
|
|
|
}}
|
|
|
|
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}
|
2018-10-12 04:41:37 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{
|
2018-12-18 23:15:51 +08:00
|
|
|
chatID !== 'public'
|
|
|
|
? (
|
|
|
|
<Button
|
|
|
|
icon="close"
|
2019-03-20 01:11:48 +08:00
|
|
|
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');
|
|
|
|
}}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.closeChatLabel, { 0: title })}
|
|
|
|
label={intl.formatMessage(intlMessages.closeChatLabel, { 0: title })}
|
|
|
|
accessKey={CLOSE_CHAT_AK}
|
|
|
|
/>
|
|
|
|
)
|
2020-08-15 01:13:51 +08:00
|
|
|
: <ChatDropdown {...{ meetingIsBreakout, isMeteorConnected, amIModerator }} />
|
2018-10-12 04:41:37 +08:00
|
|
|
}
|
|
|
|
</header>
|
2017-09-26 07:45:44 +08:00
|
|
|
<MessageList
|
|
|
|
id={ELEMENT_ID}
|
2019-07-31 10:37:50 +08:00
|
|
|
chatId={chatID}
|
2017-09-26 07:45:44 +08:00
|
|
|
handleScrollUpdate={actions.handleScrollUpdate}
|
|
|
|
handleReadMessage={actions.handleReadMessage}
|
2019-07-31 10:37:50 +08:00
|
|
|
{...{
|
|
|
|
partnerIsLoggedOut,
|
|
|
|
lastReadMessageTime,
|
|
|
|
hasUnreadMessages,
|
|
|
|
scrollPosition,
|
|
|
|
messages,
|
|
|
|
}}
|
2017-09-26 07:45:44 +08:00
|
|
|
/>
|
|
|
|
<MessageForm
|
2019-07-31 10:37:50 +08:00
|
|
|
{...{
|
|
|
|
UnsentMessagesCollection,
|
|
|
|
chatName,
|
|
|
|
minMessageLength,
|
|
|
|
maxMessageLength,
|
|
|
|
}}
|
2019-02-01 20:13:45 +08:00
|
|
|
chatId={chatID}
|
2017-09-26 07:45:44 +08:00
|
|
|
chatTitle={title}
|
2019-07-31 10:37:50 +08:00
|
|
|
chatAreaId={ELEMENT_ID}
|
|
|
|
disabled={isChatLocked || !isMeteorConnected}
|
2019-08-07 00:57:55 +08:00
|
|
|
connected={isMeteorConnected}
|
2019-08-02 22:40:43 +08:00
|
|
|
locked={isChatLocked}
|
2017-09-26 07:45:44 +08:00
|
|
|
handleSendMessage={actions.handleSendMessage}
|
2019-08-03 00:39:27 +08:00
|
|
|
partnerIsLoggedOut={partnerIsLoggedOut}
|
2017-09-26 07:45:44 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-12-17 19:48:34 +08:00
|
|
|
export default withShortcutHelper(injectWbResizeEvent(injectIntl(memo(Chat))), ['hidePrivateChat', 'closePrivateChat']);
|
2017-03-29 23:35:07 +08:00
|
|
|
|
2017-10-11 06:08:51 +08:00
|
|
|
const propTypes = {
|
2017-09-26 07:45:44 +08:00
|
|
|
chatID: PropTypes.string.isRequired,
|
|
|
|
chatName: PropTypes.string.isRequired,
|
|
|
|
title: PropTypes.string.isRequired,
|
2017-12-16 01:18:35 +08:00
|
|
|
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),
|
2017-09-26 07:45:44 +08:00
|
|
|
partnerIsLoggedOut: PropTypes.bool.isRequired,
|
|
|
|
isChatLocked: PropTypes.bool.isRequired,
|
2019-06-27 00:29:34 +08:00
|
|
|
isMeteorConnected: PropTypes.bool.isRequired,
|
2017-09-26 07:45:44 +08:00
|
|
|
actions: PropTypes.shape({
|
|
|
|
handleClosePrivateChat: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
};
|
2017-10-11 06:08:51 +08:00
|
|
|
|
2017-12-16 01:18:35 +08:00
|
|
|
const defaultProps = {
|
2019-06-03 22:19:56 +08:00
|
|
|
shortcuts: [],
|
2017-12-16 01:18:35 +08:00
|
|
|
};
|
|
|
|
|
2017-10-11 06:08:51 +08:00
|
|
|
Chat.propTypes = propTypes;
|
2017-12-16 01:18:35 +08:00
|
|
|
Chat.defaultProps = defaultProps;
|