diff --git a/web/chat/message-preview.react.js b/web/chat/message-preview.react.js index e04728c72..8bb337020 100644 --- a/web/chat/message-preview.react.js +++ b/web/chat/message-preview.react.js @@ -1,71 +1,71 @@ // @flow import classNames from 'classnames'; import * as React from 'react'; import { getMessageTitle } from 'lib/shared/message-utils'; import { threadIsGroupChat } from 'lib/shared/thread-utils'; import { stringForUser } from 'lib/shared/user-utils'; import { type MessageInfo, messageTypes, type ComposableMessageInfo, type RobotextMessageInfo, } from 'lib/types/message-types'; import { type ThreadInfo } from 'lib/types/thread-types'; import { getDefaultTextMessageRules } from '../markdown/rules.react'; import css from './chat-thread-list.css'; type Props = { +messageInfo: ?MessageInfo, +threadInfo: ThreadInfo, }; function MessagePreview(props: Props): React.Node { const { messageInfo: originalMessageInfo, threadInfo, threadInfo: { currentUser: { unread }, }, } = props; const colorStyle = unread ? css.unread : css.read; if (!originalMessageInfo) { return (
No messages
); } const messageInfo: ComposableMessageInfo | RobotextMessageInfo = originalMessageInfo.type === messageTypes.SIDEBAR_SOURCE ? originalMessageInfo.sourceMessage : originalMessageInfo; const messageTitle = getMessageTitle( messageInfo, threadInfo, getDefaultTextMessageRules().simpleMarkdownRules, ); + const hasUsername = + threadIsGroupChat(threadInfo) || + threadInfo.name !== '' || + messageInfo.creator.isViewer; + let usernameText = null; - if ( - messageInfo.type === messageTypes.TEXT && - (threadIsGroupChat(threadInfo) || - threadInfo.name !== '' || - messageInfo.creator.isViewer) - ) { + if (messageInfo.type === messageTypes.TEXT && hasUsername) { const userString = stringForUser(messageInfo.creator); usernameText = {`${userString}: `}; } return (
{usernameText} {messageTitle}
); } export default MessagePreview;