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

181 lines
5.0 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
import { withModalMounter } from '/imports/ui/components/modal/service';
import Clipboard from 'clipboard';
2017-07-22 02:17:25 +08:00
import _ from 'lodash';
import Dropdown from '/imports/ui/components/dropdown/component';
import DropdownTrigger from '/imports/ui/components/dropdown/trigger/component';
import DropdownContent from '/imports/ui/components/dropdown/content/component';
import DropdownList from '/imports/ui/components/dropdown/list/component';
import DropdownListItem from '/imports/ui/components/dropdown/list/item/component';
import Button from '/imports/ui/components/button/component';
import ChatService from '../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',
},
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);
this.state = {
isSettingOpen: false,
};
this.onActionsShow = this.onActionsShow.bind(this);
this.onActionsHide = this.onActionsHide.bind(this);
2018-01-20 01:38:04 +08:00
this.actionsKey = [
_.uniqueId('action-item-'),
_.uniqueId('action-item-'),
_.uniqueId('action-item-'),
];
}
componentDidMount() {
this.clipboard = new Clipboard('#clipboardButton', {
text: () => '',
});
}
2021-02-13 03:43:56 +08:00
componentDidUpdate(prevProps, prevState) {
2021-04-12 20:13:42 +08:00
const { timeWindowsValues, users, intl } = this.props;
2021-02-13 03:43:56 +08:00
const { isSettingOpen } = this.state;
if (prevState.isSettingOpen !== isSettingOpen) {
this.clipboard = new Clipboard('#clipboardButton', {
2021-04-12 20:13:42 +08:00
text: () => ChatService.exportChat(timeWindowsValues, users, intl),
2021-02-13 03:43:56 +08:00
});
}
}
componentWillUnmount() {
this.clipboard.destroy();
}
onActionsShow() {
this.setState({
isSettingOpen: true,
});
}
onActionsHide() {
this.setState({
isSettingOpen: false,
});
}
2017-07-22 02:17:25 +08:00
getAvailableActions() {
const {
intl,
isMeteorConnected,
amIModerator,
meetingIsBreakout,
meetingName,
timeWindowsValues,
users,
} = 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';
2017-07-22 02:17:25 +08:00
return _.compact([
ENABLE_SAVE_AND_COPY_PUBLIC_CHAT
&& (
2018-01-20 01:38:04 +08:00
<DropdownListItem
data-test="chatSave"
2017-07-28 04:45:40 +08:00
icon={saveIcon}
2017-07-22 02:17:25 +08:00
label={intl.formatMessage(intlMessages.save)}
2018-01-20 01:38:04 +08:00
key={this.actionsKey[0]}
2017-07-22 02:17:25 +08:00
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`);
2018-01-20 01:38:04 +08:00
link.setAttribute(
'href',
`data: ${mimeType} ;charset=utf-8,`
+ `${encodeURIComponent(ChatService.exportChat(timeWindowsValues, users, intl))}`,
2018-01-20 01:38:04 +08:00
);
2019-02-15 05:32:44 +08:00
link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
2017-07-22 02:17:25 +08:00
}}
/>
),
ENABLE_SAVE_AND_COPY_PUBLIC_CHAT
&& (
2018-01-20 01:38:04 +08:00
<DropdownListItem
data-test="chatCopy"
2017-07-28 04:45:40 +08:00
icon={copyIcon}
2017-07-22 02:17:25 +08:00
id="clipboardButton"
label={intl.formatMessage(intlMessages.copy)}
2018-01-20 01:38:04 +08:00
key={this.actionsKey[1]}
/>
),
!meetingIsBreakout && amIModerator && isMeteorConnected ? (
2017-07-28 04:45:40 +08:00
<DropdownListItem
data-test="chatClear"
2017-07-28 04:45:40 +08:00
icon={clearIcon}
label={intl.formatMessage(intlMessages.clear)}
2018-01-20 01:38:04 +08:00
key={this.actionsKey[2]}
2017-08-03 01:05:20 +08:00
onClick={ChatService.clearPublicChatHistory}
2017-07-28 04:45:40 +08:00
/>
2018-01-20 01:38:04 +08:00
) : null,
2017-07-22 02:17:25 +08:00
]);
}
render() {
const { intl } = this.props;
2019-06-25 02:06:02 +08:00
const { isSettingOpen } = this.state;
2017-07-22 02:17:25 +08:00
const availableActions = this.getAvailableActions();
return (
<Dropdown
2019-06-25 02:06:02 +08:00
isOpen={isSettingOpen}
onShow={this.onActionsShow}
onHide={this.onActionsHide}
>
<DropdownTrigger tabIndex={0}>
<Button
2018-01-09 10:43:34 +08:00
data-test="chatDropdownTrigger"
icon="more"
size="sm"
ghost
circle
hideLabel
color="dark"
2017-12-16 01:45:14 +08:00
label={intl.formatMessage(intlMessages.options)}
aria-label={intl.formatMessage(intlMessages.options)}
2017-12-16 01:45:14 +08:00
onClick={() => null}
/>
</DropdownTrigger>
<DropdownContent placement="bottom right">
2018-01-20 01:38:04 +08:00
<DropdownList>{availableActions}</DropdownList>
</DropdownContent>
</Dropdown>
);
}
}
export default withModalMounter(injectIntl(ChatDropdown));