From 4c85c04d4569953f2e16759f9be5940e4f61e204 Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Mon, 6 Dec 2021 16:52:47 -0500 Subject: [PATCH] Adds all message actions to context menu --- ts/components/conversation/Message.tsx | 21 ++++++++++++------- .../conversation/MessageBodyReadMore.tsx | 4 ++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index 0ce920cf1fe5..1fc4dcbb1aed 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -18,7 +18,10 @@ import type { import { ReadStatus } from '../../messages/MessageReadStatus'; import { Avatar } from '../Avatar'; import { Spinner } from '../Spinner'; -import { MessageBodyReadMore } from './MessageBodyReadMore'; +import { + doesMessageBodyOverflow, + MessageBodyReadMore, +} from './MessageBodyReadMore'; import { MessageMetadata } from './MessageMetadata'; import { ImageGrid } from './ImageGrid'; import { GIF } from './GIF'; @@ -1367,7 +1370,7 @@ export class Message extends React.PureComponent { {({ ref: popperRef }) => { // Only attach the popper reference to the reaction button if it is // visible (it is hidden when the timeline is narrow) - const maybePopperRef = this.shouldShowAdditionalMenuButtons() + const maybePopperRef = this.isWindowWidthNotNarrow() ? popperRef : undefined; @@ -1421,7 +1424,7 @@ export class Message extends React.PureComponent { {({ ref: popperRef }) => { // Only attach the popper reference to the collapsed menu button if the reaction // button is not visible (it is hidden when the timeline is narrow) - const maybePopperRef = !this.shouldShowAdditionalMenuButtons() + const maybePopperRef = !this.isWindowWidthNotNarrow() ? popperRef : undefined; @@ -1459,7 +1462,7 @@ export class Message extends React.PureComponent { `module-message__buttons--${direction}` )} > - {this.shouldShowAdditionalMenuButtons() && ( + {this.isWindowWidthNotNarrow() && ( <> {canReply ? reactButton : null} {canDownload ? downloadButton : null} @@ -1520,6 +1523,7 @@ export class Message extends React.PureComponent { showForwardMessageModal, showMessageDetail, status, + text, } = this.props; const canForward = !isTapToView && !deletedForEveryone; @@ -1531,10 +1535,13 @@ export class Message extends React.PureComponent { direction === 'outgoing'; const multipleAttachments = attachments && attachments.length > 1; + const shouldShowAdditional = + doesMessageBodyOverflow(text || '') || !this.isWindowWidthNotNarrow(); + const menu = ( {canDownload && - !this.shouldShowAdditionalMenuButtons() && + shouldShowAdditional && !isSticker && !multipleAttachments && !isTapToView && @@ -1550,7 +1557,7 @@ export class Message extends React.PureComponent { {i18n('downloadAttachment')} ) : null} - {canReply && !this.shouldShowAdditionalMenuButtons() ? ( + {canReply && shouldShowAdditional ? ( <> { return ReactDOM.createPortal(menu, document.body); } - private shouldShowAdditionalMenuButtons(): boolean { + private isWindowWidthNotNarrow(): boolean { const { containerWidthBreakpoint } = this.props; return containerWidthBreakpoint !== WidthBreakpoint.Narrow; } diff --git a/ts/components/conversation/MessageBodyReadMore.tsx b/ts/components/conversation/MessageBodyReadMore.tsx index ed1d43bd0873..6ca1d57b246b 100644 --- a/ts/components/conversation/MessageBodyReadMore.tsx +++ b/ts/components/conversation/MessageBodyReadMore.tsx @@ -27,6 +27,10 @@ const INITIAL_LENGTH = 800; const INCREMENT_COUNT = 3000; const BUFFER = 100; +export function doesMessageBodyOverflow(str: string): boolean { + return str.length > INITIAL_LENGTH + BUFFER; +} + function graphemeAwareSlice( str: string, length: number