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

164 lines
4.6 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
2022-02-15 23:54:55 +08:00
import { withModalMounter } from '/imports/ui/components/common/modal/service';
2017-07-22 02:17:25 +08:00
import _ from 'lodash';
2022-06-22 00:42:46 +08:00
import BBBMenu from '/imports/ui/components/common/menu/component';
import { getDateString } from '/imports/utils/string-utils';
2022-06-22 00:42:46 +08:00
import Trigger from '/imports/ui/components/common/control-header/right/component';
import ChatService from '../service';
import { addNewAlert } from '../../screenreader-alert/service';
const intlMessages = defineMessages({
clear: {
id: 'app.chat.dropdown.clear',
description: 'Clear button label',
},
save: {
id: 'app.chat.dropdown.save',
description: 'Clear button label',
},
copy: {
id: 'app.chat.dropdown.copy',
description: 'Copy button label',
},
copySuccess: {
id: 'app.chat.copySuccess',
description: 'aria success alert',
},
copyErr: {
id: 'app.chat.copyErr',
description: 'aria error alert',
},
options: {
id: 'app.chat.dropdown.options',
description: 'Chat Options',
},
});
const CHAT_CONFIG = Meteor.settings.public.chat;
const ENABLE_SAVE_AND_COPY_PUBLIC_CHAT = CHAT_CONFIG.enableSaveAndCopyPublicChat;
class ChatDropdown extends PureComponent {
constructor(props) {
super(props);
2018-01-20 01:38:04 +08:00
this.actionsKey = [
_.uniqueId('action-item-'),
_.uniqueId('action-item-'),
_.uniqueId('action-item-'),
];
}
2017-07-22 02:17:25 +08:00
getAvailableActions() {
const {
intl,
isMeteorConnected,
amIModerator,
meetingIsBreakout,
meetingName,
timeWindowsValues,
} = this.props;
2017-07-22 02:17:25 +08:00
2017-07-28 04:45:40 +08:00
const clearIcon = 'delete';
const saveIcon = 'download';
2017-07-28 04:45:40 +08:00
const copyIcon = 'copy';
2022-04-18 21:27:46 +08:00
this.menuItems = [];
2022-04-18 21:27:46 +08:00
if (ENABLE_SAVE_AND_COPY_PUBLIC_CHAT) {
this.menuItems.push(
{
key: this.actionsKey[0],
icon: saveIcon,
dataTest: 'chatSave',
label: intl.formatMessage(intlMessages.save),
onClick: () => {
const link = document.createElement('a');
const mimeType = 'text/plain';
link.setAttribute('download', `bbb-${meetingName}[public-chat]_${getDateString()}.txt`);
2022-04-18 21:27:46 +08:00
link.setAttribute(
'href',
`data: ${mimeType};charset=utf-8,`
+ `${encodeURIComponent(ChatService.exportChat(timeWindowsValues, intl))}`,
2022-04-18 21:27:46 +08:00
);
link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
},
},
);
}
if (ENABLE_SAVE_AND_COPY_PUBLIC_CHAT) {
this.menuItems.push(
{
key: this.actionsKey[1],
icon: copyIcon,
id: 'clipboardButton',
dataTest: 'chatCopy',
label: intl.formatMessage(intlMessages.copy),
onClick: () => {
const chatHistory = ChatService.exportChat(timeWindowsValues, intl);
2022-04-18 21:27:46 +08:00
navigator.clipboard.writeText(chatHistory).then(() => {
addNewAlert(intl.formatMessage(intlMessages.copySuccess));
2022-04-18 21:27:46 +08:00
}).catch(() => {
addNewAlert(intl.formatMessage(intlMessages.copyErr));
2022-04-18 21:27:46 +08:00
});
},
},
);
}
if (!meetingIsBreakout && amIModerator && isMeteorConnected) {
this.menuItems.push(
{
key: this.actionsKey[2],
icon: clearIcon,
dataTest: 'chatClear',
label: intl.formatMessage(intlMessages.clear),
onClick: () => ChatService.clearPublicChatHistory(),
},
);
}
return this.menuItems;
2017-07-22 02:17:25 +08:00
}
render() {
const {
intl,
amIModerator,
2022-05-13 21:42:19 +08:00
isRTL,
} = this.props;
if (!amIModerator && !ENABLE_SAVE_AND_COPY_PUBLIC_CHAT) return null;
return (
<>
2022-04-18 21:27:46 +08:00
<BBBMenu
trigger={
<Trigger
2022-04-18 21:27:46 +08:00
data-test="chatOptionsMenu"
icon="more"
label={intl.formatMessage(intlMessages.options)}
aria-label={intl.formatMessage(intlMessages.options)}
onClick={() => null}
/>
}
2022-04-18 21:27:46 +08:00
opts={{
2022-10-06 05:54:59 +08:00
id: 'chat-options-dropdown-menu',
2022-04-18 21:27:46 +08:00
keepMounted: true,
transitionDuration: 0,
elevation: 3,
getContentAnchorEl: null,
fullwidth: 'true',
anchorOrigin: { vertical: 'bottom', horizontal: isRTL ? 'right' : 'left' },
transformOrigin: { vertical: 'top', horizontal: isRTL ? 'right' : 'left' },
2022-04-18 21:27:46 +08:00
}}
actions={this.getAvailableActions()}
/>
</>
);
}
}
export default withModalMounter(injectIntl(ChatDropdown));