jiti-meet/react/features/chat/components/native/ChatMessage.js

147 lines
4.3 KiB
JavaScript
Raw Normal View History

// @flow
import React from 'react';
import { Text, View } from 'react-native';
2019-06-26 14:08:23 +00:00
import { Avatar } from '../../../base/avatar';
import { translate } from '../../../base/i18n';
2019-08-05 10:46:10 +00:00
import { Linkify } from '../../../base/react';
2019-08-23 14:41:10 +00:00
import { replaceNonUnicodeEmojis } from '../../functions';
2019-06-26 14:08:23 +00:00
import AbstractChatMessage, { type Props } from '../AbstractChatMessage';
2019-10-07 12:35:04 +00:00
import PrivateMessageButton from '../PrivateMessageButton';
2019-08-23 14:41:10 +00:00
import styles from './styles';
/**
* Renders a single chat message.
*/
class ChatMessage extends AbstractChatMessage<Props> {
/**
* 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 (
<View style = { styles.messageWrapper } >
{ this._renderAvatar() }
<View style = { detailsWrapperStyle }>
2019-10-07 12:35:04 +00:00
<View style = { styles.replyWrapper }>
<View style = { textWrapperStyle } >
{
this.props.showDisplayName
&& this._renderDisplayName()
}
<Linkify linkStyle = { styles.chatLink }>
2019-10-09 08:34:01 +00:00
{ replaceNonUnicodeEmojis(this._getMessageText()) }
2019-10-07 12:35:04 +00:00
</Linkify>
{
message.privateMessage
&& this._renderPrivateNotice()
}
</View>
{ message.privateMessage && !localMessage
&& <PrivateMessageButton
participantID = { message.id }
reply = { true }
showLabel = { false }
toggledStyles = { styles.replyStyles } /> }
</View>
{ this.props.showTimestamp && this._renderTimestamp() }
</View>
</View>
);
}
_getFormattedTimestamp: () => string;
2019-10-09 08:34:01 +00:00
_getMessageText: () => string;
2019-10-07 12:35:04 +00:00
_getPrivateNoticeMessage: () => string;
/**
* Renders the avatar of the sender.
*
* @returns {React$Element<*>}
*/
_renderAvatar() {
const { message } = this.props;
return (
<View style = { styles.avatarWrapper }>
{ this.props.showAvatar && <Avatar
displayName = { message.displayName }
participantId = { message.id }
2019-06-26 14:08:23 +00:00
size = { styles.avatarWrapper.width } />
}
</View>
);
}
/**
* Renders the display name of the sender.
*
* @returns {React$Element<*>}
*/
_renderDisplayName() {
return (
<Text style = { styles.displayName }>
{ this.props.message.displayName }
</Text>
);
}
2019-10-07 12:35:04 +00:00
/**
* Renders the message privacy notice.
*
* @returns {React$Element<*>}
*/
_renderPrivateNotice() {
return (
<Text style = { styles.privateNotice }>
{ this._getPrivateNoticeMessage() }
</Text>
);
}
/**
* Renders the time at which the message was sent.
*
* @returns {React$Element<*>}
*/
_renderTimestamp() {
return (
<Text style = { styles.timeText }>
{ this._getFormattedTimestamp() }
</Text>
);
}
}
2019-06-26 14:08:23 +00:00
export default translate(ChatMessage);