2019-09-03 19:27:57 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Text } from 'react-native';
|
|
|
|
|
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
const AtMention = React.memo(({
|
2019-10-07 20:56:30 +00:00
|
|
|
mention, mentions, username, navToRoomInfo, preview, style = []
|
2019-09-03 19:27:57 +00:00
|
|
|
}) => {
|
|
|
|
let mentionStyle = styles.mention;
|
|
|
|
if (mention === 'all' || mention === 'here') {
|
|
|
|
mentionStyle = {
|
|
|
|
...mentionStyle,
|
|
|
|
...styles.mentionAll
|
|
|
|
};
|
|
|
|
} else if (mention === username) {
|
|
|
|
mentionStyle = {
|
|
|
|
...mentionStyle,
|
|
|
|
...styles.mentionLoggedUser
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const handlePress = () => {
|
|
|
|
if (mentions && mentions.length && mentions.findIndex(m => m.username === mention) !== -1) {
|
|
|
|
const index = mentions.findIndex(m => m.username === mention);
|
|
|
|
const navParam = {
|
|
|
|
t: 'd',
|
|
|
|
rid: mentions[index]._id
|
|
|
|
};
|
|
|
|
navToRoomInfo(navParam);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Text
|
2019-10-07 20:56:30 +00:00
|
|
|
style={[preview ? styles.text : mentionStyle, ...style]}
|
|
|
|
onPress={preview ? undefined : handlePress}
|
2019-09-03 19:27:57 +00:00
|
|
|
>
|
|
|
|
{`@${ mention }`}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
AtMention.propTypes = {
|
|
|
|
mention: PropTypes.string,
|
|
|
|
username: PropTypes.string,
|
|
|
|
navToRoomInfo: PropTypes.func,
|
2019-10-07 20:56:30 +00:00
|
|
|
style: PropTypes.array,
|
|
|
|
preview: PropTypes.bool,
|
2019-09-03 19:27:57 +00:00
|
|
|
mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AtMention;
|