2019-10-30 14:14:41 +00:00
|
|
|
import React, { useContext } from 'react';
|
2022-11-10 16:22:02 +00:00
|
|
|
import { Text, TouchableOpacity, View } from 'react-native';
|
2019-10-30 14:14:41 +00:00
|
|
|
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../../lib/constants';
|
2022-03-31 22:39:24 +00:00
|
|
|
import { IEmoji } from '../../../definitions/IEmoji';
|
|
|
|
import { useTheme } from '../../../theme';
|
2019-10-30 14:14:41 +00:00
|
|
|
import Avatar from '../../Avatar';
|
2022-03-31 22:39:24 +00:00
|
|
|
import { MENTIONS_TRACKING_TYPE_CANNED, MENTIONS_TRACKING_TYPE_COMMANDS, MENTIONS_TRACKING_TYPE_EMOJIS } from '../constants';
|
2019-10-30 14:14:41 +00:00
|
|
|
import MessageboxContext from '../Context';
|
2022-03-31 22:39:24 +00:00
|
|
|
import styles from '../styles';
|
2019-10-30 14:14:41 +00:00
|
|
|
import FixedMentionItem from './FixedMentionItem';
|
|
|
|
import MentionEmoji from './MentionEmoji';
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-03-31 22:39:24 +00:00
|
|
|
const MentionItemContent = React.memo(({ trackingType, item }: IMessageBoxMentionItem) => {
|
|
|
|
const { theme } = useTheme();
|
|
|
|
switch (trackingType) {
|
|
|
|
case MENTIONS_TRACKING_TYPE_EMOJIS:
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<MentionEmoji item={item} />
|
2023-08-18 17:48:33 +00:00
|
|
|
<Text style={[styles.mentionText, { color: themes[theme].titleText }]}>:{item.name || item}:</Text>
|
2022-03-31 22:39:24 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
case MENTIONS_TRACKING_TYPE_COMMANDS:
|
|
|
|
return (
|
|
|
|
<>
|
2022-11-10 16:22:02 +00:00
|
|
|
<View style={[styles.slash, { backgroundColor: themes[theme].borderColor }]}>
|
|
|
|
<Text style={{ color: themes[theme].tintColor }}>/</Text>
|
|
|
|
</View>
|
2022-03-31 22:39:24 +00:00
|
|
|
<Text style={[styles.mentionText, { color: themes[theme].titleText }]}>{item.id}</Text>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
case MENTIONS_TRACKING_TYPE_CANNED:
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Text style={[styles.cannedItem, { color: themes[theme].titleText }]}>!{item.shortcut}</Text>
|
|
|
|
<Text numberOfLines={1} style={[styles.cannedMentionText, { color: themes[theme].auxiliaryTintColor }]}>
|
|
|
|
{item.text}
|
|
|
|
</Text>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Avatar style={styles.avatar} text={item.username || item.name} size={30} type={item.t} />
|
2023-08-18 17:48:33 +00:00
|
|
|
<Text style={[styles.mentionText, { color: themes[theme].titleText }]}>{item.username || item.name || item}</Text>
|
2022-03-31 22:39:24 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const MentionItem = ({ item, trackingType }: IMessageBoxMentionItem) => {
|
2019-10-30 14:14:41 +00:00
|
|
|
const context = useContext(MessageboxContext);
|
2022-03-31 22:39:24 +00:00
|
|
|
const { theme } = useTheme();
|
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') {
|
2022-03-31 22:39:24 +00:00
|
|
|
return <FixedMentionItem item={item} onPress={onPressMention} />;
|
2021-09-22 17:29:26 +00:00
|
|
|
}
|
|
|
|
|
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)}
|
2022-08-08 21:02:08 +00:00
|
|
|
testID={testID}
|
|
|
|
>
|
2022-03-31 22:39:24 +00:00
|
|
|
<MentionItemContent item={item} trackingType={trackingType} />
|
2019-10-30 14:14:41 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MentionItem;
|