2019-05-20 20:43:50 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { View, Text } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import { formatLastMessage, formatMessageCount } from './utils';
|
|
|
|
import styles from './styles';
|
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
|
|
|
import { THREAD } from './constants';
|
|
|
|
|
|
|
|
const Thread = React.memo(({
|
2019-10-07 20:56:30 +00:00
|
|
|
msg, tcount, tlm, customThreadTimeFormat, isThreadRoom
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
2019-10-07 20:56:30 +00:00
|
|
|
if (!tlm || isThreadRoom || tcount === 0) {
|
2019-05-20 20:43:50 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const time = formatLastMessage(tlm, customThreadTimeFormat);
|
|
|
|
const buttonText = formatMessageCount(tcount, THREAD);
|
|
|
|
return (
|
|
|
|
<View style={styles.buttonContainer}>
|
|
|
|
<View
|
|
|
|
style={[styles.button, styles.smallButton]}
|
|
|
|
testID={`message-thread-button-${ msg }`}
|
|
|
|
>
|
|
|
|
<CustomIcon name='thread' size={20} style={styles.buttonIcon} />
|
|
|
|
<Text style={styles.buttonText}>{buttonText}</Text>
|
|
|
|
</View>
|
|
|
|
<Text style={styles.time}>{time}</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}, (prevProps, nextProps) => {
|
|
|
|
if (prevProps.tcount !== nextProps.tcount) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
Thread.propTypes = {
|
|
|
|
msg: PropTypes.string,
|
|
|
|
tcount: PropTypes.string,
|
|
|
|
tlm: PropTypes.string,
|
2019-10-07 20:56:30 +00:00
|
|
|
customThreadTimeFormat: PropTypes.string,
|
|
|
|
isThreadRoom: PropTypes.bool
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
Thread.displayName = 'MessageThread';
|
|
|
|
|
|
|
|
export default Thread;
|