/* Copyright 2019 New Vector Ltd Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React, {useEffect} from 'react'; import PropTypes from 'prop-types'; import { _t } from '../../../languageHandler'; import sdk from '../../../index'; import dis from '../../../dispatcher'; import Modal from '../../../Modal'; import {aboveLeftOf, ContextMenu, ContextMenuButton, useContextMenu} from '../../structures/ContextMenu'; import { isContentActionable, canEditContent } from '../../../utils/EventUtils'; import {RoomContext} from "../../structures/RoomView"; const OptionsButton = ({mxEvent, getTile, getReplyThread, permalinkCreator, onFocusChange}) => { const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu(); useEffect(() => { onFocusChange(menuDisplayed); }, [onFocusChange, menuDisplayed]); let contextMenu; if (menuDisplayed) { const MessageContextMenu = sdk.getComponent('context_menus.MessageContextMenu'); const tile = getTile && getTile(); const replyThread = getReplyThread && getReplyThread(); const onCryptoClick = () => { Modal.createTrackedDialogAsync('Encrypted Event Dialog', '', import('../../../async-components/views/dialogs/EncryptedEventDialog'), {event: mxEvent}, ); }; let e2eInfoCallback = null; if (mxEvent.isEncrypted()) { e2eInfoCallback = onCryptoClick; } const buttonRect = button.current.getBoundingClientRect(); contextMenu = ; } return { contextMenu } ; }; const ReactButton = ({mxEvent, reactions, onFocusChange}) => { const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu(); useEffect(() => { onFocusChange(menuDisplayed); }, [onFocusChange, menuDisplayed]); let contextMenu; if (menuDisplayed) { const buttonRect = button.current.getBoundingClientRect(); const ReactionPicker = sdk.getComponent('emojipicker.ReactionPicker'); contextMenu = ; } return { contextMenu } ; }; export default class MessageActionBar extends React.PureComponent { static propTypes = { mxEvent: PropTypes.object.isRequired, // The Relations model from the JS SDK for reactions to `mxEvent` reactions: PropTypes.object, permalinkCreator: PropTypes.object, getTile: PropTypes.func, getReplyThread: PropTypes.func, onFocusChange: PropTypes.func, }; static contextTypes = { room: RoomContext, }; componentDidMount() { this.props.mxEvent.on("Event.decrypted", this.onDecrypted); } componentWillUnmount() { this.props.mxEvent.removeListener("Event.decrypted", this.onDecrypted); } onDecrypted = () => { // When an event decrypts, it is likely to change the set of available // actions, so we force an update to check again. this.forceUpdate(); }; onFocusChange = (focused) => { if (!this.props.onFocusChange) { return; } this.props.onFocusChange(focused); }; onReplyClick = (ev) => { dis.dispatch({ action: 'reply_to_event', event: this.props.mxEvent, }); }; onEditClick = (ev) => { dis.dispatch({ action: 'edit_event', event: this.props.mxEvent, }); }; render() { const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); let reactButton; let replyButton; let editButton; if (isContentActionable(this.props.mxEvent)) { if (this.context.room.canReact) { reactButton = ( ); } if (this.context.room.canReply) { replyButton = ; } } if (canEditContent(this.props.mxEvent)) { editButton = ; } // aria-live=off to not have this read out automatically as navigating around timeline, gets repetitive. return
{reactButton} {replyButton} {editButton}
; } }