2020-10-30 13:12:02 +00:00
|
|
|
import React from 'react';
|
2019-09-16 20:26:32 +00:00
|
|
|
import { connect } from 'react-redux';
|
2019-04-18 20:57:35 +00:00
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
2021-10-06 20:30:10 +00:00
|
|
|
import { ROW_HEIGHT, ROW_HEIGHT_CONDENSED } from './styles';
|
2020-07-31 17:06:22 +00:00
|
|
|
import { formatDate } from '../../utils/room';
|
|
|
|
import RoomItem from './RoomItem';
|
2022-03-25 20:05:49 +00:00
|
|
|
import { TUserStatus } from '../../definitions';
|
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
|
|
|
interface IRoomItemContainerProps {
|
|
|
|
item: any;
|
|
|
|
showLastMessage: boolean;
|
|
|
|
id: string;
|
|
|
|
onPress: Function;
|
|
|
|
onLongPress: Function;
|
|
|
|
username: string;
|
|
|
|
avatarSize: number;
|
|
|
|
width: number;
|
2022-03-25 20:05:49 +00:00
|
|
|
status: TUserStatus;
|
2021-09-13 20:41:05 +00:00
|
|
|
toggleFav(): void;
|
|
|
|
toggleRead(): void;
|
|
|
|
hideChannel(): void;
|
|
|
|
useRealName: boolean;
|
|
|
|
getUserPresence: Function;
|
|
|
|
connected: boolean;
|
|
|
|
theme: string;
|
|
|
|
isFocused: boolean;
|
|
|
|
getRoomTitle: Function;
|
|
|
|
getRoomAvatar: Function;
|
|
|
|
getIsGroupChat: Function;
|
|
|
|
getIsRead: Function;
|
|
|
|
swipeEnabled: boolean;
|
|
|
|
autoJoin: boolean;
|
2021-10-06 20:30:10 +00:00
|
|
|
showAvatar: boolean;
|
|
|
|
displayMode: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 20:30:10 +00:00
|
|
|
const attrs = [
|
|
|
|
'width',
|
|
|
|
'status',
|
|
|
|
'connected',
|
|
|
|
'theme',
|
|
|
|
'isFocused',
|
|
|
|
'forceUpdate',
|
|
|
|
'showLastMessage',
|
|
|
|
'autoJoin',
|
|
|
|
'showAvatar',
|
|
|
|
'displayMode'
|
|
|
|
];
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
class RoomItemContainer extends React.Component<IRoomItemContainerProps, any> {
|
|
|
|
private mounted: boolean;
|
|
|
|
|
|
|
|
private roomSubscription: any;
|
2020-10-30 13:12:02 +00:00
|
|
|
|
2022-03-25 20:05:49 +00:00
|
|
|
static defaultProps: Partial<IRoomItemContainerProps> = {
|
2020-10-30 13:12:02 +00:00
|
|
|
avatarSize: 48,
|
|
|
|
status: 'offline',
|
|
|
|
getUserPresence: () => {},
|
|
|
|
getRoomTitle: () => 'title',
|
|
|
|
getRoomAvatar: () => '',
|
|
|
|
getIsGroupChat: () => false,
|
|
|
|
getIsRead: () => false,
|
|
|
|
swipeEnabled: true
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-10-30 13:12:02 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
constructor(props: IRoomItemContainerProps) {
|
2020-10-30 13:12:02 +00:00
|
|
|
super(props);
|
|
|
|
this.mounted = false;
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.mounted = true;
|
2020-12-01 11:19:37 +00:00
|
|
|
const { connected, getUserPresence, id } = this.props;
|
|
|
|
if (connected && this.isDirect) {
|
|
|
|
getUserPresence(id);
|
|
|
|
}
|
2020-10-30 13:12:02 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
shouldComponentUpdate(nextProps: any) {
|
|
|
|
const { props }: any = this;
|
2020-10-30 13:12:02 +00:00
|
|
|
return !attrs.every(key => props[key] === nextProps[key]);
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
componentDidUpdate(prevProps: any) {
|
2020-10-30 13:12:02 +00:00
|
|
|
const { connected, getUserPresence, id } = this.props;
|
|
|
|
if (prevProps.connected !== connected && connected && this.isDirect) {
|
2020-04-01 12:28:54 +00:00
|
|
|
getUserPresence(id);
|
2020-03-03 21:10:39 +00:00
|
|
|
}
|
2020-10-30 13:12:02 +00:00
|
|
|
}
|
2020-03-03 21:10:39 +00:00
|
|
|
|
2020-10-30 13:12:02 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.roomSubscription?.unsubscribe) {
|
|
|
|
this.roomSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get isGroupChat() {
|
|
|
|
const { item, getIsGroupChat } = this.props;
|
|
|
|
return getIsGroupChat(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
get isDirect() {
|
2021-09-13 20:41:05 +00:00
|
|
|
const {
|
|
|
|
item: { t },
|
|
|
|
id
|
|
|
|
}: any = this.props;
|
2020-10-30 13:12:02 +00:00
|
|
|
return t === 'd' && id && !this.isGroupChat;
|
|
|
|
}
|
|
|
|
|
2020-11-04 16:53:44 +00:00
|
|
|
init = () => {
|
2020-10-30 13:12:02 +00:00
|
|
|
const { item } = this.props;
|
2020-07-20 16:44:54 +00:00
|
|
|
if (item?.observe) {
|
|
|
|
const observable = item.observe();
|
2020-10-30 13:12:02 +00:00
|
|
|
this.roomSubscription = observable?.subscribe?.(() => {
|
|
|
|
this.forceUpdate();
|
2020-07-20 16:44:54 +00:00
|
|
|
});
|
2020-10-30 13:12:02 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-22 20:15:35 +00:00
|
|
|
|
2020-10-30 13:12:02 +00:00
|
|
|
onPress = () => {
|
|
|
|
const { item, onPress } = this.props;
|
|
|
|
return onPress(item);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-04-18 20:57:35 +00:00
|
|
|
|
[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
|
|
|
onLongPress = () => {
|
|
|
|
const { item, onLongPress } = this.props;
|
2021-06-10 17:11:05 +00:00
|
|
|
if (onLongPress) {
|
|
|
|
return onLongPress(item);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
[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
|
|
|
|
2020-10-30 13:12:02 +00:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
item,
|
|
|
|
getRoomTitle,
|
|
|
|
getRoomAvatar,
|
|
|
|
getIsRead,
|
|
|
|
width,
|
|
|
|
toggleFav,
|
|
|
|
toggleRead,
|
|
|
|
hideChannel,
|
|
|
|
theme,
|
|
|
|
isFocused,
|
|
|
|
avatarSize,
|
|
|
|
status,
|
|
|
|
showLastMessage,
|
|
|
|
username,
|
|
|
|
useRealName,
|
[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
|
|
|
swipeEnabled,
|
2021-10-06 20:30:10 +00:00
|
|
|
autoJoin,
|
|
|
|
showAvatar,
|
|
|
|
displayMode
|
2020-10-30 13:12:02 +00:00
|
|
|
} = this.props;
|
|
|
|
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;
|
2020-10-30 13:12:02 +00:00
|
|
|
|
|
|
|
let accessibilityLabel = name;
|
|
|
|
if (item.unread === 1) {
|
2021-09-13 20:41:05 +00:00
|
|
|
accessibilityLabel += `, ${item.unread} ${I18n.t('alert')}`;
|
2020-10-30 13:12:02 +00:00
|
|
|
} else if (item.unread > 1) {
|
2021-09-13 20:41:05 +00:00
|
|
|
accessibilityLabel += `, ${item.unread} ${I18n.t('alerts')}`;
|
2020-10-30 13:12:02 +00:00
|
|
|
}
|
2019-07-01 14:20:38 +00:00
|
|
|
|
2020-10-30 13:12:02 +00:00
|
|
|
if (item.userMentions > 0) {
|
2021-09-13 20:41:05 +00:00
|
|
|
accessibilityLabel += `, ${I18n.t('you_were_mentioned')}`;
|
2020-10-30 13:12:02 +00:00
|
|
|
}
|
2019-10-29 13:53:58 +00:00
|
|
|
|
2020-10-30 13:12:02 +00:00
|
|
|
if (date) {
|
2021-09-13 20:41:05 +00:00
|
|
|
accessibilityLabel += `, ${I18n.t('last_message')} ${date}`;
|
2020-10-30 13:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
// @ts-ignore
|
2020-10-30 13:12:02 +00:00
|
|
|
<RoomItem
|
|
|
|
name={name}
|
|
|
|
avatar={avatar}
|
|
|
|
isGroupChat={this.isGroupChat}
|
|
|
|
isRead={isRead}
|
|
|
|
onPress={this.onPress}
|
[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
|
|
|
onLongPress={this.onLongPress}
|
2020-10-30 13:12:02 +00:00
|
|
|
date={date}
|
|
|
|
accessibilityLabel={accessibilityLabel}
|
|
|
|
width={width}
|
|
|
|
favorite={item.f}
|
|
|
|
toggleFav={toggleFav}
|
|
|
|
rid={item.rid}
|
|
|
|
toggleRead={toggleRead}
|
|
|
|
hideChannel={hideChannel}
|
|
|
|
testID={testID}
|
|
|
|
type={item.t}
|
|
|
|
theme={theme}
|
|
|
|
isFocused={isFocused}
|
|
|
|
size={avatarSize}
|
|
|
|
prid={item.prid}
|
|
|
|
status={status}
|
|
|
|
hideUnreadStatus={item.hideUnreadStatus}
|
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}
|
2020-10-30 13:12:02 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const mapStateToProps = (state: any, ownProps: any) => {
|
2021-03-31 17:47:17 +00:00
|
|
|
let status = 'loading';
|
2020-05-08 17:36:10 +00:00
|
|
|
const { id, type, visitor = {} } = ownProps;
|
|
|
|
if (state.meteor.connected) {
|
|
|
|
if (type === 'd') {
|
2021-03-31 17:47:17 +00:00
|
|
|
status = state.activeUsers[id]?.status || 'loading';
|
2020-05-08 17:36:10 +00:00
|
|
|
} else if (type === 'l' && visitor?.status) {
|
|
|
|
({ status } = visitor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
connected: state.meteor.connected,
|
2022-03-25 20:05:49 +00:00
|
|
|
status: status as TUserStatus
|
2020-05-08 17:36:10 +00:00
|
|
|
};
|
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2020-07-31 17:06:22 +00:00
|
|
|
export default connect(mapStateToProps)(RoomItemContainer);
|