import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { View } from 'react-native';
import Touchable from 'react-native-platform-touchable';
import MessageContext from './Context';
import User from './User';
import styles from './styles';
import RepliedThread from './RepliedThread';
import MessageAvatar from './MessageAvatar';
import Attachments from './Attachments';
import Urls from './Urls';
import Thread from './Thread';
import Blocks from './Blocks';
import Reactions from './Reactions';
import Broadcast from './Broadcast';
import Discussion from './Discussion';
import Content from './Content';
import ReadReceipt from './ReadReceipt';
import CallButton from './CallButton';
import { themes } from '../../constants/colors';
const MessageInner = React.memo((props) => {
if (props.type === 'discussion-created') {
return (
<>
<User {...props} />
<Discussion {...props} />
</>
);
}
if (props.type === 'jitsi_call_started') {
<Content {...props} isInfo />
<CallButton {...props} />
if (props.blocks && props.blocks.length) {
<Blocks {...props} />
<Thread {...props} />
<Reactions {...props} />
<Content {...props} />
<Attachments {...props} />
<Urls {...props} />
<Broadcast {...props} />
});
MessageInner.displayName = 'MessageInner';
const Message = React.memo((props) => {
if (props.isThreadReply || props.isThreadSequential || props.isInfo || props.isIgnored) {
const thread = props.isThreadReply ? <RepliedThread {...props} /> : null;
<View style={[styles.container, props.style]}>
{thread}
<View style={styles.flex}>
<MessageAvatar small {...props} />
<View
style={[
styles.messageContent,
props.isHeader && styles.messageContentWithHeader
]}
>
</View>
<MessageAvatar {...props} />
<MessageInner {...props} />
<ReadReceipt
isReadReceiptEnabled={props.isReadReceiptEnabled}
unread={props.unread}
theme={props.theme}
/>
Message.displayName = 'Message';
const MessageTouchable = React.memo((props) => {
if (props.hasError) {
<View>
<Message {...props} />
const { onPress, onLongPress } = useContext(MessageContext);
<Touchable
onLongPress={onLongPress}
onPress={onPress}
disabled={(props.isInfo && !props.isThreadReply) || props.archived || props.isTemp}
style={{ backgroundColor: props.highlighted ? themes[props.theme].headerBackground : null }}
</Touchable>
MessageTouchable.displayName = 'MessageTouchable';
MessageTouchable.propTypes = {
hasError: PropTypes.bool,
isInfo: PropTypes.bool,
isThreadReply: PropTypes.bool,
isTemp: PropTypes.bool,
archived: PropTypes.bool,
highlighted: PropTypes.bool,
theme: PropTypes.string
};
Message.propTypes = {
isThreadSequential: PropTypes.bool,
isHeader: PropTypes.bool,
style: PropTypes.any,
onLongPress: PropTypes.func,
isReadReceiptEnabled: PropTypes.bool,
unread: PropTypes.bool,
theme: PropTypes.string,
isIgnored: PropTypes.bool
MessageInner.propTypes = {
type: PropTypes.string,
blocks: PropTypes.array
export default MessageTouchable;