2016-04-29 03:02:51 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { Link } from 'react-router';
|
2017-03-29 23:35:07 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-07-21 22:16:45 +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
|
|
|
});
|
|
|
|
|
|
|
|
class Chat extends Component {
|
2016-06-02 00:33:19 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
2017-03-24 05:52:36 +08:00
|
|
|
componentDidMount() {
|
|
|
|
//to let the whiteboard know that the presentation area's size has changed
|
|
|
|
window.dispatchEvent(new Event('resize'));
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
//to let the whiteboard know that the presentation area's size has changed
|
|
|
|
window.dispatchEvent(new Event('resize'));
|
|
|
|
}
|
|
|
|
|
2016-04-29 03:02:51 +08:00
|
|
|
render() {
|
2016-06-02 00:33:19 +08:00
|
|
|
const {
|
2016-07-01 01:10:36 +08:00
|
|
|
chatID,
|
2016-12-07 21:48:29 +08:00
|
|
|
chatName,
|
2016-06-02 00:33:19 +08:00
|
|
|
title,
|
|
|
|
messages,
|
2016-07-01 01:10:36 +08:00
|
|
|
scrollPosition,
|
2016-07-05 21:34:13 +08:00
|
|
|
hasUnreadMessages,
|
2016-07-12 03:42:54 +08:00
|
|
|
lastReadMessageTime,
|
2017-04-07 05:08:20 +08:00
|
|
|
partnerIsLoggedOut,
|
2016-06-07 22:19:19 +08:00
|
|
|
isChatLocked,
|
2017-06-01 22:24:29 +08:00
|
|
|
minMessageLength,
|
|
|
|
maxMessageLength,
|
2016-06-03 02:40:27 +08:00
|
|
|
actions,
|
2017-03-29 23:35:07 +08:00
|
|
|
intl,
|
2016-06-02 00:33:19 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2016-04-29 03:02:51 +08:00
|
|
|
return (
|
2017-04-20 21:53:03 +08:00
|
|
|
<div className={styles.chat}>
|
2016-06-02 00:33:19 +08:00
|
|
|
<header className={styles.header}>
|
2017-03-17 06:39:34 +08:00
|
|
|
<div className={styles.title}>
|
2017-03-29 23:35:07 +08:00
|
|
|
<Link
|
|
|
|
to="/users"
|
|
|
|
role="button"
|
2017-06-03 03:25:02 +08:00
|
|
|
aria-label={intl.formatMessage(intlMessages.hideChatLabel, { 0: title })}
|
|
|
|
>
|
|
|
|
<Icon iconName="left_arrow" /> {title}
|
2017-03-17 06:39:34 +08:00
|
|
|
</Link>
|
|
|
|
</div>
|
2017-08-17 10:24:59 +08:00
|
|
|
{
|
|
|
|
chatID !== 'public' ?
|
|
|
|
<Link
|
|
|
|
to="/users"
|
|
|
|
role="button"
|
|
|
|
className={styles.closeIcon}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.closeChatLabel, { 0: title })}
|
|
|
|
>
|
|
|
|
<Icon iconName="close" onClick={() => actions.handleClosePrivateChat(chatID)} />
|
|
|
|
</Link> :
|
|
|
|
<ChatDropdown />
|
|
|
|
}
|
2016-06-02 00:33:19 +08:00
|
|
|
</header>
|
|
|
|
<MessageList
|
2016-07-01 01:10:36 +08:00
|
|
|
chatId={chatID}
|
2016-06-02 00:33:19 +08:00
|
|
|
messages={messages}
|
|
|
|
id={ELEMENT_ID}
|
2016-07-01 01:10:36 +08:00
|
|
|
scrollPosition={scrollPosition}
|
2016-07-05 21:34:13 +08:00
|
|
|
hasUnreadMessages={hasUnreadMessages}
|
2016-07-01 01:10:36 +08:00
|
|
|
handleScrollUpdate={actions.handleScrollUpdate}
|
2016-07-05 02:53:47 +08:00
|
|
|
handleReadMessage={actions.handleReadMessage}
|
2016-07-12 03:42:54 +08:00
|
|
|
lastReadMessageTime={lastReadMessageTime}
|
2017-04-07 05:08:20 +08:00
|
|
|
partnerIsLoggedOut={partnerIsLoggedOut}
|
2016-06-02 00:33:19 +08:00
|
|
|
/>
|
2016-06-03 02:40:27 +08:00
|
|
|
<MessageForm
|
2016-06-07 22:19:19 +08:00
|
|
|
disabled={isChatLocked}
|
2016-06-03 02:40:27 +08:00
|
|
|
chatAreaId={ELEMENT_ID}
|
|
|
|
chatTitle={title}
|
2016-12-07 21:48:29 +08:00
|
|
|
chatName={chatName}
|
2017-06-01 22:24:29 +08:00
|
|
|
minMessageLength={minMessageLength}
|
|
|
|
maxMessageLength={maxMessageLength}
|
2016-06-03 02:40:27 +08:00
|
|
|
handleSendMessage={actions.handleSendMessage}
|
|
|
|
/>
|
2017-04-20 21:53:03 +08:00
|
|
|
</div>
|
2016-04-29 03:02:51 +08:00
|
|
|
);
|
|
|
|
}
|
2017-07-21 22:16:45 +08:00
|
|
|
};
|
2017-03-29 23:35:07 +08:00
|
|
|
|
|
|
|
export default injectIntl(Chat);
|