import React, { useContext } from 'react'; import { View, Text } from 'react-native'; import PropTypes from 'prop-types'; import Touchable from 'react-native-platform-touchable'; import { formatMessageCount } from './utils'; import styles from './styles'; import { CustomIcon } from '../../lib/Icons'; import { THREAD } from './constants'; import { themes } from '../../constants/colors'; import { formatDateThreads } from '../../utils/room'; import MessageContext from './Context'; const Thread = React.memo(({ msg, tcount, tlm, isThreadRoom, theme, id }) => { if (!tlm || isThreadRoom || tcount === 0) { return null; } const { threadBadgeColor, toggleFollowThread, user, replies } = useContext(MessageContext); const time = formatDateThreads(tlm); const buttonText = formatMessageCount(tcount, THREAD); const isFollowing = replies?.find(u => u === user.id); return ( {buttonText} {time} {threadBadgeColor ? : null} toggleFollowThread(isFollowing, id)}> ); }, (prevProps, nextProps) => { if (prevProps.tcount !== nextProps.tcount) { return false; } if (prevProps.theme !== nextProps.theme) { return false; } return true; }); Thread.propTypes = { msg: PropTypes.string, tcount: PropTypes.string, theme: PropTypes.string, tlm: PropTypes.string, isThreadRoom: PropTypes.bool, id: PropTypes.string }; Thread.displayName = 'MessageThread'; export default Thread;