2019-08-27 12:25:38 +00:00
|
|
|
import React from 'react';
|
2022-03-25 17:20:09 +00:00
|
|
|
import { StyleProp, Text, TextStyle } from 'react-native';
|
2019-08-27 12:25:38 +00:00
|
|
|
|
2021-10-20 16:32:58 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2022-07-04 18:10:14 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2019-08-27 12:25:38 +00:00
|
|
|
import styles from './styles';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { events, logEvent } from '../../lib/methods/helpers/log';
|
2022-03-25 17:20:09 +00:00
|
|
|
import { IUserMention } from './interfaces';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
interface IAtMention {
|
|
|
|
mention: string;
|
2022-02-17 15:27:01 +00:00
|
|
|
username?: string;
|
|
|
|
navToRoomInfo?: Function;
|
2022-03-25 17:20:09 +00:00
|
|
|
style?: StyleProp<TextStyle>[];
|
2022-02-17 15:27:01 +00:00
|
|
|
useRealName?: boolean;
|
2022-03-25 17:20:09 +00:00
|
|
|
mentions?: IUserMention[];
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
2019-08-27 12:25:38 +00:00
|
|
|
|
2022-07-04 18:10:14 +00:00
|
|
|
const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, style = [], useRealName }: IAtMention) => {
|
|
|
|
const { theme } = useTheme();
|
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,
|
|
|
|
{
|
2022-07-04 18:10:14 +00:00
|
|
|
color: themes[theme].mentionGroupColor
|
2020-07-29 20:49:08 +00:00
|
|
|
},
|
|
|
|
...style
|
2022-08-08 21:02:08 +00:00
|
|
|
]}
|
|
|
|
>
|
2021-09-13 20:41:05 +00:00
|
|
|
{mention}
|
2020-07-29 20:49:08 +00:00
|
|
|
</Text>
|
|
|
|
);
|
2020-05-20 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2023-12-22 15:36:23 +00:00
|
|
|
const itsMe = mention === username;
|
2020-07-29 20:49:08 +00:00
|
|
|
let mentionStyle = {};
|
2023-12-22 15:36:23 +00:00
|
|
|
if (itsMe) {
|
2019-08-27 12:25:38 +00:00
|
|
|
mentionStyle = {
|
2022-07-04 18:10:14 +00:00
|
|
|
color: themes[theme].mentionMeColor
|
2019-12-04 16:39:53 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
mentionStyle = {
|
2022-07-04 18:10:14 +00:00
|
|
|
color: themes[theme].mentionOtherColor
|
2019-08-27 12:25:38 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const user = mentions?.find?.((m: any) => m && m.username === mention);
|
2020-02-21 16:13:05 +00:00
|
|
|
|
2019-08-27 12:25:38 +00:00
|
|
|
const handlePress = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.ROOM_MENTION_GO_USER_INFO);
|
2020-02-14 00:22:53 +00:00
|
|
|
const navParam = {
|
|
|
|
t: 'd',
|
2023-12-22 15:36:23 +00:00
|
|
|
rid: user && user._id,
|
|
|
|
itsMe
|
2020-02-14 00:22:53 +00:00
|
|
|
};
|
2022-02-17 15:27:01 +00:00
|
|
|
if (navToRoomInfo) {
|
|
|
|
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 (
|
2022-07-04 18:10:14 +00:00
|
|
|
<Text style={[styles.mention, mentionStyle, ...style]} onPress={handlePress}>
|
2020-03-04 13:52:13 +00:00
|
|
|
{useRealName && user.name ? user.name : user.username}
|
2020-02-14 00:22:53 +00:00
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-04 18:10:14 +00:00
|
|
|
return <Text style={[styles.text, { color: themes[theme].bodyText }, ...style]}>{`@${mention}`}</Text>;
|
2019-08-27 12:25:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default AtMention;
|