2020-07-31 17:06:22 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { View } from 'react-native';
|
|
|
|
|
|
|
|
import styles from './styles';
|
|
|
|
import Wrapper from './Wrapper';
|
2020-07-31 18:22:30 +00:00
|
|
|
import UnreadBadge from '../UnreadBadge';
|
2020-07-31 17:06:22 +00:00
|
|
|
import TypeIcon from './TypeIcon';
|
|
|
|
import LastMessage from './LastMessage';
|
|
|
|
import Title from './Title';
|
|
|
|
import UpdatedAt from './UpdatedAt';
|
|
|
|
import Touchable from './Touchable';
|
|
|
|
|
|
|
|
const RoomItem = ({
|
|
|
|
rid,
|
|
|
|
type,
|
|
|
|
prid,
|
|
|
|
name,
|
|
|
|
avatar,
|
|
|
|
width,
|
|
|
|
avatarSize,
|
|
|
|
baseUrl,
|
|
|
|
userId,
|
|
|
|
username,
|
|
|
|
token,
|
|
|
|
showLastMessage,
|
|
|
|
status,
|
|
|
|
useRealName,
|
|
|
|
theme,
|
|
|
|
isFocused,
|
|
|
|
isGroupChat,
|
|
|
|
isRead,
|
|
|
|
date,
|
|
|
|
accessibilityLabel,
|
|
|
|
favorite,
|
|
|
|
lastMessage,
|
|
|
|
alert,
|
|
|
|
hideUnreadStatus,
|
|
|
|
unread,
|
|
|
|
userMentions,
|
|
|
|
groupMentions,
|
|
|
|
roomUpdatedAt,
|
|
|
|
testID,
|
2020-07-31 18:22:30 +00:00
|
|
|
swipeEnabled,
|
2020-07-31 17:06:22 +00:00
|
|
|
onPress,
|
|
|
|
toggleFav,
|
|
|
|
toggleRead,
|
|
|
|
hideChannel
|
|
|
|
}) => (
|
|
|
|
<Touchable
|
|
|
|
onPress={onPress}
|
|
|
|
width={width}
|
|
|
|
favorite={favorite}
|
|
|
|
toggleFav={toggleFav}
|
|
|
|
isRead={isRead}
|
|
|
|
rid={rid}
|
|
|
|
toggleRead={toggleRead}
|
|
|
|
hideChannel={hideChannel}
|
|
|
|
testID={testID}
|
|
|
|
type={type}
|
|
|
|
theme={theme}
|
|
|
|
isFocused={isFocused}
|
2020-07-31 18:22:30 +00:00
|
|
|
swipeEnabled={swipeEnabled}
|
2020-07-31 17:06:22 +00:00
|
|
|
>
|
|
|
|
<Wrapper
|
|
|
|
accessibilityLabel={accessibilityLabel}
|
|
|
|
avatar={avatar}
|
|
|
|
avatarSize={avatarSize}
|
|
|
|
type={type}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
userId={userId}
|
|
|
|
token={token}
|
|
|
|
theme={theme}
|
|
|
|
>
|
|
|
|
{showLastMessage
|
|
|
|
? (
|
|
|
|
<>
|
|
|
|
<View style={styles.titleContainer}>
|
|
|
|
<TypeIcon
|
|
|
|
type={type}
|
|
|
|
prid={prid}
|
|
|
|
status={status}
|
|
|
|
isGroupChat={isGroupChat}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
<Title
|
|
|
|
name={name}
|
|
|
|
theme={theme}
|
|
|
|
hideUnreadStatus={hideUnreadStatus}
|
|
|
|
alert={alert}
|
|
|
|
/>
|
|
|
|
<UpdatedAt
|
|
|
|
roomUpdatedAt={roomUpdatedAt}
|
|
|
|
date={date}
|
|
|
|
theme={theme}
|
|
|
|
hideUnreadStatus={hideUnreadStatus}
|
|
|
|
alert={alert}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<View style={styles.row}>
|
|
|
|
<LastMessage
|
|
|
|
lastMessage={lastMessage}
|
|
|
|
type={type}
|
|
|
|
showLastMessage={showLastMessage}
|
|
|
|
username={username}
|
|
|
|
alert={alert && !hideUnreadStatus}
|
|
|
|
useRealName={useRealName}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
<UnreadBadge
|
|
|
|
unread={unread}
|
|
|
|
userMentions={userMentions}
|
|
|
|
groupMentions={groupMentions}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
: (
|
|
|
|
<View style={[styles.titleContainer, styles.flex]}>
|
|
|
|
<TypeIcon
|
|
|
|
type={type}
|
|
|
|
prid={prid}
|
|
|
|
status={status}
|
|
|
|
isGroupChat={isGroupChat}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
<Title
|
|
|
|
name={name}
|
|
|
|
theme={theme}
|
|
|
|
hideUnreadStatus={hideUnreadStatus}
|
|
|
|
alert={alert}
|
|
|
|
/>
|
|
|
|
<UnreadBadge
|
|
|
|
unread={unread}
|
|
|
|
userMentions={userMentions}
|
|
|
|
groupMentions={groupMentions}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</Wrapper>
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
|
|
|
|
RoomItem.propTypes = {
|
|
|
|
rid: PropTypes.string.isRequired,
|
|
|
|
type: PropTypes.string.isRequired,
|
|
|
|
prid: PropTypes.string,
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
avatar: PropTypes.string.isRequired,
|
|
|
|
baseUrl: PropTypes.string.isRequired,
|
|
|
|
showLastMessage: PropTypes.bool,
|
|
|
|
userId: PropTypes.string,
|
|
|
|
username: PropTypes.string,
|
|
|
|
token: PropTypes.string,
|
|
|
|
avatarSize: PropTypes.number,
|
|
|
|
testID: PropTypes.string,
|
|
|
|
width: PropTypes.number,
|
|
|
|
status: PropTypes.string,
|
|
|
|
useRealName: PropTypes.bool,
|
|
|
|
theme: PropTypes.string,
|
|
|
|
isFocused: PropTypes.bool,
|
|
|
|
isGroupChat: PropTypes.bool,
|
|
|
|
isRead: PropTypes.bool,
|
|
|
|
date: PropTypes.string,
|
|
|
|
accessibilityLabel: PropTypes.string,
|
|
|
|
lastMessage: PropTypes.object,
|
|
|
|
favorite: PropTypes.bool,
|
|
|
|
alert: PropTypes.bool,
|
|
|
|
hideUnreadStatus: PropTypes.bool,
|
|
|
|
unread: PropTypes.number,
|
|
|
|
userMentions: PropTypes.number,
|
|
|
|
groupMentions: PropTypes.number,
|
|
|
|
roomUpdatedAt: PropTypes.instanceOf(Date),
|
2020-07-31 18:22:30 +00:00
|
|
|
swipeEnabled: PropTypes.bool,
|
2020-07-31 17:06:22 +00:00
|
|
|
toggleFav: PropTypes.func,
|
|
|
|
toggleRead: PropTypes.func,
|
|
|
|
onPress: PropTypes.func,
|
|
|
|
hideChannel: PropTypes.func
|
|
|
|
};
|
|
|
|
|
|
|
|
RoomItem.defaultProps = {
|
|
|
|
avatarSize: 48,
|
2020-07-31 18:22:30 +00:00
|
|
|
status: 'offline',
|
|
|
|
swipeEnabled: true
|
2020-07-31 17:06:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default RoomItem;
|