2020-04-30 20:05:59 +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';
|
|
|
|
|
2020-04-30 20:05:59 +00:00
|
|
|
import Touchable from './Touchable';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
|
|
|
import styles from './styles';
|
|
|
|
import { BUTTON_HIT_SLOP } from './utils';
|
|
|
|
import I18n from '../../i18n';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2020-04-30 20:05:59 +00:00
|
|
|
import MessageContext from './Context';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
const Broadcast = React.memo(({
|
2020-04-30 20:05:59 +00:00
|
|
|
author, broadcast, theme
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
2020-04-30 20:05:59 +00:00
|
|
|
const { user, replyBroadcast } = useContext(MessageContext);
|
2019-05-20 20:43:50 +00:00
|
|
|
const isOwn = author._id === user.id;
|
|
|
|
if (broadcast && !isOwn) {
|
|
|
|
return (
|
|
|
|
<View style={styles.buttonContainer}>
|
|
|
|
<Touchable
|
|
|
|
onPress={replyBroadcast}
|
2019-12-04 16:39:53 +00:00
|
|
|
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
|
|
|
style={[styles.button, { backgroundColor: themes[theme].tintColor }]}
|
2019-05-20 20:43:50 +00:00
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
2020-03-03 20:27:38 +00:00
|
|
|
testID='message-broadcast-reply'
|
2019-05-20 20:43:50 +00:00
|
|
|
>
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-12-04 16:39:53 +00:00
|
|
|
<CustomIcon name='back' size={20} style={styles.buttonIcon} color={themes[theme].buttonText} />
|
|
|
|
<Text style={[styles.buttonText, { color: themes[theme].buttonText }]}>{I18n.t('Reply')}</Text>
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-05-20 20:43:50 +00:00
|
|
|
</Touchable>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
2019-12-04 16:39:53 +00:00
|
|
|
});
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
Broadcast.propTypes = {
|
|
|
|
author: PropTypes.object,
|
|
|
|
broadcast: PropTypes.bool,
|
2020-04-30 20:05:59 +00:00
|
|
|
theme: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
Broadcast.displayName = 'MessageBroadcast';
|
|
|
|
|
|
|
|
export default Broadcast;
|