diff --git a/native/chat/message-preview.react.js b/native/chat/message-preview.react.js index 76022dbff..b3e7ff048 100644 --- a/native/chat/message-preview.react.js +++ b/native/chat/message-preview.react.js @@ -1,100 +1,104 @@ // @flow import PropTypes from 'prop-types'; import * as React from 'react'; import { Text } from 'react-native'; import { messagePreviewText } from 'lib/shared/message-utils'; import { threadIsGroupChat } from 'lib/shared/thread-utils'; import { stringForUser } from 'lib/shared/user-utils'; import { type MessageInfo, messageInfoPropType, messageTypes, } from 'lib/types/message-types'; import { type ThreadInfo, threadInfoPropType } from 'lib/types/thread-types'; import { connect } from 'lib/utils/redux-utils'; import { firstLine } from 'lib/utils/string-utils'; import { SingleLine } from '../components/single-line.react'; import type { AppState } from '../redux/redux-setup'; import { styleSelector } from '../themes/colors'; type Props = {| messageInfo: MessageInfo, threadInfo: ThreadInfo, // Redux state styles: typeof styles, |}; class MessagePreview extends React.PureComponent { static propTypes = { messageInfo: messageInfoPropType.isRequired, threadInfo: threadInfoPropType.isRequired, styles: PropTypes.objectOf(PropTypes.object).isRequired, }; render() { const messageInfo: MessageInfo = this.props.messageInfo; const unreadStyle = this.props.threadInfo.currentUser.unread ? this.props.styles.unread : null; if (messageInfo.type === messageTypes.TEXT) { let usernameText = null; - if (threadIsGroupChat(this.props.threadInfo)) { + if ( + threadIsGroupChat(this.props.threadInfo) || + this.props.threadInfo.name !== '' || + messageInfo.creator.isViewer + ) { const userString = stringForUser(messageInfo.creator); const username = `${userString}: `; usernameText = ( {username} ); } const firstMessageLine = firstLine(messageInfo.text); return ( {usernameText} {firstMessageLine} ); } else { const preview = messagePreviewText(messageInfo, this.props.threadInfo); return ( {preview} ); } } } const styles = { lastMessage: { color: 'listForegroundTertiaryLabel', flex: 1, fontSize: 16, paddingLeft: 10, }, preview: { color: 'listForegroundQuaternaryLabel', }, unread: { color: 'listForegroundLabel', }, username: { color: 'listForegroundQuaternaryLabel', }, }; const stylesSelector = styleSelector(styles); export default connect((state: AppState) => ({ styles: stylesSelector(state), }))(MessagePreview); diff --git a/web/chat/message-preview.react.js b/web/chat/message-preview.react.js index 6c71fa2d8..0b6b3625d 100644 --- a/web/chat/message-preview.react.js +++ b/web/chat/message-preview.react.js @@ -1,66 +1,70 @@ // @flow import classNames from 'classnames'; import * as React from 'react'; import { messagePreviewText } from 'lib/shared/message-utils'; import { threadIsGroupChat } from 'lib/shared/thread-utils'; import { stringForUser } from 'lib/shared/user-utils'; import { type MessageInfo, messageInfoPropType, messageTypes, } from 'lib/types/message-types'; import { type ThreadInfo, threadInfoPropType } from 'lib/types/thread-types'; import { firstLine } from 'lib/utils/string-utils'; import css from './chat-thread-list.css'; type Props = {| messageInfo: ?MessageInfo, threadInfo: ThreadInfo, |}; class MessagePreview extends React.PureComponent { static propTypes = { messageInfo: messageInfoPropType, threadInfo: threadInfoPropType.isRequired, }; render() { const messageInfo = this.props.messageInfo; if (!messageInfo) { return (
No messages
); } const unread = this.props.threadInfo.currentUser.unread; if (messageInfo.type === messageTypes.TEXT) { let usernameText = null; - if (threadIsGroupChat(this.props.threadInfo)) { + if ( + threadIsGroupChat(this.props.threadInfo) || + this.props.threadInfo.name !== '' || + messageInfo.creator.isViewer + ) { const userString = stringForUser(messageInfo.creator); const username = `${userString}: `; const usernameStyle = unread ? css.black : css.light; usernameText = {username}; } const colorStyle = unread ? css.black : css.dark; return (
{usernameText} {firstLine(messageInfo.text)}
); } else { const preview = messagePreviewText(messageInfo, this.props.threadInfo); const colorStyle = unread ? css.black : css.light; return (
{firstLine(preview)}
); } } } export default MessagePreview;