2022-06-27 18:23:43 +00:00
|
|
|
import React, { useEffect, useReducer, useRef } from 'react';
|
|
|
|
import { Subscription } from 'rxjs';
|
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-06-27 18:23:43 +00:00
|
|
|
const attrs = ['width', 'isFocused', 'showLastMessage', 'autoJoin', 'showAvatar', 'displayMode'];
|
|
|
|
|
|
|
|
const RoomItemContainer = React.memo(
|
|
|
|
({
|
|
|
|
item,
|
|
|
|
id,
|
|
|
|
onPress,
|
|
|
|
onLongPress,
|
|
|
|
width,
|
|
|
|
toggleFav,
|
|
|
|
toggleRead,
|
|
|
|
hideChannel,
|
|
|
|
isFocused,
|
|
|
|
showLastMessage,
|
|
|
|
username,
|
|
|
|
useRealName,
|
|
|
|
autoJoin,
|
|
|
|
showAvatar,
|
|
|
|
displayMode,
|
|
|
|
getRoomTitle = () => 'title',
|
|
|
|
getRoomAvatar = () => '',
|
|
|
|
getIsRead = () => false,
|
2022-12-21 22:22:22 +00:00
|
|
|
swipeEnabled = true
|
2022-06-27 18:23:43 +00:00
|
|
|
}: IRoomItemContainerProps) => {
|
2020-10-30 13:12:02 +00:00
|
|
|
const name = getRoomTitle(item);
|
2021-09-13 20:41:05 +00:00
|
|
|
const testID = `rooms-list-view-item-${name}`;
|
2020-10-30 13:12:02 +00:00
|
|
|
const avatar = getRoomAvatar(item);
|
|
|
|
const isRead = getIsRead(item);
|
2020-12-04 19:25:51 +00:00
|
|
|
const date = item.roomUpdatedAt && formatDate(item.roomUpdatedAt);
|
2021-09-13 20:41:05 +00:00
|
|
|
const alert = item.alert || item.tunread?.length;
|
2022-06-27 18:23:43 +00:00
|
|
|
const connected = useAppSelector(state => state.meteor.connected);
|
|
|
|
const userStatus = useAppSelector(state => state.activeUsers[id || '']?.status);
|
|
|
|
const [_, forceUpdate] = useReducer(x => x + 1, 1);
|
|
|
|
const roomSubscription = useRef<Subscription | null>(null);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const init = () => {
|
|
|
|
if (item?.observe) {
|
|
|
|
const observable = item.observe();
|
|
|
|
roomSubscription.current = observable?.subscribe?.(() => {
|
|
|
|
if (_) forceUpdate();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
init();
|
|
|
|
|
|
|
|
return () => roomSubscription.current?.unsubscribe();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const isDirect = !!(item.t === 'd' && id && !isGroupChat(item));
|
|
|
|
if (connected && isDirect) {
|
|
|
|
getUserPresence(id);
|
|
|
|
}
|
|
|
|
}, [connected]);
|
|
|
|
|
|
|
|
const handleOnPress = () => onPress(item);
|
|
|
|
|
|
|
|
const handleOnLongPress = () => onLongPress && onLongPress(item);
|
|
|
|
|
|
|
|
let accessibilityLabel = '';
|
2020-10-30 13:12:02 +00:00
|
|
|
if (item.unread === 1) {
|
2022-06-27 18:23:43 +00:00
|
|
|
accessibilityLabel = `, ${item.unread} ${I18n.t('alert')}`;
|
2020-10-30 13:12:02 +00:00
|
|
|
} else if (item.unread > 1) {
|
2022-06-27 18:23:43 +00:00
|
|
|
accessibilityLabel = `, ${item.unread} ${I18n.t('alerts')}`;
|
2020-10-30 13:12:02 +00:00
|
|
|
}
|
|
|
|
if (item.userMentions > 0) {
|
2022-06-27 18:23:43 +00:00
|
|
|
accessibilityLabel = `, ${I18n.t('you_were_mentioned')}`;
|
2020-10-30 13:12:02 +00:00
|
|
|
}
|
|
|
|
if (date) {
|
2022-06-27 18:23:43 +00:00
|
|
|
accessibilityLabel = `, ${I18n.t('last_message')} ${date}`;
|
2020-10-30 13:12:02 +00:00
|
|
|
}
|
|
|
|
|
2022-07-14 17:18:45 +00:00
|
|
|
const status = item.t === 'l' ? item.visitor?.status || item.v?.status : userStatus;
|
|
|
|
|
2020-10-30 13:12:02 +00:00
|
|
|
return (
|
|
|
|
<RoomItem
|
|
|
|
name={name}
|
|
|
|
avatar={avatar}
|
2022-06-27 18:23:43 +00:00
|
|
|
isGroupChat={isGroupChat(item)}
|
2020-10-30 13:12:02 +00:00
|
|
|
isRead={isRead}
|
2022-06-27 18:23:43 +00:00
|
|
|
onPress={handleOnPress}
|
|
|
|
onLongPress={handleOnLongPress}
|
2020-10-30 13:12:02 +00:00
|
|
|
date={date}
|
|
|
|
accessibilityLabel={accessibilityLabel}
|
|
|
|
width={width}
|
|
|
|
favorite={item.f}
|
|
|
|
rid={item.rid}
|
2022-06-27 18:23:43 +00:00
|
|
|
toggleFav={toggleFav}
|
2020-10-30 13:12:02 +00:00
|
|
|
toggleRead={toggleRead}
|
|
|
|
hideChannel={hideChannel}
|
|
|
|
testID={testID}
|
|
|
|
type={item.t}
|
|
|
|
isFocused={isFocused}
|
|
|
|
prid={item.prid}
|
2022-07-14 17:18:45 +00:00
|
|
|
status={status}
|
2020-10-30 13:12:02 +00:00
|
|
|
hideUnreadStatus={item.hideUnreadStatus}
|
2022-06-13 13:24:54 +00:00
|
|
|
hideMentionStatus={item.hideMentionStatus}
|
2020-10-30 17:35:07 +00:00
|
|
|
alert={alert}
|
2020-10-30 13:12:02 +00:00
|
|
|
lastMessage={item.lastMessage}
|
|
|
|
showLastMessage={showLastMessage}
|
|
|
|
username={username}
|
|
|
|
useRealName={useRealName}
|
|
|
|
unread={item.unread}
|
2020-10-30 17:35:07 +00:00
|
|
|
userMentions={item.userMentions}
|
2020-10-30 13:12:02 +00:00
|
|
|
groupMentions={item.groupMentions}
|
2020-10-30 17:35:07 +00:00
|
|
|
tunread={item.tunread}
|
|
|
|
tunreadUser={item.tunreadUser}
|
|
|
|
tunreadGroup={item.tunreadGroup}
|
2020-10-30 13:12:02 +00:00
|
|
|
swipeEnabled={swipeEnabled}
|
2021-04-07 18:31:25 +00:00
|
|
|
teamMain={item.teamMain}
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
autoJoin={autoJoin}
|
2021-10-06 20:30:10 +00:00
|
|
|
showAvatar={showAvatar}
|
|
|
|
displayMode={displayMode}
|
2022-04-15 02:27:36 +00:00
|
|
|
sourceType={item.source}
|
2020-10-30 13:12:02 +00:00
|
|
|
/>
|
|
|
|
);
|
2022-06-27 18:23:43 +00:00
|
|
|
},
|
|
|
|
(props, nextProps) => attrs.every(key => props[key] === nextProps[key])
|
|
|
|
);
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2022-06-27 18:23:43 +00:00
|
|
|
export default RoomItemContainer;
|