2018-12-17 19:48:34 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-07-21 22:16:45 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import { withModalMounter } from '/imports/ui/components/modal/service';
|
2017-07-22 02:17:25 +08:00
|
|
|
import _ from 'lodash';
|
2021-08-11 10:44:34 +08:00
|
|
|
import BBBMenu from "/imports/ui/components/menu/component";
|
2017-10-17 03:28:27 +08:00
|
|
|
import Button from '/imports/ui/components/button/component';
|
|
|
|
|
2021-09-06 03:22:06 +08:00
|
|
|
import { alertScreenReader } from '/imports/utils/dom-utils';
|
|
|
|
|
2018-12-10 10:12:42 +08:00
|
|
|
import ChatService from '../service';
|
2017-07-21 22:16:45 +08:00
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
2021-09-06 03:22:06 +08:00
|
|
|
copySuccess: {
|
|
|
|
id: 'app.chat.copySuccess',
|
|
|
|
description: 'aria success alert',
|
|
|
|
},
|
|
|
|
copyErr: {
|
|
|
|
id: 'app.chat.copyErr',
|
|
|
|
description: 'aria error alert',
|
|
|
|
},
|
2017-07-21 22:16:45 +08:00
|
|
|
options: {
|
|
|
|
id: 'app.chat.dropdown.options',
|
|
|
|
description: 'Chat Options',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-06-02 22:50:26 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const ENABLE_SAVE_AND_COPY_PUBLIC_CHAT = CHAT_CONFIG.enableSaveAndCopyPublicChat;
|
|
|
|
|
2018-12-17 19:48:34 +08:00
|
|
|
class ChatDropdown extends PureComponent {
|
2017-07-21 22:16:45 +08:00
|
|
|
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-21 22:16:45 +08:00
|
|
|
}
|
|
|
|
|
2017-07-22 02:17:25 +08:00
|
|
|
getAvailableActions() {
|
2020-08-04 21:27:32 +08:00
|
|
|
const {
|
2021-06-02 22:50:26 +08:00
|
|
|
intl,
|
|
|
|
isMeteorConnected,
|
|
|
|
amIModerator,
|
|
|
|
meetingIsBreakout,
|
|
|
|
meetingName,
|
|
|
|
timeWindowsValues,
|
|
|
|
users,
|
2020-08-04 21:27:32 +08:00
|
|
|
} = this.props;
|
2017-07-22 02:17:25 +08:00
|
|
|
|
2017-07-28 04:45:40 +08:00
|
|
|
const clearIcon = 'delete';
|
2019-02-22 06:15:33 +08:00
|
|
|
const saveIcon = 'download';
|
2017-07-28 04:45:40 +08:00
|
|
|
const copyIcon = 'copy';
|
2021-08-11 10:44:34 +08:00
|
|
|
|
|
|
|
this.menuItems = [];
|
2021-06-02 22:50:26 +08:00
|
|
|
ENABLE_SAVE_AND_COPY_PUBLIC_CHAT
|
|
|
|
&& (
|
2021-08-11 10:44:34 +08:00
|
|
|
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';
|
|
|
|
const date = new Date();
|
|
|
|
const time = `${date.getHours()}-${date.getMinutes()}`;
|
|
|
|
const dateString = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}_${time}`;
|
|
|
|
link.setAttribute('download', `bbb-${meetingName}[public-chat]_${dateString}.txt`);
|
|
|
|
link.setAttribute(
|
|
|
|
'href',
|
|
|
|
`data: ${mimeType} ;charset=utf-8,`
|
|
|
|
+ `${encodeURIComponent(ChatService.exportChat(timeWindowsValues, users, intl))}`,
|
|
|
|
);
|
|
|
|
link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2021-06-02 22:50:26 +08:00
|
|
|
),
|
|
|
|
ENABLE_SAVE_AND_COPY_PUBLIC_CHAT
|
|
|
|
&& (
|
2021-08-11 10:44:34 +08:00
|
|
|
this.menuItems.push(
|
|
|
|
{
|
|
|
|
key: this.actionsKey[1],
|
|
|
|
icon: copyIcon,
|
|
|
|
id: "clipboardButton",
|
|
|
|
dataTest: "chatCopy",
|
|
|
|
label: intl.formatMessage(intlMessages.copy),
|
|
|
|
onClick: () => {
|
|
|
|
let chatHistory = ChatService.exportChat(timeWindowsValues, users, intl);
|
2021-09-06 03:22:06 +08:00
|
|
|
navigator.clipboard.writeText(chatHistory).then(() => {
|
|
|
|
alertScreenReader(intl.formatMessage(intlMessages.copySuccess));
|
|
|
|
}).catch(() => {
|
|
|
|
alertScreenReader(intl.formatMessage(intlMessages.copyErr));
|
|
|
|
});
|
2021-08-11 10:44:34 +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
|
|
|
}
|
|
|
|
|
2017-07-21 22:16:45 +08:00
|
|
|
render() {
|
2021-06-05 02:51:29 +08:00
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
amIModerator,
|
|
|
|
} = this.props;
|
2017-07-21 22:16:45 +08:00
|
|
|
|
2021-06-05 02:51:29 +08:00
|
|
|
if (!amIModerator && !ENABLE_SAVE_AND_COPY_PUBLIC_CHAT) return null;
|
2017-07-21 22:16:45 +08:00
|
|
|
return (
|
2021-09-06 03:22:06 +08:00
|
|
|
<>
|
2021-08-11 10:44:34 +08:00
|
|
|
<BBBMenu
|
|
|
|
trigger={
|
2017-10-17 03:28:27 +08:00
|
|
|
<Button
|
2021-08-14 09:32:19 +08:00
|
|
|
data-test="chatOptionsMenu"
|
2017-10-17 03:28:27 +08:00
|
|
|
icon="more"
|
2019-03-20 01:11:48 +08:00
|
|
|
size="sm"
|
2017-10-17 03:28:27 +08:00
|
|
|
ghost
|
|
|
|
circle
|
|
|
|
hideLabel
|
2019-03-20 01:11:48 +08:00
|
|
|
color="dark"
|
2017-12-16 01:45:14 +08:00
|
|
|
label={intl.formatMessage(intlMessages.options)}
|
2017-10-24 22:52:49 +08:00
|
|
|
aria-label={intl.formatMessage(intlMessages.options)}
|
2017-12-16 01:45:14 +08:00
|
|
|
onClick={() => null}
|
2021-08-11 10:44:34 +08:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
opts={{
|
|
|
|
id: "default-dropdown-menu",
|
|
|
|
keepMounted: true,
|
|
|
|
transitionDuration: 0,
|
|
|
|
elevation: 3,
|
|
|
|
getContentAnchorEl: null,
|
|
|
|
fullwidth: "true",
|
|
|
|
anchorOrigin: { vertical: 'bottom', horizontal: 'left' },
|
|
|
|
transformorigin: { vertical: 'bottom', horizontal: 'left' },
|
|
|
|
}}
|
|
|
|
actions={this.getAvailableActions()}
|
|
|
|
/>
|
2021-09-06 03:22:06 +08:00
|
|
|
</>
|
2017-07-21 22:16:45 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withModalMounter(injectIntl(ChatDropdown));
|