diff --git a/web/chat/composed-message.react.js b/web/chat/composed-message.react.js --- a/web/chat/composed-message.react.js +++ b/web/chat/composed-message.react.js @@ -47,36 +47,41 @@ tooltipPositions.TOP, ]; -type BaseProps = { +type Props = { +item: ChatMessageInfoItem, +threadInfo: ThreadInfo, +shouldDisplayPinIndicator: boolean, +sendFailed: boolean, +children: React.Node, +fixedWidth?: boolean, - +borderRadius: number, -}; -type DefaultProps = { +borderRadius: number }; -type BaseConfig = React.Config; -type Props = { - ...BaseProps, - +onMouseLeave: ?() => mixed, - +onMouseEnter: (event: SyntheticEvent) => mixed, - +stringForUser: ?string, - +onClickUser: () => mixed, + +borderRadius?: number, }; -class ComposedMessage extends React.PureComponent { - static defaultProps: DefaultProps = { borderRadius: 8 }; +const ComposedMessage: React.ComponentType = React.memo( + function ComposedMessage(props) { + const { item, threadInfo } = props; + const { creator } = item.messageInfo; + const { isViewer } = creator; + const availablePositions = isViewer + ? availableTooltipPositionsForViewerMessage + : availableTooltipPositionsForNonViewerMessage; + + const { onMouseLeave, onMouseEnter } = useMessageTooltip({ + item, + threadInfo, + availablePositions, + }); + + const shouldShowUsername = !isViewer && item.startsCluster; + + const pushUserProfileModal = usePushUserProfileModal(creator.id); - render(): React.Node { - assertComposableMessageType(this.props.item.messageInfo.type); - const { borderRadius, item, threadInfo, shouldDisplayPinIndicator } = - this.props; + assertComposableMessageType(item.messageInfo.type); + const { shouldDisplayPinIndicator } = props; + const borderRadius = props.borderRadius ?? 8; const { hasBeenEdited, isPinned } = item; - const { id, creator } = item.messageInfo; + const { id } = item.messageInfo; const threadColor = threadInfo.color; - const { isViewer } = creator; const contentClassName = classNames({ [css.content]: true, [css.viewerContent]: isViewer, @@ -84,11 +89,11 @@ }); const messageBoxContainerClassName = classNames({ [css.messageBoxContainer]: true, - [css.fixedWidthMessageBoxContainer]: this.props.fixedWidth, + [css.fixedWidthMessageBoxContainer]: props.fixedWidth, }); const messageBoxClassName = classNames({ [css.messageBox]: true, - [css.fixedWidthMessageBox]: this.props.fixedWidth, + [css.fixedWidthMessageBox]: props.fixedWidth, }); const messageBoxStyle = { borderTopRightRadius: isViewer && !item.startsCluster ? 0 : borderRadius, @@ -98,10 +103,10 @@ }; let authorName = null; - const { stringForUser } = this.props; + const stringForUser = useStringForUser(shouldShowUsername ? creator : null); if (stringForUser) { authorName = ( - + {stringForUser} ); @@ -121,7 +126,7 @@ notDeliveredP2PMessages.length === 0 ) { deliveryIconSpan = ; - } else if (this.props.sendFailed) { + } else if (props.sendFailed) { deliveryIconSpan = ; deliveryIconColor = 'FF0000'; failedSendInfo = ; @@ -163,7 +168,7 @@ let avatar; if (!isViewer && item.endsCluster) { avatar = ( -
+
); @@ -197,8 +202,8 @@ {avatar}
{pinIcon}
- {this.props.children} + {props.children}
{deliveryIcon} @@ -215,42 +220,7 @@ {inlineEngagement} ); - } -} - -type ConnectedConfig = React.Config< - BaseProps, - typeof ComposedMessage.defaultProps, ->; -const ConnectedComposedMessage: React.ComponentType = - React.memo(function ConnectedComposedMessage(props) { - const { item, threadInfo } = props; - const { creator } = props.item.messageInfo; - const { isViewer } = creator; - const availablePositions = isViewer - ? availableTooltipPositionsForViewerMessage - : availableTooltipPositionsForNonViewerMessage; - - const { onMouseLeave, onMouseEnter } = useMessageTooltip({ - item, - threadInfo, - availablePositions, - }); - - const shouldShowUsername = !isViewer && item.startsCluster; - const stringForUser = useStringForUser(shouldShowUsername ? creator : null); - - const pushUserProfileModal = usePushUserProfileModal(creator.id); - - return ( - - ); - }); + }, +); -export default ConnectedComposedMessage; +export default ComposedMessage;