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

182 lines
5.5 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 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';
import TimeWindowList from './time-window-list/container';
import ChatDropdownContainer from './chat-dropdown/container';
2021-05-18 04:25:07 +08:00
import { PANELS, ACTIONS } from '../layout/enums';
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';
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
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,
amIModerator,
meetingIsBreakout,
timeWindowsValues,
dispatch,
count,
2021-08-05 19:03:24 +08:00
layoutContextDispatch,
2021-03-10 04:52:20 +08:00
syncing,
syncedPercent,
lastTimeWindowValuesBuild,
2022-07-26 03:53:19 +08:00
width,
} = props;
const userSentMessage = UserSentMessageCollection.findOne({ userId: Auth.userID, sent: true });
2021-11-02 21:55:09 +08:00
const { isChrome } = browserInfo;
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);
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
>
<Header
2022-06-08 02:52:22 +08:00
data-test="chatTitle"
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,
}}
/>
)}
/>
<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,
2021-08-09 22:24:02 +08:00
userSentMessage,
2022-07-26 03:53:19 +08:00
width,
2019-07-31 10:37:50 +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}
chatTitle={title}
2019-07-31 10:37:50 +08:00
chatAreaId={ELEMENT_ID}
disabled={isChatLocked || !isMeteorConnected}
connected={isMeteorConnected}
locked={isChatLocked}
partnerIsLoggedOut={partnerIsLoggedOut}
/>
2021-11-02 21:55:09 +08:00
</Styled.Chat>
);
};
export default memo(withShortcutHelper(injectWbResizeEvent(injectIntl(Chat)), ['hidePrivateChat', 'closePrivateChat']));
2017-10-11 06:08:51 +08:00
const propTypes = {
chatID: PropTypes.string.isRequired,
title: PropTypes.string.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;