2020-06-26 20:22:56 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { StyleSheet, Text, View } from 'react-native';
|
2020-06-26 20:22:56 +00:00
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
|
|
|
import RocketChat from '../../lib/rocketchat';
|
|
|
|
import { themes } from '../../constants/colors';
|
2022-01-17 16:10:39 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2020-06-26 20:22:56 +00:00
|
|
|
import { isAndroid, isTablet } from '../../utils/deviceInfo';
|
|
|
|
import sharedStyles from '../Styles';
|
2020-10-30 17:35:07 +00:00
|
|
|
import { makeThreadName } from '../../utils/room';
|
2022-02-10 12:10:42 +00:00
|
|
|
import { ISubscription } from '../../definitions';
|
2020-06-26 20:22:56 +00:00
|
|
|
|
|
|
|
const androidMarginLeft = isTablet ? 0 : 4;
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
marginRight: isAndroid ? 15 : 5,
|
|
|
|
marginLeft: isAndroid ? androidMarginLeft : -10,
|
|
|
|
justifyContent: 'center'
|
|
|
|
},
|
|
|
|
inner: {
|
|
|
|
alignItems: 'center',
|
|
|
|
flexDirection: 'row',
|
|
|
|
flex: 1
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
fontSize: 16,
|
|
|
|
...sharedStyles.textRegular,
|
|
|
|
marginRight: 4
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
...sharedStyles.textSemibold
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-16 16:19:50 +00:00
|
|
|
interface IHeader {
|
2022-02-10 12:10:42 +00:00
|
|
|
room: ISubscription;
|
2021-11-16 16:19:50 +00:00
|
|
|
thread: { id?: string };
|
|
|
|
}
|
|
|
|
|
2022-01-17 16:10:39 +00:00
|
|
|
const Header = React.memo(({ room, thread }: IHeader) => {
|
|
|
|
const { theme } = useTheme();
|
2020-06-26 20:22:56 +00:00
|
|
|
let type;
|
2020-07-03 14:07:29 +00:00
|
|
|
if (thread?.id) {
|
2020-06-26 20:22:56 +00:00
|
|
|
type = 'thread';
|
|
|
|
} else if (room?.prid) {
|
|
|
|
type = 'discussion';
|
|
|
|
} else {
|
|
|
|
type = room?.t;
|
|
|
|
}
|
|
|
|
let icon;
|
|
|
|
if (type === 'discussion') {
|
2020-07-27 19:53:33 +00:00
|
|
|
icon = 'discussions';
|
2020-06-26 20:22:56 +00:00
|
|
|
} else if (type === 'thread') {
|
|
|
|
icon = 'threads';
|
|
|
|
} else if (type === 'c') {
|
2020-07-27 19:53:33 +00:00
|
|
|
icon = 'channel-public';
|
2020-06-26 20:22:56 +00:00
|
|
|
} else if (type === 'l') {
|
2020-07-27 19:53:33 +00:00
|
|
|
icon = 'omnichannel';
|
2020-06-26 20:22:56 +00:00
|
|
|
} else if (type === 'd') {
|
|
|
|
if (RocketChat.isGroupChat(room)) {
|
|
|
|
icon = 'team';
|
|
|
|
} else {
|
2020-07-27 19:53:33 +00:00
|
|
|
icon = 'mention';
|
2020-06-26 20:22:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-07-27 19:53:33 +00:00
|
|
|
icon = 'channel-private';
|
2020-06-26 20:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const textColor = themes[theme].previewTintColor;
|
|
|
|
|
2020-10-30 17:35:07 +00:00
|
|
|
let title;
|
|
|
|
if (thread?.id) {
|
|
|
|
title = makeThreadName(thread);
|
|
|
|
} else {
|
|
|
|
title = RocketChat.getRoomTitle(room);
|
|
|
|
}
|
|
|
|
|
2020-06-26 20:22:56 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.inner}>
|
|
|
|
<Text numberOfLines={1} style={styles.text}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text style={[styles.text, { color: textColor }]} numberOfLines={1}>
|
|
|
|
{I18n.t('Sending_to')}{' '}
|
|
|
|
</Text>
|
|
|
|
<CustomIcon name={icon} size={16} color={textColor} />
|
|
|
|
<Text style={[styles.name, { color: textColor }]} numberOfLines={1}>
|
2020-10-30 17:35:07 +00:00
|
|
|
{title}
|
2020-06-26 20:22:56 +00:00
|
|
|
</Text>
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-01-17 16:10:39 +00:00
|
|
|
export default Header;
|