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';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
const Thread = React.memo(({
|
2019-12-04 16:39:53 +00:00
|
|
|
msg, tcount, tlm, customThreadTimeFormat, isThreadRoom, theme
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
2019-09-26 17:12:27 +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
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.button, styles.smallButton, { backgroundColor: themes[theme].tintColor }]}
|
2019-05-20 20:43:50 +00:00
|
|
|
testID={`message-thread-button-${ msg }`}
|
|
|
|
>
|
2020-06-05 13:28:58 +00:00
|
|
|
<CustomIcon name='threads' size={20} style={[styles.buttonIcon, { color: themes[theme].buttonText }]} />
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.buttonText, { color: themes[theme].buttonText }]}>{buttonText}</Text>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}, (prevProps, nextProps) => {
|
|
|
|
if (prevProps.tcount !== nextProps.tcount) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-04 16:39:53 +00:00
|
|
|
if (prevProps.theme !== nextProps.theme) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
Thread.propTypes = {
|
|
|
|
msg: PropTypes.string,
|
|
|
|
tcount: PropTypes.string,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2019-05-20 20:43:50 +00:00
|
|
|
tlm: PropTypes.string,
|
2019-09-16 20:26:32 +00:00
|
|
|
customThreadTimeFormat: PropTypes.string,
|
|
|
|
isThreadRoom: PropTypes.bool
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
Thread.displayName = 'MessageThread';
|
|
|
|
|
|
|
|
export default Thread;
|