2019-08-27 12:25:38 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Text } from 'react-native';
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
|
2019-08-27 12:25:38 +00:00
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
const AtMention = React.memo(({
|
2019-12-04 16:39:53 +00:00
|
|
|
mention, mentions, username, navToRoomInfo, preview, style = [], theme
|
2019-08-27 12:25:38 +00:00
|
|
|
}) => {
|
2019-12-04 16:39:53 +00:00
|
|
|
let mentionStyle = { ...styles.mention, color: themes[theme].buttonText };
|
2019-08-27 12:25:38 +00:00
|
|
|
if (mention === 'all' || mention === 'here') {
|
|
|
|
mentionStyle = {
|
|
|
|
...mentionStyle,
|
|
|
|
...styles.mentionAll
|
|
|
|
};
|
|
|
|
} else if (mention === username) {
|
|
|
|
mentionStyle = {
|
|
|
|
...mentionStyle,
|
2019-12-04 16:39:53 +00:00
|
|
|
backgroundColor: themes[theme].actionTintColor
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
mentionStyle = {
|
|
|
|
...mentionStyle,
|
|
|
|
color: themes[theme].actionTintColor
|
2019-08-27 12:25:38 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const handlePress = () => {
|
2020-02-14 00:22:53 +00:00
|
|
|
const index = mentions.findIndex(m => m.username === mention);
|
|
|
|
const navParam = {
|
|
|
|
t: 'd',
|
|
|
|
rid: mentions[index]._id
|
|
|
|
};
|
|
|
|
navToRoomInfo(navParam);
|
2019-08-27 12:25:38 +00:00
|
|
|
};
|
|
|
|
|
2020-02-14 00:22:53 +00:00
|
|
|
if (mentions && mentions.length && mentions.findIndex(m => m.username === mention) !== -1) {
|
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
style={[preview ? { ...styles.text, color: themes[theme].bodyText } : mentionStyle, ...style]}
|
|
|
|
onPress={preview ? undefined : handlePress}
|
|
|
|
>
|
|
|
|
{mention}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:25:38 +00:00
|
|
|
return (
|
2020-02-14 00:22:53 +00:00
|
|
|
<Text style={[styles.text, { color: themes[theme].bodyText }, ...style]}>
|
2019-08-27 12:25:38 +00:00
|
|
|
{`@${ mention }`}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
AtMention.propTypes = {
|
|
|
|
mention: PropTypes.string,
|
|
|
|
username: PropTypes.string,
|
|
|
|
navToRoomInfo: PropTypes.func,
|
2019-10-02 12:41:51 +00:00
|
|
|
style: PropTypes.array,
|
2019-10-04 13:28:36 +00:00
|
|
|
preview: PropTypes.bool,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2019-08-27 12:25:38 +00:00
|
|
|
mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AtMention;
|