2020-10-30 17:35:07 +00:00
|
|
|
import React, { useContext } from 'react';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { View, Text } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import styles from './styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2020-10-30 17:35:07 +00:00
|
|
|
import MessageContext from './Context';
|
2021-01-25 17:14:45 +00:00
|
|
|
import ThreadDetails from '../ThreadDetails';
|
|
|
|
import I18n from '../../i18n';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
const Thread = React.memo(({
|
2020-10-30 17:35:07 +00:00
|
|
|
msg, tcount, tlm, isThreadRoom, theme, id
|
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;
|
|
|
|
}
|
|
|
|
|
2020-10-30 17:35:07 +00:00
|
|
|
const {
|
2020-11-12 14:17:32 +00:00
|
|
|
threadBadgeColor, toggleFollowThread, user, replies
|
2020-10-30 17:35:07 +00:00
|
|
|
} = useContext(MessageContext);
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.buttonContainer}>
|
|
|
|
<View
|
2020-10-30 17:35:07 +00:00
|
|
|
style={[styles.button, { backgroundColor: themes[theme].tintColor }]}
|
2019-05-20 20:43:50 +00:00
|
|
|
testID={`message-thread-button-${ msg }`}
|
|
|
|
>
|
2021-01-25 17:14:45 +00:00
|
|
|
<Text style={[styles.buttonText, { color: themes[theme].buttonText }]}>{I18n.t('Reply')}</Text>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
2021-01-25 17:14:45 +00:00
|
|
|
<ThreadDetails
|
|
|
|
item={{
|
|
|
|
tcount,
|
|
|
|
replies,
|
|
|
|
tlm,
|
|
|
|
id
|
|
|
|
}}
|
|
|
|
user={user}
|
|
|
|
badgeColor={threadBadgeColor}
|
|
|
|
toggleFollowThread={toggleFollowThread}
|
|
|
|
style={styles.threadDetails}
|
|
|
|
/>
|
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,
|
2020-10-30 17:35:07 +00:00
|
|
|
isThreadRoom: PropTypes.bool,
|
|
|
|
id: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
Thread.displayName = 'MessageThread';
|
|
|
|
|
|
|
|
export default Thread;
|