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(({
|
2020-02-28 16:18:03 +00:00
|
|
|
mention, mentions, username, navToRoomInfo, style = [], useRealName, theme
|
2019-08-27 12:25:38 +00:00
|
|
|
}) => {
|
|
|
|
if (mention === 'all' || mention === 'here') {
|
2020-07-29 20:49:08 +00:00
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
styles.mention,
|
|
|
|
{
|
|
|
|
color: themes[theme].mentionGroupColor,
|
|
|
|
backgroundColor: themes[theme].mentionGroupBackground
|
|
|
|
},
|
|
|
|
...style
|
|
|
|
]}
|
|
|
|
>{mention}
|
|
|
|
</Text>
|
|
|
|
);
|
2020-05-20 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2020-07-29 20:49:08 +00:00
|
|
|
let mentionStyle = {};
|
2020-05-20 12:53:40 +00:00
|
|
|
if (mention === username) {
|
2019-08-27 12:25:38 +00:00
|
|
|
mentionStyle = {
|
2020-07-29 20:49:08 +00:00
|
|
|
color: themes[theme].mentionMeColor,
|
|
|
|
backgroundColor: themes[theme].mentionMeBackground
|
2019-12-04 16:39:53 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
mentionStyle = {
|
2020-07-29 20:49:08 +00:00
|
|
|
color: themes[theme].mentionOtherColor,
|
|
|
|
backgroundColor: themes[theme].mentionOtherBackground
|
2019-08-27 12:25:38 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-21 16:13:05 +00:00
|
|
|
const user = mentions && mentions.length && mentions.find(m => m.username === mention);
|
|
|
|
|
2019-08-27 12:25:38 +00:00
|
|
|
const handlePress = () => {
|
2020-02-14 00:22:53 +00:00
|
|
|
const navParam = {
|
|
|
|
t: 'd',
|
2020-02-21 16:13:05 +00:00
|
|
|
rid: user && user._id
|
2020-02-14 00:22:53 +00:00
|
|
|
};
|
|
|
|
navToRoomInfo(navParam);
|
2019-08-27 12:25:38 +00:00
|
|
|
};
|
|
|
|
|
2020-02-21 16:13:05 +00:00
|
|
|
if (user) {
|
2020-02-14 00:22:53 +00:00
|
|
|
return (
|
|
|
|
<Text
|
2020-07-29 20:49:08 +00:00
|
|
|
style={[styles.mention, mentionStyle, ...style]}
|
2020-02-28 16:18:03 +00:00
|
|
|
onPress={handlePress}
|
2020-02-14 00:22:53 +00:00
|
|
|
>
|
2020-03-04 13:52:13 +00:00
|
|
|
{useRealName && user.name ? user.name : user.username}
|
2020-02-14 00:22:53 +00:00
|
|
|
</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,
|
2020-02-21 16:13:05 +00:00
|
|
|
useRealName: 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;
|