2021-05-26 17:24:54 +00:00
|
|
|
import React, { memo, useEffect, useState } from 'react';
|
2020-12-18 14:14:25 +00:00
|
|
|
import { View } from 'react-native';
|
2019-05-20 20:43:50 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
|
|
|
import styles from './styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2020-09-11 14:31:38 +00:00
|
|
|
import I18n from '../../i18n';
|
2020-12-18 14:14:25 +00:00
|
|
|
import Markdown from '../markdown';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2021-05-26 17:24:54 +00:00
|
|
|
const RepliedThread = memo(({
|
2020-09-11 14:31:38 +00:00
|
|
|
tmid, tmsg, isHeader, fetchThreadName, id, isEncrypted, theme
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
2019-10-08 12:36:15 +00:00
|
|
|
if (!tmid || !isHeader) {
|
2019-05-20 20:43:50 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-05-26 17:24:54 +00:00
|
|
|
const [msg, setMsg] = useState(isEncrypted ? I18n.t('Encrypted_message') : tmsg);
|
|
|
|
const fetch = async() => {
|
|
|
|
const threadName = await fetchThreadName(tmid, id);
|
|
|
|
setMsg(threadName);
|
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2021-05-26 17:24:54 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (!msg) {
|
|
|
|
fetch();
|
|
|
|
}
|
|
|
|
}, []);
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2021-05-26 17:24:54 +00:00
|
|
|
if (!msg) {
|
|
|
|
return null;
|
2020-09-11 14:31:38 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.repliedThread} testID={`message-thread-replied-on-${ msg }`}>
|
2020-06-05 13:28:58 +00:00
|
|
|
<CustomIcon name='threads' size={20} style={styles.repliedThreadIcon} color={themes[theme].tintColor} />
|
2020-12-18 14:14:25 +00:00
|
|
|
<Markdown
|
|
|
|
msg={msg}
|
|
|
|
theme={theme}
|
|
|
|
style={[styles.repliedThreadName, { color: themes[theme].tintColor }]}
|
|
|
|
preview
|
|
|
|
numberOfLines={1}
|
|
|
|
/>
|
2020-10-30 13:59:44 +00:00
|
|
|
<View style={styles.repliedThreadDisclosure}>
|
|
|
|
<CustomIcon
|
|
|
|
name='chevron-right'
|
|
|
|
color={themes[theme].auxiliaryText}
|
|
|
|
size={20}
|
|
|
|
/>
|
|
|
|
</View>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
RepliedThread.propTypes = {
|
|
|
|
tmid: PropTypes.string,
|
|
|
|
tmsg: PropTypes.string,
|
2019-09-16 20:26:32 +00:00
|
|
|
id: PropTypes.string,
|
2019-05-20 20:43:50 +00:00
|
|
|
isHeader: PropTypes.bool,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2020-09-11 14:31:38 +00:00
|
|
|
fetchThreadName: PropTypes.func,
|
|
|
|
isEncrypted: PropTypes.bool
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
RepliedThread.displayName = 'MessageRepliedThread';
|
|
|
|
|
|
|
|
export default RepliedThread;
|