// @flow import React from 'react'; import { Text, View } from 'react-native'; import { Avatar } from '../../../base/avatar'; import { translate } from '../../../base/i18n'; import AbstractChatMessage, { type Props } from '../AbstractChatMessage'; 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() } { message.messageType === 'error' ? this.props.t('chat.error', { error: message.error, originalText: message.message }) : message.message } { this.props.showTimestamp && this._renderTimestamp() } ); } _getFormattedTimestamp: () => string; /** * Renders the avatar of the sender. * * @returns {React$Element<*>} */ _renderAvatar() { return ( { this.props.showAvatar && } ); } /** * Renders the display name of the sender. * * @returns {React$Element<*>} */ _renderDisplayName() { return ( { this.props.message.displayName } ); } /** * Renders the time at which the message was sent. * * @returns {React$Element<*>} */ _renderTimestamp() { return ( { this._getFormattedTimestamp() } ); } } export default translate(ChatMessage);