Rocket.Chat.ReactNative/app/containers/message/User.tsx

139 lines
3.2 KiB
TypeScript
Raw Normal View History

import moment from 'moment';
import React, { useContext } from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { MessageType, MessageTypesValues, SubscriptionType } from '../../definitions';
import { useTheme } from '../../theme';
import { IRoomInfoParam } from '../../views/SearchMessagesView';
import sharedStyles from '../../views/Styles';
import RightIcons from './Components/RightIcons';
import MessageContext from './Context';
import messageStyles from './styles';
import { messageHaveAuthorName } from './utils';
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center'
},
actionIcons: {
flexDirection: 'row',
alignItems: 'center'
},
username: {
flexShrink: 1,
fontSize: 16,
lineHeight: 22,
2022-08-23 19:32:51 +00:00
...sharedStyles.textSemibold
},
usernameInfoMessage: {
fontSize: 16,
...sharedStyles.textMedium
},
titleContainer: {
flexShrink: 1,
flexDirection: 'row',
alignItems: 'center'
},
alias: {
fontSize: 14,
...sharedStyles.textRegular
}
});
interface IMessageUser {
isHeader?: boolean;
hasError: boolean;
useRealName?: boolean;
author?: {
_id: string;
name?: string;
username?: string;
};
alias?: string;
ts?: Date;
timeFormat?: string;
navToRoomInfo?: (navParam: IRoomInfoParam) => void;
type: MessageType;
isEdited: boolean;
isReadReceiptEnabled?: boolean;
unread?: boolean;
isTranslated: boolean;
}
const User = React.memo(
({
isHeader,
useRealName,
author,
alias,
ts,
timeFormat,
hasError,
navToRoomInfo,
type,
isEdited,
isTranslated,
...props
}: IMessageUser) => {
const { user } = useContext(MessageContext);
const { colors } = useTheme();
if (isHeader) {
const username = (useRealName && author?.name) || author?.username;
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
const aliasUsername = alias ? <Text style={[styles.alias, { color: colors.fontSecondaryInfo }]}> @{username}</Text> : null;
const time = moment(ts).format(timeFormat);
const itsMe = author?._id === user.id;
const onUserPress = () => {
navToRoomInfo?.({
t: SubscriptionType.DIRECT,
rid: author?._id || '',
itsMe
});
};
const textContent = (
<>
{alias || username}
{aliasUsername}
</>
);
if (messageHaveAuthorName(type as MessageTypesValues)) {
return (
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
<Text style={[styles.usernameInfoMessage, { color: colors.fontTitlesLabels }]} onPress={onUserPress}>
{textContent}
</Text>
);
}
return (
<View style={styles.container}>
<TouchableOpacity testID={`username-header-${username}`} style={styles.titleContainer} onPress={onUserPress}>
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
<Text style={[styles.username, { color: colors.fontTitlesLabels }]} numberOfLines={1}>
{textContent}
</Text>
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
<Text style={[messageStyles.time, { color: colors.fontSecondaryInfo }]}>{time}</Text>
</TouchableOpacity>
<RightIcons
type={type}
isEdited={isEdited}
hasError={hasError}
isReadReceiptEnabled={props.isReadReceiptEnabled}
unread={props.unread}
isTranslated={isTranslated}
/>
</View>
);
}
return null;
}
);
User.displayName = 'MessageUser';
export default User;