2019-05-20 20:43:50 +00:00
|
|
|
import React from 'react';
|
2018-09-11 16:32:52 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { View } from 'react-native';
|
2019-04-08 12:35:28 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2018-09-11 16:32:52 +00:00
|
|
|
|
|
|
|
import User from './User';
|
2019-05-20 20:43:50 +00:00
|
|
|
import MessageError from './MessageError';
|
2018-09-11 16:32:52 +00:00
|
|
|
import styles from './styles';
|
2019-05-03 13:33:38 +00:00
|
|
|
import sharedStyles from '../../views/Styles';
|
2019-05-20 20:43:50 +00:00
|
|
|
import RepliedThread from './RepliedThread';
|
|
|
|
import MessageAvatar from './MessageAvatar';
|
|
|
|
import Attachments from './Attachments';
|
|
|
|
import Urls from './Urls';
|
|
|
|
import Thread from './Thread';
|
|
|
|
import Reactions from './Reactions';
|
|
|
|
import Broadcast from './Broadcast';
|
|
|
|
import Discussion from './Discussion';
|
|
|
|
import Content from './Content';
|
|
|
|
|
|
|
|
const MessageInner = React.memo((props) => {
|
|
|
|
if (props.type === 'discussion-created') {
|
2019-04-08 12:35:28 +00:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2019-05-20 20:43:50 +00:00
|
|
|
<User {...props} />
|
|
|
|
<Discussion {...props} />
|
2019-04-08 12:35:28 +00:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<User {...props} />
|
|
|
|
<Content {...props} />
|
|
|
|
<Attachments {...props} />
|
|
|
|
<Urls {...props} />
|
|
|
|
<Thread {...props} />
|
|
|
|
<Reactions {...props} />
|
|
|
|
<Broadcast {...props} />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
MessageInner.displayName = 'MessageInner';
|
|
|
|
|
|
|
|
const Message = React.memo((props) => {
|
|
|
|
if (props.isThreadReply || props.isThreadSequential || props.isInfo) {
|
|
|
|
const thread = props.isThreadReply ? <RepliedThread isTemp={props.isTemp} {...props} /> : null;
|
2019-04-17 17:01:03 +00:00
|
|
|
return (
|
2019-05-20 20:43:50 +00:00
|
|
|
<View style={[styles.container, props.style, props.isTemp && styles.temp]}>
|
|
|
|
{thread}
|
|
|
|
<View style={[styles.flex, sharedStyles.alignItemsCenter]}>
|
|
|
|
<MessageAvatar small {...props} />
|
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.messageContent,
|
2019-05-21 13:32:06 +00:00
|
|
|
props.isHeader && styles.messageContentWithHeader
|
2019-05-20 20:43:50 +00:00
|
|
|
]}
|
|
|
|
>
|
|
|
|
<Content {...props} />
|
|
|
|
</View>
|
|
|
|
</View>
|
2019-04-24 18:36:29 +00:00
|
|
|
</View>
|
2019-04-17 17:01:03 +00:00
|
|
|
);
|
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
|
|
|
<View style={[styles.container, props.style, props.isTemp && styles.temp]}>
|
2019-05-03 13:33:38 +00:00
|
|
|
<View style={styles.flex}>
|
2019-05-20 20:43:50 +00:00
|
|
|
<MessageAvatar {...props} />
|
2019-05-03 13:33:38 +00:00
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.messageContent,
|
2019-05-21 13:32:06 +00:00
|
|
|
props.isHeader && styles.messageContentWithHeader
|
2019-05-03 13:33:38 +00:00
|
|
|
]}
|
|
|
|
>
|
2019-05-20 20:43:50 +00:00
|
|
|
<MessageInner {...props} />
|
2019-05-03 13:33:38 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
Message.displayName = 'Message';
|
2018-09-11 16:32:52 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
const MessageTouchable = React.memo((props) => {
|
|
|
|
if (props.hasError) {
|
2018-09-11 16:32:52 +00:00
|
|
|
return (
|
2018-11-16 11:06:29 +00:00
|
|
|
<View style={styles.root}>
|
2019-05-20 20:43:50 +00:00
|
|
|
<MessageError {...props} />
|
|
|
|
<Message {...props} />
|
2018-11-16 11:06:29 +00:00
|
|
|
</View>
|
2018-09-11 16:32:52 +00:00
|
|
|
);
|
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
|
|
|
<Touchable
|
|
|
|
onLongPress={props.onLongPress}
|
|
|
|
onPress={props.onPress}
|
|
|
|
disabled={props.isInfo || props.archived || props.isTemp}
|
|
|
|
>
|
|
|
|
<View>
|
|
|
|
<Message {...props} />
|
|
|
|
</View>
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
MessageTouchable.displayName = 'MessageTouchable';
|
|
|
|
|
|
|
|
MessageTouchable.propTypes = {
|
|
|
|
hasError: PropTypes.bool,
|
|
|
|
isInfo: PropTypes.bool,
|
|
|
|
isTemp: PropTypes.bool,
|
|
|
|
archived: PropTypes.bool,
|
|
|
|
onLongPress: PropTypes.func,
|
|
|
|
onPress: PropTypes.func
|
|
|
|
};
|
|
|
|
|
|
|
|
Message.propTypes = {
|
|
|
|
isThreadReply: PropTypes.bool,
|
|
|
|
isThreadSequential: PropTypes.bool,
|
|
|
|
isInfo: PropTypes.bool,
|
|
|
|
isTemp: PropTypes.bool,
|
|
|
|
isHeader: PropTypes.bool,
|
|
|
|
hasError: PropTypes.bool,
|
|
|
|
style: PropTypes.any,
|
|
|
|
onLongPress: PropTypes.func,
|
|
|
|
onPress: PropTypes.func
|
|
|
|
};
|
|
|
|
|
|
|
|
MessageInner.propTypes = {
|
|
|
|
type: PropTypes.string
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MessageTouchable;
|