From e4eeafd4852a2669c51ec465c740a4152fc3d0ac Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Sun, 21 Feb 2021 18:02:34 +0100 Subject: [PATCH] migrate the message context menu to IconizedContextMenu Signed-off-by: Michael Weimann --- res/css/_components.scss | 1 - .../context_menus/_MessageContextMenu.scss | 30 --- .../views/context_menus/MessageContextMenu.js | 172 ++++++++++++------ .../views/messages/MessageActionBar.js | 17 +- 4 files changed, 124 insertions(+), 96 deletions(-) delete mode 100644 res/css/views/context_menus/_MessageContextMenu.scss diff --git a/res/css/_components.scss b/res/css/_components.scss index ec3af8655e..77f13437a2 100644 --- a/res/css/_components.scss +++ b/res/css/_components.scss @@ -57,7 +57,6 @@ @import "./views/beta/_BetaCard.scss"; @import "./views/context_menus/_CallContextMenu.scss"; @import "./views/context_menus/_IconizedContextMenu.scss"; -@import "./views/context_menus/_MessageContextMenu.scss"; @import "./views/context_menus/_StatusMessageContextMenu.scss"; @import "./views/context_menus/_TagTileContextMenu.scss"; @import "./views/dialogs/_AddExistingToSpaceDialog.scss"; diff --git a/res/css/views/context_menus/_MessageContextMenu.scss b/res/css/views/context_menus/_MessageContextMenu.scss deleted file mode 100644 index 2ecb93e734..0000000000 --- a/res/css/views/context_menus/_MessageContextMenu.scss +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2015, 2016 OpenMarket Ltd - -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. -*/ - -.mx_MessageContextMenu { - padding: 6px; -} - -.mx_MessageContextMenu_field { - display: block; - padding: 3px 6px 3px 6px; - cursor: pointer; - white-space: nowrap; -} - -.mx_MessageContextMenu_field.mx_MessageContextMenu_fieldSet { - font-weight: bold; -} diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index eef10c995a..f0ee2cb259 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -22,13 +22,13 @@ import { EventStatus } from 'matrix-js-sdk/src/models/event'; import { MatrixClientPeg } from '../../../MatrixClientPeg'; import dis from '../../../dispatcher/dispatcher'; import * as sdk from '../../../index'; -import { _t } from '../../../languageHandler'; +import {_t} from '../../../languageHandler'; import Modal from '../../../Modal'; import Resend from '../../../Resend'; import SettingsStore from '../../../settings/SettingsStore'; import { isUrlPermitted } from '../../../HtmlUtils'; import { isContentActionable } from '../../../utils/EventUtils'; -import { MenuItem } from "../../structures/ContextMenu"; +import IconizedContextMenu, {IconizedContextMenuOption, IconizedContextMenuOptionList} from "./IconizedContextMenu"; import { EventType } from "matrix-js-sdk/src/@types/event"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import { ReadPinsEventId } from "../right_panel/PinnedMessagesCard"; @@ -257,55 +257,62 @@ export default class MessageContextMenu extends React.Component { let externalURLButton; let quoteButton; let collapseReplyThread; + const optionLists = []; // status is SENT before remote-echo, null after const isSent = !eventStatus || eventStatus === EventStatus.SENT; if (!mxEvent.isRedacted()) { if (unsentReactionsCount !== 0) { resendReactionsButton = ( - - { _t('Resend %(unsentCount)s reaction(s)', {unsentCount: unsentReactionsCount}) } - + ); } } if (isSent && this.state.canRedact) { redactButton = ( - - { _t('Remove') } - + ); } if (isContentActionable(mxEvent)) { forwardButton = ( - - { _t('Forward Message') } - + ); if (this.state.canPin) { pinButton = ( - - { this._isPinned() ? _t('Unpin Message') : _t('Pin Message') } - + ); } } const viewSourceButton = ( - - { _t('View Source') } - + ); if (this.props.eventTileOps) { if (this.props.eventTileOps.isWidgetHidden()) { unhidePreviewButton = ( - - { _t('Unhide Preview') } - + ); } } @@ -316,77 +323,130 @@ export default class MessageContextMenu extends React.Component { } // XXX: if we use room ID, we should also include a server where the event can be found (other than in the domain of the event ID) const permalinkButton = ( - - { mxEvent.isRedacted() || mxEvent.getType() !== 'm.room.message' - ? _t('Share Permalink') : _t('Share Message') } - + /> ); if (this.props.eventTileOps) { // this event is rendered using TextualBody quoteButton = ( - - { _t('Quote') } - + ); } // Bridges can provide a 'external_url' to link back to the source. if ( - typeof(mxEvent.event.content.external_url) === "string" && + typeof (mxEvent.event.content.external_url) === "string" && isUrlPermitted(mxEvent.event.content.external_url) ) { externalURLButton = ( - - { _t('Source URL') } - + /> ); } if (this.props.collapseReplyThread) { collapseReplyThread = ( - - { _t('Collapse Reply Thread') } - + ); } let reportEventButton; if (mxEvent.getSender() !== me) { reportEventButton = ( - - { _t('Report Content') } - + ); } + if (forwardButton || quoteButton || collapseReplyThread) { + optionLists.push(( + + {quoteButton} + {forwardButton} + {collapseReplyThread} + + )); + } + + if (resendReactionsButton) { + optionLists.push(( + + {resendReactionsButton} + + )); + } + + if (externalURLButton || permalinkButton) { + optionLists.push(( + + {externalURLButton} + {permalinkButton} + + )); + } + + if (pinButton || unhidePreviewButton) { + optionLists.push(( + + {pinButton} + {unhidePreviewButton} + + )); + } + + if (reportEventButton) { + optionLists.push(( + + {reportEventButton} + + )); + } + + if (viewSourceButton) { + optionLists.push(( + + {viewSourceButton} + + )); + } + + if (redactButton) { + optionLists.push(( + + {redactButton} + + )); + } + return ( -
- { resendReactionsButton } - { redactButton } - { forwardButton } - { pinButton } - { viewSourceButton } - { unhidePreviewButton } - { permalinkButton } - { quoteButton } - { externalURLButton } - { collapseReplyThread } - { reportEventButton } -
+ + {optionLists} + ); } } diff --git a/src/components/views/messages/MessageActionBar.js b/src/components/views/messages/MessageActionBar.js index 37737519ce..3d434e0ee2 100644 --- a/src/components/views/messages/MessageActionBar.js +++ b/src/components/views/messages/MessageActionBar.js @@ -48,15 +48,14 @@ const OptionsButton = ({mxEvent, getTile, getReplyThread, permalinkCreator, onFo const replyThread = getReplyThread && getReplyThread(); const buttonRect = button.current.getBoundingClientRect(); - contextMenu = - - ; + contextMenu = ; } return