2019-10-30 14:14:41 +00:00
|
|
|
import React, { useContext } from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { Text, TouchableOpacity } from 'react-native';
|
2019-10-30 14:14:41 +00:00
|
|
|
|
|
|
|
import styles from '../styles';
|
|
|
|
import Avatar from '../../Avatar';
|
|
|
|
import MessageboxContext from '../Context';
|
|
|
|
import FixedMentionItem from './FixedMentionItem';
|
|
|
|
import MentionEmoji from './MentionEmoji';
|
2021-09-22 17:29:26 +00:00
|
|
|
import { MENTIONS_TRACKING_TYPE_EMOJIS, MENTIONS_TRACKING_TYPE_COMMANDS, MENTIONS_TRACKING_TYPE_CANNED } from '../constants';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../../constants/colors';
|
2022-02-17 15:27:01 +00:00
|
|
|
import { IEmoji } from '../../../definitions/IEmoji';
|
2019-10-30 14:14:41 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IMessageBoxMentionItem {
|
|
|
|
item: {
|
|
|
|
name: string;
|
|
|
|
command: string;
|
|
|
|
username: string;
|
|
|
|
t: string;
|
|
|
|
id: string;
|
2021-09-22 17:29:26 +00:00
|
|
|
shortcut: string;
|
|
|
|
text: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
} & IEmoji;
|
|
|
|
trackingType: string;
|
|
|
|
theme: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MentionItem = ({ item, trackingType, theme }: IMessageBoxMentionItem) => {
|
2019-10-30 14:14:41 +00:00
|
|
|
const context = useContext(MessageboxContext);
|
2020-10-30 13:12:02 +00:00
|
|
|
const { onPressMention } = context;
|
2019-10-30 14:14:41 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const defineTestID = (type: string) => {
|
2019-10-30 14:14:41 +00:00
|
|
|
switch (type) {
|
|
|
|
case MENTIONS_TRACKING_TYPE_EMOJIS:
|
2021-09-13 20:41:05 +00:00
|
|
|
return `mention-item-${item.name || item}`;
|
2019-10-30 14:14:41 +00:00
|
|
|
case MENTIONS_TRACKING_TYPE_COMMANDS:
|
2021-09-13 20:41:05 +00:00
|
|
|
return `mention-item-${item.command || item}`;
|
2021-09-22 17:29:26 +00:00
|
|
|
case MENTIONS_TRACKING_TYPE_CANNED:
|
|
|
|
return `mention-item-${item.shortcut || item}`;
|
2019-10-30 14:14:41 +00:00
|
|
|
default:
|
2021-09-13 20:41:05 +00:00
|
|
|
return `mention-item-${item.username || item.name || item}`;
|
2019-10-30 14:14:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const testID = defineTestID(trackingType);
|
|
|
|
|
|
|
|
if (item.username === 'all' || item.username === 'here') {
|
2019-12-04 16:39:53 +00:00
|
|
|
return <FixedMentionItem item={item} onPress={onPressMention} theme={theme} />;
|
2019-10-30 14:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let content = (
|
|
|
|
<>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Avatar style={styles.avatar} text={item.username || item.name} size={30} type={item.t} />
|
|
|
|
<Text style={[styles.mentionText, { color: themes[theme].titleText }]}>{item.username || item.name || item}</Text>
|
2019-10-30 14:14:41 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (trackingType === MENTIONS_TRACKING_TYPE_EMOJIS) {
|
|
|
|
content = (
|
|
|
|
<>
|
|
|
|
<MentionEmoji item={item} />
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text style={[styles.mentionText, { color: themes[theme].titleText }]}>:{item.name || item}:</Text>
|
2019-10-30 14:14:41 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trackingType === MENTIONS_TRACKING_TYPE_COMMANDS) {
|
|
|
|
content = (
|
|
|
|
<>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.slash, { backgroundColor: themes[theme].borderColor, color: themes[theme].tintColor }]}>/</Text>
|
2020-04-30 16:05:31 +00:00
|
|
|
<Text style={[styles.mentionText, { color: themes[theme].titleText }]}>{item.id}</Text>
|
2019-10-30 14:14:41 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-22 17:29:26 +00:00
|
|
|
if (trackingType === MENTIONS_TRACKING_TYPE_CANNED) {
|
|
|
|
content = (
|
|
|
|
<>
|
|
|
|
<Text style={[styles.cannedItem, { color: themes[theme].titleText }]}>!{item.shortcut}</Text>
|
|
|
|
<Text numberOfLines={1} style={[styles.cannedMentionText, { color: themes[theme].auxiliaryTintColor }]}>
|
|
|
|
{item.text}
|
|
|
|
</Text>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-30 14:14:41 +00:00
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[
|
|
|
|
styles.mentionItem,
|
|
|
|
{
|
|
|
|
backgroundColor: themes[theme].auxiliaryBackground,
|
|
|
|
borderTopColor: themes[theme].separatorColor
|
|
|
|
}
|
|
|
|
]}
|
2019-10-30 14:14:41 +00:00
|
|
|
onPress={() => onPressMention(item)}
|
2021-09-13 20:41:05 +00:00
|
|
|
testID={testID}>
|
2019-10-30 14:14:41 +00:00
|
|
|
{content}
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MentionItem;
|