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';
|
2018-11-01 02:51:56 +08:00
|
|
|
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
|
2021-05-18 04:25:07 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2021-03-10 04:52:20 +08:00
|
|
|
import ChatLogger from '/imports/ui/components/chat/chat-logger/ChatLogger';
|
2021-11-02 21:55:09 +08:00
|
|
|
import Styled from './styles';
|
2021-05-18 04:25:07 +08:00
|
|
|
import MessageFormContainer from './message-form/container';
|
2021-01-20 01:06:32 +08:00
|
|
|
import TimeWindowList from './time-window-list/container';
|
2020-08-04 21:27:32 +08:00
|
|
|
import ChatDropdownContainer from './chat-dropdown/container';
|
2021-05-18 04:25:07 +08:00
|
|
|
import { PANELS, ACTIONS } from '../layout/enums';
|
2021-05-19 03:59:42 +08:00
|
|
|
import { UserSentMessageCollection } from './service';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
2021-11-02 21:55:09 +08:00
|
|
|
import browserInfo from '/imports/utils/browserInfo';
|
2022-05-20 01:28:58 +08:00
|
|
|
import Header from '/imports/ui/components/common/control-header/component';
|
2016-06-02 00:33:19 +08:00
|
|
|
|
2021-05-18 04:25:07 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const PUBLIC_CHAT_ID = CHAT_CONFIG.public_id;
|
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
|
|
|
});
|
2021-01-20 01:06:32 +08:00
|
|
|
|
2017-09-26 07:45:44 +08:00
|
|
|
const Chat = (props) => {
|
|
|
|
const {
|
|
|
|
chatID,
|
|
|
|
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,
|
2019-09-06 23:15:42 +08:00
|
|
|
amIModerator,
|
2020-08-15 01:13:51 +08:00
|
|
|
meetingIsBreakout,
|
2021-01-20 01:06:32 +08:00
|
|
|
timeWindowsValues,
|
|
|
|
dispatch,
|
|
|
|
count,
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch,
|
2021-03-10 04:52:20 +08:00
|
|
|
syncing,
|
|
|
|
syncedPercent,
|
2021-03-25 21:41:13 +08:00
|
|
|
lastTimeWindowValuesBuild,
|
2017-09-26 07:45:44 +08:00
|
|
|
} = props;
|
2021-04-09 22:16:49 +08:00
|
|
|
|
2021-05-19 03:59:42 +08:00
|
|
|
const userSentMessage = UserSentMessageCollection.findOne({ userId: Auth.userID, sent: true });
|
2021-11-02 21:55:09 +08:00
|
|
|
const { isChrome } = browserInfo;
|
2021-05-19 03:59:42 +08:00
|
|
|
|
2021-06-23 02:24:24 +08:00
|
|
|
const HIDE_CHAT_AK = shortcuts.hideprivatechat;
|
|
|
|
const CLOSE_CHAT_AK = shortcuts.closeprivatechat;
|
2022-01-20 21:03:18 +08:00
|
|
|
const isPublicChat = chatID === PUBLIC_CHAT_ID;
|
2021-03-10 04:52:20 +08:00
|
|
|
ChatLogger.debug('ChatComponent::render', props);
|
2017-09-26 07:45:44 +08:00
|
|
|
return (
|
2021-11-02 21:55:09 +08:00
|
|
|
<Styled.Chat
|
|
|
|
isChrome={isChrome}
|
2022-01-20 21:03:18 +08:00
|
|
|
data-test={isPublicChat ? 'publicChat' : 'privateChat'}
|
2018-01-09 10:43:34 +08:00
|
|
|
>
|
2022-05-20 01:28:58 +08:00
|
|
|
<Header
|
2022-06-08 02:52:22 +08:00
|
|
|
data-test="chatTitle"
|
2022-05-20 01:28:58 +08:00
|
|
|
leftButtonProps={{
|
|
|
|
accessKey: chatID !== 'public' ? HIDE_CHAT_AK : null,
|
|
|
|
'aria-label': intl.formatMessage(intlMessages.hideChatLabel, { 0: title }),
|
|
|
|
'data-test': isPublicChat ? 'hidePublicChat' : 'hidePrivateChat',
|
|
|
|
label: title,
|
|
|
|
onClick: () => {
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
|
|
|
|
value: false,
|
|
|
|
});
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_ID_CHAT_OPEN,
|
|
|
|
value: '',
|
|
|
|
});
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
|
|
|
|
value: PANELS.NONE,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
rightButtonProps={{
|
|
|
|
accessKey: CLOSE_CHAT_AK,
|
|
|
|
'aria-label': intl.formatMessage(intlMessages.closeChatLabel, { 0: title }),
|
|
|
|
'data-test': "closePrivateChat",
|
|
|
|
icon: "close",
|
|
|
|
label: intl.formatMessage(intlMessages.closeChatLabel, { 0: title }),
|
|
|
|
onClick: () => {
|
|
|
|
actions.handleClosePrivateChat(chatID);
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
|
|
|
|
value: false,
|
|
|
|
});
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_ID_CHAT_OPEN,
|
|
|
|
value: '',
|
|
|
|
});
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
|
|
|
|
value: PANELS.NONE,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
customRightButton={isPublicChat && (
|
|
|
|
<ChatDropdownContainer {...{
|
|
|
|
meetingIsBreakout, isMeteorConnected, amIModerator, timeWindowsValues,
|
|
|
|
}}
|
2018-10-12 04:41:37 +08:00
|
|
|
/>
|
2022-05-20 01:28:58 +08:00
|
|
|
)}
|
|
|
|
/>
|
2021-01-20 01:06:32 +08:00
|
|
|
<TimeWindowList
|
2017-09-26 07:45:44 +08:00
|
|
|
id={ELEMENT_ID}
|
2019-07-31 10:37:50 +08:00
|
|
|
chatId={chatID}
|
2017-09-26 07:45:44 +08:00
|
|
|
handleScrollUpdate={actions.handleScrollUpdate}
|
2019-07-31 10:37:50 +08:00
|
|
|
{...{
|
|
|
|
partnerIsLoggedOut,
|
|
|
|
lastReadMessageTime,
|
|
|
|
hasUnreadMessages,
|
|
|
|
scrollPosition,
|
|
|
|
messages,
|
2021-01-20 01:06:32 +08:00
|
|
|
currentUserIsModerator: amIModerator,
|
|
|
|
timeWindowsValues,
|
|
|
|
dispatch,
|
|
|
|
count,
|
2021-03-10 04:52:20 +08:00
|
|
|
syncing,
|
|
|
|
syncedPercent,
|
2021-03-25 21:41:13 +08:00
|
|
|
lastTimeWindowValuesBuild,
|
2021-08-09 22:24:02 +08:00
|
|
|
userSentMessage,
|
2019-07-31 10:37:50 +08:00
|
|
|
}}
|
2017-09-26 07:45:44 +08:00
|
|
|
/>
|
2021-05-18 04:25:07 +08:00
|
|
|
<MessageFormContainer
|
2019-07-31 10:37:50 +08:00
|
|
|
{...{
|
2021-02-09 20:44:01 +08:00
|
|
|
title,
|
2019-07-31 10:37:50 +08:00
|
|
|
}}
|
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}
|
2019-08-03 00:39:27 +08:00
|
|
|
partnerIsLoggedOut={partnerIsLoggedOut}
|
2017-09-26 07:45:44 +08:00
|
|
|
/>
|
2021-11-02 21:55:09 +08:00
|
|
|
</Styled.Chat>
|
2017-09-26 07:45:44 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-05-18 21:04:17 +08:00
|
|
|
export default memo(withShortcutHelper(injectWbResizeEvent(injectIntl(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,
|
|
|
|
title: PropTypes.string.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;
|