// @flow import React from 'react'; import { Text, View } from 'react-native'; import { Avatar } from '../../../base/avatar'; import { translate } from '../../../base/i18n'; import { Linkify } from '../../../base/react'; import { replaceNonUnicodeEmojis } from '../../functions'; import AbstractChatMessage, { type Props } from '../AbstractChatMessage'; import PrivateMessageButton from '../PrivateMessageButton'; import styles from './styles'; /** * Renders a single chat message. */ class ChatMessage extends AbstractChatMessage { /** * Implements {@code Component#render}. * * @inheritdoc */ render() { const { message } = this.props; const localMessage = message.messageType === 'local'; // Style arrays that need to be updated in various scenarios, such as // error messages or others. const detailsWrapperStyle = [ styles.detailsWrapper ]; const textWrapperStyle = [ styles.textWrapper ]; if (localMessage) { // The wrapper needs to be aligned to the right. detailsWrapperStyle.push(styles.ownMessageDetailsWrapper); // The bubble needs to be differently styled. textWrapperStyle.push(styles.ownTextWrapper); } else if (message.messageType === 'error') { // The bubble needs to be differently styled. textWrapperStyle.push(styles.systemTextWrapper); } return ( { this._renderAvatar() } { this.props.showDisplayName && this._renderDisplayName() } { replaceNonUnicodeEmojis(this._getMessageText()) } { message.privateMessage && this._renderPrivateNotice() } { message.privateMessage && !localMessage && } { this.props.showTimestamp && this._renderTimestamp() } ); } _getFormattedTimestamp: () => string; _getMessageText: () => string; _getPrivateNoticeMessage: () => string; /** * Renders the avatar of the sender. * * @returns {React$Element<*>} */ _renderAvatar() { const { message } = this.props; return ( { this.props.showAvatar && } ); } /** * Renders the display name of the sender. * * @returns {React$Element<*>} */ _renderDisplayName() { return ( { this.props.message.displayName } ); } /** * Renders the message privacy notice. * * @returns {React$Element<*>} */ _renderPrivateNotice() { return ( { this._getPrivateNoticeMessage() } ); } /** * Renders the time at which the message was sent. * * @returns {React$Element<*>} */ _renderTimestamp() { return ( { this._getFormattedTimestamp() } ); } } export default translate(ChatMessage);