2017-09-26 07:45:44 +08:00
|
|
|
import React from 'react';
|
|
|
|
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-01-08 14:17:18 +08:00
|
|
|
import { styles } from './styles';
|
2016-06-02 00:33:19 +08:00
|
|
|
import MessageForm from './message-form/component';
|
|
|
|
import MessageList from './message-list/component';
|
2017-08-08 22:52:26 +08:00
|
|
|
import ChatDropdown from './chat-dropdown/component';
|
2016-06-02 00:33:19 +08:00
|
|
|
import Icon from '../icon/component';
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2018-05-01 05:09:56 +08:00
|
|
|
const SHORTCUTS_CONFIG = Meteor.settings.public.app.shortcuts;
|
2018-05-02 08:02:45 +08:00
|
|
|
const HIDE_CHAT_AK = SHORTCUTS_CONFIG.hidePrivateChat.accesskey;
|
|
|
|
const CLOSE_CHAT_AK = SHORTCUTS_CONFIG.closePrivateChat.accesskey;
|
2018-05-01 05:09:56 +08:00
|
|
|
|
2017-09-26 07:45:44 +08:00
|
|
|
const Chat = (props) => {
|
|
|
|
const {
|
|
|
|
chatID,
|
|
|
|
chatName,
|
|
|
|
title,
|
|
|
|
messages,
|
|
|
|
scrollPosition,
|
|
|
|
hasUnreadMessages,
|
|
|
|
lastReadMessageTime,
|
|
|
|
partnerIsLoggedOut,
|
|
|
|
isChatLocked,
|
|
|
|
minMessageLength,
|
|
|
|
maxMessageLength,
|
|
|
|
actions,
|
|
|
|
intl,
|
|
|
|
} = props;
|
2016-06-02 00:33:19 +08:00
|
|
|
|
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={() => {
|
|
|
|
Session.set('isChatOpen', false);
|
|
|
|
}}
|
|
|
|
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>
|
|
|
|
{
|
|
|
|
chatID !== 'public' ?
|
|
|
|
<Button
|
|
|
|
className={styles.closeBtn}
|
|
|
|
icon="close"
|
|
|
|
size="md"
|
|
|
|
hideLabel
|
|
|
|
onClick={() => {
|
|
|
|
actions.handleClosePrivateChat(chatID);
|
2018-10-24 22:29:51 +08:00
|
|
|
Session.set('isChatOpen', false);
|
2018-10-12 04:41:37 +08:00
|
|
|
Session.set('idChatOpen', '');
|
|
|
|
}}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.closeChatLabel, { 0: title })}
|
|
|
|
label={intl.formatMessage(intlMessages.closeChatLabel, { 0: title })}
|
|
|
|
accessKey={CLOSE_CHAT_AK}
|
|
|
|
/>
|
|
|
|
:
|
|
|
|
<ChatDropdown />
|
|
|
|
}
|
|
|
|
</header>
|
2017-09-26 07:45:44 +08:00
|
|
|
<MessageList
|
|
|
|
chatId={chatID}
|
|
|
|
messages={messages}
|
|
|
|
id={ELEMENT_ID}
|
|
|
|
scrollPosition={scrollPosition}
|
|
|
|
hasUnreadMessages={hasUnreadMessages}
|
|
|
|
handleScrollUpdate={actions.handleScrollUpdate}
|
|
|
|
handleReadMessage={actions.handleReadMessage}
|
|
|
|
lastReadMessageTime={lastReadMessageTime}
|
|
|
|
partnerIsLoggedOut={partnerIsLoggedOut}
|
|
|
|
/>
|
|
|
|
<MessageForm
|
|
|
|
disabled={isChatLocked}
|
|
|
|
chatAreaId={ELEMENT_ID}
|
|
|
|
chatTitle={title}
|
|
|
|
chatName={chatName}
|
|
|
|
minMessageLength={minMessageLength}
|
|
|
|
maxMessageLength={maxMessageLength}
|
|
|
|
handleSendMessage={actions.handleSendMessage}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default injectWbResizeEvent(injectIntl(Chat));
|
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,
|
|
|
|
scrollPosition: PropTypes.number,
|
2017-09-26 07:45:44 +08:00
|
|
|
hasUnreadMessages: PropTypes.bool.isRequired,
|
|
|
|
lastReadMessageTime: PropTypes.number.isRequired,
|
|
|
|
partnerIsLoggedOut: PropTypes.bool.isRequired,
|
|
|
|
isChatLocked: PropTypes.bool.isRequired,
|
|
|
|
minMessageLength: PropTypes.number.isRequired,
|
|
|
|
maxMessageLength: PropTypes.number.isRequired,
|
|
|
|
actions: PropTypes.shape({
|
|
|
|
handleClosePrivateChat: PropTypes.func.isRequired,
|
|
|
|
handleReadMessage: PropTypes.func.isRequired,
|
|
|
|
handleScrollUpdate: PropTypes.func.isRequired,
|
|
|
|
handleSendMessage: 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 = {
|
|
|
|
scrollPosition: 0,
|
|
|
|
};
|
|
|
|
|
2017-10-11 06:08:51 +08:00
|
|
|
Chat.propTypes = propTypes;
|
2017-12-16 01:18:35 +08:00
|
|
|
Chat.defaultProps = defaultProps;
|