2022-11-25 20:34:49 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2019-04-18 20:57:35 +00:00
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
2022-06-27 18:23:43 +00:00
|
|
|
import { useAppSelector } from '../../lib/hooks';
|
|
|
|
import { getUserPresence } from '../../lib/methods';
|
|
|
|
import { isGroupChat } from '../../lib/methods/helpers';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { formatDate } from '../../lib/methods/helpers/room';
|
2022-04-20 21:37:54 +00:00
|
|
|
import { IRoomItemContainerProps } from './interfaces';
|
2022-06-27 18:23:43 +00:00
|
|
|
import RoomItem from './RoomItem';
|
|
|
|
import { ROW_HEIGHT, ROW_HEIGHT_CONDENSED } from './styles';
|
2019-04-18 20:57:35 +00:00
|
|
|
|
2021-10-06 20:30:10 +00:00
|
|
|
export { ROW_HEIGHT, ROW_HEIGHT_CONDENSED };
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-11-28 20:15:13 +00:00
|
|
|
const RoomItemContainer = ({
|
|
|
|
item,
|
|
|
|
id,
|
|
|
|
onPress,
|
|
|
|
onLongPress,
|
|
|
|
width,
|
|
|
|
toggleFav,
|
|
|
|
toggleRead,
|
|
|
|
hideChannel,
|
|
|
|
isFocused,
|
|
|
|
showLastMessage,
|
|
|
|
username,
|
|
|
|
useRealName,
|
|
|
|
autoJoin,
|
|
|
|
showAvatar,
|
|
|
|
displayMode,
|
|
|
|
getRoomTitle = () => 'title',
|
|
|
|
getRoomAvatar = () => '',
|
|
|
|
getIsRead = () => false,
|
|
|
|
swipeEnabled = true
|
|
|
|
}: IRoomItemContainerProps): React.ReactElement => {
|
|
|
|
const name = getRoomTitle(item);
|
|
|
|
const testID = `rooms-list-view-item-${name}`;
|
|
|
|
const avatar = getRoomAvatar(item);
|
|
|
|
const isRead = getIsRead(item);
|
|
|
|
const date = item.roomUpdatedAt && formatDate(item.roomUpdatedAt);
|
|
|
|
const alert = item.alert || item.tunread?.length;
|
|
|
|
const connected = useAppSelector(state => state.meteor.connected);
|
|
|
|
const userStatus = useAppSelector(state => state.activeUsers[id || '']?.status);
|
2022-06-27 18:23:43 +00:00
|
|
|
|
2022-11-28 20:15:13 +00:00
|
|
|
useEffect(() => {
|
|
|
|
const isDirect = !!(item.t === 'd' && id && !isGroupChat(item));
|
|
|
|
if (connected && isDirect) {
|
|
|
|
getUserPresence(id);
|
2020-10-30 13:12:02 +00:00
|
|
|
}
|
2022-11-28 20:15:13 +00:00
|
|
|
}, [connected]);
|
|
|
|
|
|
|
|
const handleOnPress = () => onPress(item);
|
2020-10-30 13:12:02 +00:00
|
|
|
|
2022-11-28 20:15:13 +00:00
|
|
|
const handleOnLongPress = () => onLongPress && onLongPress(item);
|
2022-07-14 17:18:45 +00:00
|
|
|
|
2022-11-28 20:15:13 +00:00
|
|
|
let accessibilityLabel = '';
|
|
|
|
if (item.unread === 1) {
|
|
|
|
accessibilityLabel = `, ${item.unread} ${I18n.t('alert')}`;
|
|
|
|
} else if (item.unread > 1) {
|
|
|
|
accessibilityLabel = `, ${item.unread} ${I18n.t('alerts')}`;
|
2022-09-19 20:08:25 +00:00
|
|
|
}
|
2022-11-28 20:15:13 +00:00
|
|
|
if (item.userMentions > 0) {
|
|
|
|
accessibilityLabel = `, ${I18n.t('you_were_mentioned')}`;
|
|
|
|
}
|
|
|
|
if (date) {
|
|
|
|
accessibilityLabel = `, ${I18n.t('last_message')} ${date}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const status = item.t === 'l' ? item.visitor?.status || item.v?.status : userStatus;
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2022-11-28 20:15:13 +00:00
|
|
|
return (
|
|
|
|
<RoomItem
|
|
|
|
name={name}
|
|
|
|
avatar={avatar}
|
|
|
|
isGroupChat={isGroupChat(item)}
|
|
|
|
isRead={isRead}
|
|
|
|
onPress={handleOnPress}
|
|
|
|
onLongPress={handleOnLongPress}
|
|
|
|
date={date}
|
|
|
|
accessibilityLabel={accessibilityLabel}
|
|
|
|
width={width}
|
|
|
|
favorite={item.f}
|
|
|
|
rid={item.rid}
|
|
|
|
toggleFav={toggleFav}
|
|
|
|
toggleRead={toggleRead}
|
|
|
|
hideChannel={hideChannel}
|
|
|
|
testID={testID}
|
|
|
|
type={item.t}
|
|
|
|
isFocused={isFocused}
|
|
|
|
prid={item.prid}
|
|
|
|
status={status}
|
|
|
|
hideUnreadStatus={item.hideUnreadStatus}
|
|
|
|
hideMentionStatus={item.hideMentionStatus}
|
|
|
|
alert={alert}
|
|
|
|
lastMessage={item.lastMessage}
|
|
|
|
showLastMessage={showLastMessage}
|
|
|
|
username={username}
|
|
|
|
useRealName={useRealName}
|
|
|
|
unread={item.unread}
|
|
|
|
userMentions={item.userMentions}
|
|
|
|
groupMentions={item.groupMentions}
|
|
|
|
tunread={item.tunread}
|
|
|
|
tunreadUser={item.tunreadUser}
|
|
|
|
tunreadGroup={item.tunreadGroup}
|
|
|
|
swipeEnabled={swipeEnabled}
|
|
|
|
teamMain={item.teamMain}
|
|
|
|
autoJoin={autoJoin}
|
|
|
|
showAvatar={showAvatar}
|
|
|
|
displayMode={displayMode}
|
|
|
|
sourceType={item.source}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2022-06-27 18:23:43 +00:00
|
|
|
export default RoomItemContainer;
|