2017-08-03 18:23:43 +00:00
|
|
|
import React from 'react';
|
2017-08-05 18:16:32 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-09-25 19:28:42 +00:00
|
|
|
import {
|
2019-09-16 20:26:32 +00:00
|
|
|
View,
|
|
|
|
FlatList,
|
|
|
|
BackHandler,
|
|
|
|
Text,
|
|
|
|
Keyboard,
|
2020-02-11 20:13:44 +00:00
|
|
|
RefreshControl
|
2018-09-25 19:28:42 +00:00
|
|
|
} from 'react-native';
|
2019-01-31 16:08:38 +00:00
|
|
|
import { connect } from 'react-redux';
|
2020-07-20 16:44:54 +00:00
|
|
|
import isEqual from 'react-fast-compare';
|
2019-03-12 16:23:06 +00:00
|
|
|
import Orientation from 'react-native-orientation-locker';
|
2019-09-16 20:26:32 +00:00
|
|
|
import { Q } from '@nozbe/watermelondb';
|
2020-07-06 20:56:28 +00:00
|
|
|
import { withSafeAreaInsets } from 'react-native-safe-area-context';
|
2018-05-18 17:55:08 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
import database from '../../lib/database';
|
2017-12-08 19:13:21 +00:00
|
|
|
import RocketChat from '../../lib/rocketchat';
|
2019-03-29 19:36:07 +00:00
|
|
|
import RoomItem, { ROW_HEIGHT } from '../../presentation/RoomItem';
|
2017-12-08 19:13:21 +00:00
|
|
|
import styles from './styles';
|
2020-07-30 13:26:17 +00:00
|
|
|
import log, { logEvent, events } from '../../utils/log';
|
2018-06-01 17:38:13 +00:00
|
|
|
import I18n from '../../i18n';
|
2018-08-31 16:46:33 +00:00
|
|
|
import SortDropdown from './SortDropdown';
|
|
|
|
import ServerDropdown from './ServerDropdown';
|
2019-02-07 16:13:21 +00:00
|
|
|
import {
|
|
|
|
toggleSortDropdown as toggleSortDropdownAction,
|
|
|
|
openSearchHeader as openSearchHeaderAction,
|
2019-06-05 13:39:12 +00:00
|
|
|
closeSearchHeader as closeSearchHeaderAction,
|
2019-10-28 12:46:50 +00:00
|
|
|
roomsRequest as roomsRequestAction,
|
|
|
|
closeServerDropdown as closeServerDropdownAction
|
2019-02-07 16:13:21 +00:00
|
|
|
} from '../../actions/rooms';
|
2020-06-15 14:00:46 +00:00
|
|
|
import { appStart as appStartAction, ROOT_BACKGROUND } from '../../actions/app';
|
2018-12-21 10:55:35 +00:00
|
|
|
import debounce from '../../utils/debounce';
|
2020-07-06 20:56:28 +00:00
|
|
|
import { isIOS, isTablet } from '../../utils/deviceInfo';
|
2019-03-12 16:23:06 +00:00
|
|
|
import RoomsListHeaderView from './Header';
|
2019-09-16 20:26:32 +00:00
|
|
|
import {
|
|
|
|
DrawerButton,
|
|
|
|
CustomHeaderButtons,
|
|
|
|
Item
|
|
|
|
} from '../../containers/HeaderButton';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2019-12-04 16:39:53 +00:00
|
|
|
import ActivityIndicator from '../../containers/ActivityIndicator';
|
2019-04-17 18:57:46 +00:00
|
|
|
import ListHeader from './ListHeader';
|
2019-06-17 13:57:07 +00:00
|
|
|
import { selectServerRequest as selectServerRequestAction } from '../../actions/server';
|
2019-09-19 13:32:24 +00:00
|
|
|
import { animateNextTransition } from '../../utils/layoutAnimation';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { withTheme } from '../../theme';
|
|
|
|
import { themes } from '../../constants/colors';
|
2019-11-25 20:01:17 +00:00
|
|
|
import EventEmitter from '../../utils/events';
|
|
|
|
import {
|
|
|
|
KEY_COMMAND,
|
|
|
|
handleCommandShowPreferences,
|
|
|
|
handleCommandSearching,
|
|
|
|
handleCommandSelectRoom,
|
|
|
|
handleCommandPreviousRoom,
|
|
|
|
handleCommandNextRoom,
|
|
|
|
handleCommandShowNewMessage,
|
|
|
|
handleCommandAddNewServer
|
|
|
|
} from '../../commands';
|
|
|
|
import { MAX_SIDEBAR_WIDTH } from '../../constants/tablet';
|
2020-02-11 14:09:14 +00:00
|
|
|
import { getUserSelector } from '../../selectors/login';
|
2020-05-13 19:02:57 +00:00
|
|
|
import { goRoom } from '../../utils/goRoom';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2020-07-06 20:56:28 +00:00
|
|
|
import Header, { getHeaderTitlePosition } from '../../containers/Header';
|
2020-06-17 17:35:58 +00:00
|
|
|
import { withDimensions } from '../../dimensions';
|
2020-08-21 13:38:50 +00:00
|
|
|
import { showErrorAlert, showConfirmationAlert } from '../../utils/info';
|
2020-09-11 14:31:38 +00:00
|
|
|
import { E2E_BANNER_TYPE } from '../../lib/encryption/constants';
|
2020-08-28 19:41:08 +00:00
|
|
|
|
|
|
|
import { getInquiryQueueSelector } from '../../ee/omnichannel/selectors/inquiry';
|
|
|
|
import { changeLivechatStatus, isOmnichannelStatusAvailable } from '../../ee/omnichannel/lib';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
const INITIAL_NUM_TO_RENDER = isTablet ? 20 : 12;
|
|
|
|
const CHATS_HEADER = 'Chats';
|
|
|
|
const UNREAD_HEADER = 'Unread';
|
|
|
|
const FAVORITES_HEADER = 'Favorites';
|
|
|
|
const DISCUSSIONS_HEADER = 'Discussions';
|
|
|
|
const CHANNELS_HEADER = 'Channels';
|
|
|
|
const DM_HEADER = 'Direct_Messages';
|
|
|
|
const GROUPS_HEADER = 'Private_Groups';
|
2020-08-25 12:10:15 +00:00
|
|
|
const OMNICHANNEL_HEADER = 'Open_Livechats';
|
2020-07-20 16:44:54 +00:00
|
|
|
const QUERY_SIZE = 20;
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2019-12-03 12:32:02 +00:00
|
|
|
const filterIsUnread = s => (s.unread > 0 || s.alert) && !s.hideUnreadStatus;
|
|
|
|
const filterIsFavorite = s => s.f;
|
2020-08-25 12:10:15 +00:00
|
|
|
const filterIsOmnichannel = s => s.t === 'l';
|
2019-12-03 12:32:02 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
const shouldUpdateProps = [
|
|
|
|
'searchText',
|
|
|
|
'loadingServer',
|
|
|
|
'showServerDropdown',
|
|
|
|
'showSortDropdown',
|
|
|
|
'sortBy',
|
|
|
|
'groupByType',
|
|
|
|
'showFavorites',
|
|
|
|
'showUnread',
|
|
|
|
'useRealName',
|
|
|
|
'StoreLastMessage',
|
2019-11-25 20:01:17 +00:00
|
|
|
'appState',
|
2019-12-04 16:39:53 +00:00
|
|
|
'theme',
|
2020-06-15 14:00:46 +00:00
|
|
|
'isMasterDetail',
|
2020-07-31 18:22:30 +00:00
|
|
|
'refreshing',
|
|
|
|
'queueSize',
|
2020-09-11 14:31:38 +00:00
|
|
|
'inquiryEnabled',
|
|
|
|
'encryptionBanner'
|
2019-09-16 20:26:32 +00:00
|
|
|
];
|
|
|
|
const getItemLayout = (data, index) => ({
|
|
|
|
length: ROW_HEIGHT,
|
|
|
|
offset: ROW_HEIGHT * index,
|
|
|
|
index
|
|
|
|
});
|
2018-09-26 13:56:36 +00:00
|
|
|
const keyExtractor = item => item.rid;
|
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class RoomsListView extends React.Component {
|
2017-08-05 18:16:32 +00:00
|
|
|
static propTypes = {
|
2019-03-12 16:23:06 +00:00
|
|
|
navigation: PropTypes.object,
|
2020-02-11 14:09:14 +00:00
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string,
|
|
|
|
username: PropTypes.string,
|
2020-08-21 13:38:50 +00:00
|
|
|
token: PropTypes.string,
|
2020-08-25 12:10:15 +00:00
|
|
|
statusLivechat: PropTypes.string,
|
|
|
|
roles: PropTypes.object
|
2020-02-11 14:09:14 +00:00
|
|
|
}),
|
2017-12-08 19:13:21 +00:00
|
|
|
server: PropTypes.string,
|
2018-08-01 19:35:06 +00:00
|
|
|
searchText: PropTypes.string,
|
2018-08-31 16:46:33 +00:00
|
|
|
loadingServer: PropTypes.bool,
|
|
|
|
showServerDropdown: PropTypes.bool,
|
|
|
|
showSortDropdown: PropTypes.bool,
|
2018-09-04 14:29:20 +00:00
|
|
|
sortBy: PropTypes.string,
|
|
|
|
groupByType: PropTypes.bool,
|
|
|
|
showFavorites: PropTypes.bool,
|
|
|
|
showUnread: PropTypes.bool,
|
2020-02-11 20:13:44 +00:00
|
|
|
refreshing: PropTypes.bool,
|
2019-03-29 19:36:07 +00:00
|
|
|
StoreLastMessage: PropTypes.bool,
|
2019-06-05 13:39:12 +00:00
|
|
|
appState: PropTypes.string,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2018-10-23 21:39:48 +00:00
|
|
|
toggleSortDropdown: PropTypes.func,
|
|
|
|
openSearchHeader: PropTypes.func,
|
2018-11-27 19:40:53 +00:00
|
|
|
closeSearchHeader: PropTypes.func,
|
2019-06-05 13:39:12 +00:00
|
|
|
appStart: PropTypes.func,
|
2019-10-28 12:46:50 +00:00
|
|
|
roomsRequest: PropTypes.func,
|
2019-11-25 20:01:17 +00:00
|
|
|
closeServerDropdown: PropTypes.func,
|
2020-02-21 16:13:05 +00:00
|
|
|
useRealName: PropTypes.bool,
|
2020-04-03 18:03:53 +00:00
|
|
|
connected: PropTypes.bool,
|
2020-06-15 14:00:46 +00:00
|
|
|
isMasterDetail: PropTypes.bool,
|
2020-06-17 17:35:58 +00:00
|
|
|
rooms: PropTypes.array,
|
2020-07-06 20:56:28 +00:00
|
|
|
width: PropTypes.number,
|
2020-07-31 18:22:30 +00:00
|
|
|
insets: PropTypes.object,
|
|
|
|
queueSize: PropTypes.number,
|
2020-09-11 14:31:38 +00:00
|
|
|
inquiryEnabled: PropTypes.bool,
|
|
|
|
encryptionBanner: PropTypes.string
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2017-08-09 16:19:17 +00:00
|
|
|
|
2017-08-03 18:23:43 +00:00
|
|
|
constructor(props) {
|
2019-05-28 13:03:08 +00:00
|
|
|
super(props);
|
2019-04-17 18:57:46 +00:00
|
|
|
console.time(`${ this.constructor.name } init`);
|
|
|
|
console.time(`${ this.constructor.name } mount`);
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
this.gotSubscriptions = false;
|
2020-02-17 19:06:18 +00:00
|
|
|
this.animated = false;
|
2020-07-20 16:44:54 +00:00
|
|
|
this.count = 0;
|
2017-08-10 16:16:32 +00:00
|
|
|
this.state = {
|
2018-11-27 19:40:53 +00:00
|
|
|
searching: false,
|
2018-05-24 20:17:00 +00:00
|
|
|
search: [],
|
2018-08-31 16:46:33 +00:00
|
|
|
loading: true,
|
2020-07-20 16:44:54 +00:00
|
|
|
chatsOrder: [],
|
2018-08-31 16:46:33 +00:00
|
|
|
chats: [],
|
2020-06-15 14:00:46 +00:00
|
|
|
item: {}
|
2017-08-10 16:16:32 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
2017-08-13 01:35:09 +00:00
|
|
|
}
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2018-07-18 20:34:59 +00:00
|
|
|
componentDidMount() {
|
2020-07-02 17:14:12 +00:00
|
|
|
const {
|
|
|
|
navigation, closeServerDropdown, appState
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* - When didMount is triggered and appState is foreground,
|
|
|
|
* it means the user is logging in and selectServer has ran, so we can getSubscriptions
|
|
|
|
*
|
|
|
|
* - When didMount is triggered and appState is background,
|
|
|
|
* it means the user has resumed the app, so selectServer needs to be triggered,
|
|
|
|
* which is going to change server and getSubscriptions will be triggered by componentWillReceiveProps
|
|
|
|
*/
|
|
|
|
if (appState === 'foreground') {
|
|
|
|
this.getSubscriptions();
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
this.unsubscribeFocus = navigation.addListener('focus', () => {
|
2020-05-08 17:04:37 +00:00
|
|
|
Orientation.unlockAllOrientations();
|
2020-02-17 19:06:18 +00:00
|
|
|
this.animated = true;
|
2020-04-30 17:38:57 +00:00
|
|
|
// Check if there were changes while not focused (it's set on sCU)
|
|
|
|
if (this.shouldUpdate) {
|
|
|
|
this.forceUpdate();
|
|
|
|
this.shouldUpdate = false;
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
|
|
|
|
});
|
2020-06-15 14:00:46 +00:00
|
|
|
this.unsubscribeBlur = navigation.addListener('blur', () => {
|
2020-02-17 19:06:18 +00:00
|
|
|
this.animated = false;
|
2019-11-25 20:01:17 +00:00
|
|
|
closeServerDropdown();
|
2020-06-15 14:00:46 +00:00
|
|
|
this.cancelSearch();
|
2019-11-27 20:53:46 +00:00
|
|
|
if (this.backHandler && this.backHandler.remove) {
|
|
|
|
this.backHandler.remove();
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
});
|
2019-04-17 18:57:46 +00:00
|
|
|
console.timeEnd(`${ this.constructor.name } mount`);
|
2018-07-18 20:34:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 16:37:49 +00:00
|
|
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
2019-11-25 20:01:17 +00:00
|
|
|
const { loadingServer, searchText, server } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
|
|
|
if (nextProps.server && loadingServer !== nextProps.loadingServer) {
|
2018-08-31 16:46:33 +00:00
|
|
|
if (nextProps.loadingServer) {
|
2019-11-25 20:01:17 +00:00
|
|
|
this.setState({ loading: true });
|
2018-08-31 16:46:33 +00:00
|
|
|
} else {
|
|
|
|
this.getSubscriptions();
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
if (server && server !== nextProps.server) {
|
|
|
|
this.gotSubscriptions = false;
|
|
|
|
}
|
|
|
|
if (searchText !== nextProps.searchText) {
|
2018-08-31 16:46:33 +00:00
|
|
|
this.search(nextProps.searchText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
2020-07-20 16:44:54 +00:00
|
|
|
const { chatsOrder, searching, item } = this.state;
|
2018-12-21 10:55:35 +00:00
|
|
|
// eslint-disable-next-line react/destructuring-assignment
|
|
|
|
const propsUpdated = shouldUpdateProps.some(key => nextProps[key] !== this.props[key]);
|
|
|
|
if (propsUpdated) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-24 18:19:33 +00:00
|
|
|
// Compare changes only once
|
2020-07-20 16:44:54 +00:00
|
|
|
const chatsNotEqual = !isEqual(nextState.chatsOrder, chatsOrder);
|
2019-09-24 18:19:33 +00:00
|
|
|
|
|
|
|
// If they aren't equal, set to update if focused
|
|
|
|
if (chatsNotEqual) {
|
|
|
|
this.shouldUpdate = true;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:24:39 +00:00
|
|
|
if (nextState.searching !== searching) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
if (nextState.item?.rid !== item?.rid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-24 18:19:33 +00:00
|
|
|
// Abort if it's not focused
|
2019-09-16 20:26:32 +00:00
|
|
|
if (!nextProps.navigation.isFocused()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
loading,
|
|
|
|
search
|
|
|
|
} = this.state;
|
2020-07-06 20:56:28 +00:00
|
|
|
const { rooms, width, insets } = this.props;
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextState.loading !== loading) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-17 17:35:58 +00:00
|
|
|
if (nextProps.width !== width) {
|
2019-07-04 16:15:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
if (!isEqual(nextState.search, search)) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
if (!isEqual(nextProps.rooms, rooms)) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-06 20:56:28 +00:00
|
|
|
if (!isEqual(nextProps.insets, insets)) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-24 18:19:33 +00:00
|
|
|
// If it's focused and there are changes, update
|
|
|
|
if (chatsNotEqual) {
|
|
|
|
this.shouldUpdate = false;
|
2019-09-16 20:26:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
return false;
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
2018-09-25 19:28:42 +00:00
|
|
|
const {
|
2019-09-16 20:26:32 +00:00
|
|
|
sortBy,
|
|
|
|
groupByType,
|
|
|
|
showFavorites,
|
|
|
|
showUnread,
|
|
|
|
appState,
|
2020-04-03 18:03:53 +00:00
|
|
|
connected,
|
2020-06-15 14:00:46 +00:00
|
|
|
roomsRequest,
|
|
|
|
rooms,
|
2020-07-06 20:56:28 +00:00
|
|
|
isMasterDetail,
|
|
|
|
insets
|
2018-09-25 19:28:42 +00:00
|
|
|
} = this.props;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { item } = this.state;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
if (
|
|
|
|
!(
|
|
|
|
prevProps.sortBy === sortBy
|
|
|
|
&& prevProps.groupByType === groupByType
|
|
|
|
&& prevProps.showFavorites === showFavorites
|
|
|
|
&& prevProps.showUnread === showUnread
|
|
|
|
)
|
|
|
|
) {
|
2020-07-20 16:44:54 +00:00
|
|
|
this.getSubscriptions();
|
2019-09-16 20:26:32 +00:00
|
|
|
} else if (
|
|
|
|
appState === 'foreground'
|
|
|
|
&& appState !== prevProps.appState
|
2020-04-03 18:03:53 +00:00
|
|
|
&& connected
|
2019-09-16 20:26:32 +00:00
|
|
|
) {
|
2019-06-05 13:39:12 +00:00
|
|
|
roomsRequest();
|
2017-11-07 20:25:04 +00:00
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
// Update current item in case of another action triggers an update on rooms reducer
|
|
|
|
if (isMasterDetail && item?.rid !== rooms[0] && !isEqual(rooms, prevProps.rooms)) {
|
|
|
|
// eslint-disable-next-line react/no-did-update-set-state
|
|
|
|
this.setState({ item: { rid: rooms[0] } });
|
|
|
|
}
|
2020-07-06 20:56:28 +00:00
|
|
|
if (insets.left !== prevProps.insets.left || insets.right !== prevProps.insets.right) {
|
|
|
|
this.setHeader();
|
|
|
|
}
|
2017-11-07 20:25:04 +00:00
|
|
|
}
|
2018-03-02 21:31:44 +00:00
|
|
|
|
2017-08-09 16:19:17 +00:00
|
|
|
componentWillUnmount() {
|
2020-07-20 16:44:54 +00:00
|
|
|
this.unsubscribeQuery();
|
2020-06-15 14:00:46 +00:00
|
|
|
if (this.unsubscribeFocus) {
|
|
|
|
this.unsubscribeFocus();
|
2019-09-24 18:19:33 +00:00
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
if (this.unsubscribeBlur) {
|
|
|
|
this.unsubscribeBlur();
|
2019-05-03 14:54:57 +00:00
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.removeListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
2019-04-17 18:57:46 +00:00
|
|
|
console.countReset(`${ this.constructor.name }.render calls`);
|
2017-08-12 20:52:55 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
getHeader = () => {
|
|
|
|
const { searching } = this.state;
|
2020-07-06 20:56:28 +00:00
|
|
|
const { navigation, isMasterDetail, insets } = this.props;
|
|
|
|
const headerTitlePosition = getHeaderTitlePosition(insets);
|
2020-06-15 14:00:46 +00:00
|
|
|
return {
|
2020-07-06 20:56:28 +00:00
|
|
|
headerTitleAlign: 'left',
|
|
|
|
headerLeft: () => (searching ? (
|
2020-06-15 14:00:46 +00:00
|
|
|
<CustomHeaderButtons left>
|
|
|
|
<Item
|
|
|
|
title='cancel'
|
2020-07-27 19:53:33 +00:00
|
|
|
iconName='close'
|
2020-06-15 14:00:46 +00:00
|
|
|
onPress={this.cancelSearch}
|
|
|
|
/>
|
|
|
|
</CustomHeaderButtons>
|
|
|
|
) : (
|
|
|
|
<DrawerButton
|
|
|
|
navigation={navigation}
|
|
|
|
testID='rooms-list-view-sidebar'
|
2020-07-06 20:56:28 +00:00
|
|
|
onPress={isMasterDetail
|
|
|
|
? () => navigation.navigate('ModalStackNavigator', { screen: 'SettingsView' })
|
|
|
|
: () => navigation.toggleDrawer()}
|
2020-06-15 14:00:46 +00:00
|
|
|
/>
|
|
|
|
)),
|
|
|
|
headerTitle: () => <RoomsListHeaderView />,
|
2020-07-06 20:56:28 +00:00
|
|
|
headerTitleContainerStyle: {
|
|
|
|
left: headerTitlePosition.left,
|
|
|
|
right: headerTitlePosition.right
|
|
|
|
},
|
|
|
|
headerRight: () => (searching ? null : (
|
2020-06-15 14:00:46 +00:00
|
|
|
<CustomHeaderButtons>
|
|
|
|
<Item
|
|
|
|
title='new'
|
2020-07-27 19:53:33 +00:00
|
|
|
iconName='create'
|
2020-07-30 13:26:17 +00:00
|
|
|
onPress={this.goToNewMessage}
|
2020-06-15 14:00:46 +00:00
|
|
|
testID='rooms-list-view-create-channel'
|
|
|
|
/>
|
2020-07-06 20:56:28 +00:00
|
|
|
<Item
|
|
|
|
title='search'
|
2020-07-27 19:53:33 +00:00
|
|
|
iconName='search'
|
2020-07-06 20:56:28 +00:00
|
|
|
onPress={this.initSearching}
|
|
|
|
testID='rooms-list-view-search'
|
|
|
|
/>
|
2020-08-20 14:16:33 +00:00
|
|
|
<Item
|
|
|
|
title='directory'
|
|
|
|
iconName='directory'
|
|
|
|
onPress={this.goDirectory}
|
|
|
|
testID='rooms-list-view-directory'
|
|
|
|
/>
|
2020-06-15 14:00:46 +00:00
|
|
|
</CustomHeaderButtons>
|
|
|
|
))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
setHeader = () => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
const options = this.getHeader();
|
|
|
|
navigation.setOptions(options);
|
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
internalSetState = (...args) => {
|
2020-02-17 19:06:18 +00:00
|
|
|
if (this.animated) {
|
2019-09-19 13:32:24 +00:00
|
|
|
animateNextTransition();
|
2018-10-29 13:54:23 +00:00
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
this.setState(...args);
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
addRoomsGroup = (data, header, allData) => {
|
|
|
|
if (data.length > 0) {
|
|
|
|
if (header) {
|
|
|
|
allData.push({ rid: header, separator: true });
|
|
|
|
}
|
|
|
|
allData = allData.concat(data);
|
|
|
|
}
|
|
|
|
return allData;
|
|
|
|
}
|
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
getSubscriptions = async() => {
|
|
|
|
this.unsubscribeQuery();
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
const {
|
2019-09-16 20:26:32 +00:00
|
|
|
sortBy,
|
|
|
|
showUnread,
|
|
|
|
showFavorites,
|
2020-08-25 12:10:15 +00:00
|
|
|
groupByType,
|
|
|
|
user
|
2018-09-25 19:28:42 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
2020-07-20 16:44:54 +00:00
|
|
|
let observable;
|
|
|
|
|
|
|
|
const defaultWhereClause = [
|
|
|
|
Q.where('archived', false),
|
|
|
|
Q.where('open', true)
|
|
|
|
];
|
|
|
|
|
|
|
|
if (sortBy === 'alphabetical') {
|
|
|
|
defaultWhereClause.push(Q.experimentalSortBy(`${ this.useRealName ? 'fname' : 'name' }`, Q.asc));
|
|
|
|
} else {
|
|
|
|
defaultWhereClause.push(Q.experimentalSortBy('room_updated_at', Q.desc));
|
|
|
|
}
|
|
|
|
|
|
|
|
// When we're grouping by something
|
|
|
|
if (this.isGrouping) {
|
|
|
|
observable = await db.collections
|
|
|
|
.get('subscriptions')
|
|
|
|
.query(...defaultWhereClause)
|
|
|
|
.observe();
|
|
|
|
|
|
|
|
// When we're NOT grouping
|
|
|
|
} else {
|
|
|
|
this.count += QUERY_SIZE;
|
|
|
|
observable = await db.collections
|
|
|
|
.get('subscriptions')
|
|
|
|
.query(
|
|
|
|
...defaultWhereClause,
|
|
|
|
Q.experimentalSkip(0),
|
|
|
|
Q.experimentalTake(this.count)
|
|
|
|
)
|
|
|
|
.observe();
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
this.querySubscription = observable.subscribe((data) => {
|
2019-11-25 20:01:17 +00:00
|
|
|
let tempChats = [];
|
2020-07-20 16:44:54 +00:00
|
|
|
let chats = data;
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
/**
|
|
|
|
* We trigger re-render only when chats order changes
|
|
|
|
* RoomItem handles its own re-render
|
|
|
|
*/
|
|
|
|
const chatsOrder = data.map(item => item.rid);
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2020-08-25 12:10:15 +00:00
|
|
|
const isOmnichannelAgent = user?.roles?.includes('livechat-agent');
|
|
|
|
if (isOmnichannelAgent) {
|
|
|
|
const omnichannel = chats.filter(s => filterIsOmnichannel(s));
|
|
|
|
chats = chats.filter(s => !filterIsOmnichannel(s));
|
|
|
|
tempChats = this.addRoomsGroup(omnichannel, OMNICHANNEL_HEADER, tempChats);
|
|
|
|
}
|
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
// unread
|
2018-09-25 19:28:42 +00:00
|
|
|
if (showUnread) {
|
2019-12-03 12:32:02 +00:00
|
|
|
const unread = chats.filter(s => filterIsUnread(s));
|
|
|
|
chats = chats.filter(s => !filterIsUnread(s));
|
2019-11-25 20:01:17 +00:00
|
|
|
tempChats = this.addRoomsGroup(unread, UNREAD_HEADER, tempChats);
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
// favorites
|
2018-09-25 19:28:42 +00:00
|
|
|
if (showFavorites) {
|
2019-12-03 12:32:02 +00:00
|
|
|
const favorites = chats.filter(s => filterIsFavorite(s));
|
|
|
|
chats = chats.filter(s => !filterIsFavorite(s));
|
|
|
|
tempChats = this.addRoomsGroup(favorites, FAVORITES_HEADER, tempChats);
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
// type
|
2018-09-25 19:28:42 +00:00
|
|
|
if (groupByType) {
|
2019-11-25 20:01:17 +00:00
|
|
|
const discussions = chats.filter(s => s.prid);
|
|
|
|
const channels = chats.filter(s => s.t === 'c' && !s.prid);
|
|
|
|
const privateGroup = chats.filter(s => s.t === 'p' && !s.prid);
|
|
|
|
const direct = chats.filter(s => s.t === 'd' && !s.prid);
|
2019-12-03 12:32:02 +00:00
|
|
|
tempChats = this.addRoomsGroup(discussions, DISCUSSIONS_HEADER, tempChats);
|
|
|
|
tempChats = this.addRoomsGroup(channels, CHANNELS_HEADER, tempChats);
|
|
|
|
tempChats = this.addRoomsGroup(privateGroup, GROUPS_HEADER, tempChats);
|
|
|
|
tempChats = this.addRoomsGroup(direct, DM_HEADER, tempChats);
|
2020-08-25 12:10:15 +00:00
|
|
|
} else if (showUnread || showFavorites || isOmnichannelAgent) {
|
2019-12-03 12:32:02 +00:00
|
|
|
tempChats = this.addRoomsGroup(chats, CHATS_HEADER, tempChats);
|
2019-11-25 20:01:17 +00:00
|
|
|
} else {
|
2019-12-03 12:32:02 +00:00
|
|
|
tempChats = chats;
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
this.internalSetState({
|
2019-11-25 20:01:17 +00:00
|
|
|
chats: tempChats,
|
2020-07-20 16:44:54 +00:00
|
|
|
chatsOrder,
|
2019-04-17 18:57:46 +00:00
|
|
|
loading: false
|
2018-08-31 16:46:33 +00:00
|
|
|
});
|
2019-04-17 18:57:46 +00:00
|
|
|
});
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
2018-10-18 17:56:49 +00:00
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
unsubscribeQuery = () => {
|
|
|
|
if (this.querySubscription && this.querySubscription.unsubscribe) {
|
|
|
|
this.querySubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:24:39 +00:00
|
|
|
initSearching = () => {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.RL_SEARCH);
|
2020-06-15 14:00:46 +00:00
|
|
|
const { openSearchHeader } = this.props;
|
|
|
|
this.internalSetState({ searching: true }, () => {
|
2020-07-06 20:56:28 +00:00
|
|
|
openSearchHeader();
|
|
|
|
this.setHeader();
|
2020-06-15 14:00:46 +00:00
|
|
|
});
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-07-10 13:40:32 +00:00
|
|
|
|
2020-02-13 19:24:39 +00:00
|
|
|
cancelSearch = () => {
|
|
|
|
const { searching } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { closeSearchHeader } = this.props;
|
2020-02-13 19:24:39 +00:00
|
|
|
|
|
|
|
if (!searching) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
Keyboard.dismiss();
|
|
|
|
|
2020-02-13 19:24:39 +00:00
|
|
|
this.setState({ searching: false, search: [] }, () => {
|
2020-07-06 20:56:28 +00:00
|
|
|
this.setHeader();
|
|
|
|
closeSearchHeader();
|
2020-02-13 19:24:39 +00:00
|
|
|
setTimeout(() => {
|
2020-07-08 16:36:37 +00:00
|
|
|
this.scrollToTop();
|
2020-02-13 19:24:39 +00:00
|
|
|
}, 200);
|
|
|
|
});
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
handleBackPress = () => {
|
2018-11-27 19:40:53 +00:00
|
|
|
const { searching } = this.state;
|
|
|
|
const { appStart } = this.props;
|
|
|
|
if (searching) {
|
2020-02-13 19:24:39 +00:00
|
|
|
this.cancelSearch();
|
2018-11-27 19:40:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
appStart({ root: ROOT_BACKGROUND });
|
2018-11-27 19:40:53 +00:00
|
|
|
return false;
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-02-16 18:34:25 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
|
|
|
search = debounce(async(text) => {
|
2018-08-31 18:13:30 +00:00
|
|
|
const result = await RocketChat.search({ text });
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2020-02-13 19:24:39 +00:00
|
|
|
// if the search was cancelled before the promise is resolved
|
2020-06-15 14:00:46 +00:00
|
|
|
const { searching } = this.state;
|
2020-02-13 19:24:39 +00:00
|
|
|
if (!searching) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
this.internalSetState({
|
2020-02-13 19:24:39 +00:00
|
|
|
search: result,
|
|
|
|
searching: true
|
2018-08-31 18:13:30 +00:00
|
|
|
});
|
2020-07-08 16:36:37 +00:00
|
|
|
this.scrollToTop();
|
2019-09-16 20:26:32 +00:00
|
|
|
}, 300);
|
2017-08-10 16:16:32 +00:00
|
|
|
|
2020-01-28 13:22:35 +00:00
|
|
|
getRoomTitle = item => RocketChat.getRoomTitle(item)
|
2019-04-08 12:35:28 +00:00
|
|
|
|
2020-02-12 17:21:11 +00:00
|
|
|
getRoomAvatar = item => RocketChat.getRoomAvatar(item)
|
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
isGroupChat = item => RocketChat.isGroupChat(item)
|
|
|
|
|
|
|
|
isRead = item => RocketChat.isRead(item)
|
|
|
|
|
2020-03-03 21:10:39 +00:00
|
|
|
getUserPresence = uid => RocketChat.getUserPresence(uid)
|
|
|
|
|
2020-04-09 05:20:57 +00:00
|
|
|
getUidDirectMessage = room => RocketChat.getUidDirectMessage(room);
|
2020-04-01 12:28:54 +00:00
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
get isGrouping() {
|
|
|
|
const { showUnread, showFavorites, groupByType } = this.props;
|
|
|
|
return showUnread || showFavorites || groupByType;
|
|
|
|
}
|
|
|
|
|
2020-05-13 19:02:57 +00:00
|
|
|
onPressItem = (item = {}) => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation, isMasterDetail } = this.props;
|
2020-04-30 16:03:07 +00:00
|
|
|
if (!navigation.isFocused()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-13 19:02:57 +00:00
|
|
|
|
|
|
|
this.cancelSearch();
|
2020-06-15 14:00:46 +00:00
|
|
|
this.goRoom({ item, isMasterDetail });
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2020-07-08 16:36:37 +00:00
|
|
|
scrollToTop = () => {
|
|
|
|
if (this.scroll?.scrollToOffset) {
|
|
|
|
this.scroll.scrollToOffset({ offset: 0 });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 18:15:03 +00:00
|
|
|
toggleSort = () => {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.RL_TOGGLE_SORT_DROPDOWN);
|
2018-09-25 19:28:42 +00:00
|
|
|
const { toggleSortDropdown } = this.props;
|
|
|
|
|
2020-07-08 16:36:37 +00:00
|
|
|
this.scrollToTop();
|
2018-09-05 18:15:03 +00:00
|
|
|
setTimeout(() => {
|
2018-09-25 19:28:42 +00:00
|
|
|
toggleSortDropdown();
|
2018-09-05 18:15:03 +00:00
|
|
|
}, 100);
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2019-07-01 14:20:38 +00:00
|
|
|
toggleFav = async(rid, favorite) => {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(favorite ? events.RL_UNFAVORITE_CHANNEL : events.RL_FAVORITE_CHANNEL);
|
2019-07-01 14:20:38 +00:00
|
|
|
try {
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
2019-07-15 16:54:28 +00:00
|
|
|
const result = await RocketChat.toggleFavorite(rid, !favorite);
|
|
|
|
if (result.success) {
|
2019-09-16 20:26:32 +00:00
|
|
|
const subCollection = db.collections.get('subscriptions');
|
|
|
|
await db.action(async() => {
|
|
|
|
try {
|
|
|
|
const subRecord = await subCollection.find(rid);
|
|
|
|
await subRecord.update((sub) => {
|
|
|
|
sub.f = !favorite;
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
2019-07-15 16:54:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-07-01 14:20:38 +00:00
|
|
|
} catch (e) {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.RL_TOGGLE_FAVORITE_FAIL);
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-07-01 14:20:38 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2019-07-01 14:20:38 +00:00
|
|
|
|
|
|
|
toggleRead = async(rid, isRead) => {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(isRead ? events.RL_UNREAD_CHANNEL : events.RL_READ_CHANNEL);
|
2019-07-01 14:20:38 +00:00
|
|
|
try {
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
2019-07-04 16:15:30 +00:00
|
|
|
const result = await RocketChat.toggleRead(isRead, rid);
|
|
|
|
if (result.success) {
|
2019-09-16 20:26:32 +00:00
|
|
|
const subCollection = db.collections.get('subscriptions');
|
|
|
|
await db.action(async() => {
|
|
|
|
try {
|
|
|
|
const subRecord = await subCollection.find(rid);
|
|
|
|
await subRecord.update((sub) => {
|
|
|
|
sub.alert = isRead;
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
2019-07-04 16:15:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-07-01 14:20:38 +00:00
|
|
|
} catch (e) {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.RL_TOGGLE_READ_F);
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-07-01 14:20:38 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2019-07-01 14:20:38 +00:00
|
|
|
|
|
|
|
hideChannel = async(rid, type) => {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.RL_HIDE_CHANNEL);
|
2019-07-01 14:20:38 +00:00
|
|
|
try {
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
2019-07-04 16:15:30 +00:00
|
|
|
const result = await RocketChat.hideRoom(rid, type);
|
|
|
|
if (result.success) {
|
2019-09-16 20:26:32 +00:00
|
|
|
const subCollection = db.collections.get('subscriptions');
|
|
|
|
await db.action(async() => {
|
|
|
|
try {
|
|
|
|
const subRecord = await subCollection.find(rid);
|
|
|
|
await subRecord.destroyPermanently();
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
2019-07-04 16:15:30 +00:00
|
|
|
});
|
|
|
|
}
|
2019-07-01 14:20:38 +00:00
|
|
|
} catch (e) {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.RL_HIDE_CHANNEL_F);
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-07-01 14:20:38 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2019-07-01 14:20:38 +00:00
|
|
|
|
2019-06-10 16:22:35 +00:00
|
|
|
goDirectory = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.RL_GO_DIRECTORY);
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation, isMasterDetail } = this.props;
|
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('ModalStackNavigator', { screen: 'DirectoryView' });
|
|
|
|
} else {
|
|
|
|
navigation.navigate('DirectoryView');
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2019-06-10 16:22:35 +00:00
|
|
|
|
2020-07-31 18:22:30 +00:00
|
|
|
goQueue = () => {
|
|
|
|
logEvent(events.RL_GO_QUEUE);
|
2020-08-21 13:38:50 +00:00
|
|
|
const {
|
|
|
|
navigation, isMasterDetail, queueSize, inquiryEnabled, user
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
// if not-available, prompt to change to available
|
2020-08-28 19:41:08 +00:00
|
|
|
if (!isOmnichannelStatusAvailable(user)) {
|
2020-08-21 13:38:50 +00:00
|
|
|
showConfirmationAlert({
|
|
|
|
message: I18n.t('Omnichannel_enable_alert'),
|
2020-08-25 20:04:18 +00:00
|
|
|
confirmationText: I18n.t('Yes'),
|
2020-08-21 13:38:50 +00:00
|
|
|
onPress: async() => {
|
|
|
|
try {
|
2020-08-28 19:41:08 +00:00
|
|
|
await changeLivechatStatus();
|
2020-08-21 13:38:50 +00:00
|
|
|
} catch {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!inquiryEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-31 18:22:30 +00:00
|
|
|
// prevent navigation to empty list
|
|
|
|
if (!queueSize) {
|
|
|
|
return showErrorAlert(I18n.t('Queue_is_empty'), I18n.t('Oops'));
|
|
|
|
}
|
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('ModalStackNavigator', { screen: 'QueueListView' });
|
|
|
|
} else {
|
|
|
|
navigation.navigate('QueueListView');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
goRoom = ({ item, isMasterDetail }) => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.RL_GO_ROOM);
|
2020-06-15 14:00:46 +00:00
|
|
|
const { item: currentItem } = this.state;
|
|
|
|
const { rooms } = this.props;
|
|
|
|
if (currentItem?.rid === item.rid || rooms?.includes(item.rid)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Only mark room as focused when in master detail layout
|
|
|
|
if (isMasterDetail) {
|
|
|
|
this.setState({ item });
|
|
|
|
}
|
|
|
|
goRoom({ item, isMasterDetail });
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
goRoomByIndex = (index) => {
|
|
|
|
const { chats } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { isMasterDetail } = this.props;
|
2019-11-25 20:01:17 +00:00
|
|
|
const filteredChats = chats.filter(c => !c.separator);
|
|
|
|
const room = filteredChats[index - 1];
|
|
|
|
if (room) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.goRoom({ item: room, isMasterDetail });
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
findOtherRoom = (index, sign) => {
|
|
|
|
const { chats } = this.state;
|
|
|
|
const otherIndex = index + sign;
|
|
|
|
const otherRoom = chats[otherIndex];
|
|
|
|
if (!otherRoom) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (otherRoom.separator) {
|
|
|
|
return this.findOtherRoom(otherIndex, sign);
|
|
|
|
} else {
|
|
|
|
return otherRoom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go to previous or next room based on sign (-1 or 1)
|
|
|
|
// It's used by iPad key commands
|
|
|
|
goOtherRoom = (sign) => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { item } = this.state;
|
|
|
|
if (!item) {
|
2019-11-25 20:01:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
// Don't run during search
|
|
|
|
const { search } = this.state;
|
|
|
|
if (search.length > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { chats } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { isMasterDetail } = this.props;
|
|
|
|
const index = chats.findIndex(c => c.rid === item.rid);
|
2019-11-25 20:01:17 +00:00
|
|
|
const otherRoom = this.findOtherRoom(index, sign);
|
|
|
|
if (otherRoom) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.goRoom({ item: otherRoom, isMasterDetail });
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-30 13:26:17 +00:00
|
|
|
goToNewMessage = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.RL_GO_NEW_MSG);
|
2020-07-30 13:26:17 +00:00
|
|
|
const { navigation, isMasterDetail } = this.props;
|
|
|
|
|
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('ModalStackNavigator', { screen: 'NewMessageView' });
|
|
|
|
} else {
|
|
|
|
navigation.navigate('NewMessageStackNavigator');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-11 14:31:38 +00:00
|
|
|
goEncryption = () => {
|
|
|
|
logEvent(events.RL_GO_E2E_SAVE_PASSWORD);
|
|
|
|
const { navigation, isMasterDetail, encryptionBanner } = this.props;
|
|
|
|
|
|
|
|
const isSavePassword = encryptionBanner === E2E_BANNER_TYPE.SAVE_PASSWORD;
|
|
|
|
if (isMasterDetail) {
|
|
|
|
const screen = isSavePassword ? 'E2ESaveYourPasswordView' : 'E2EEnterYourPasswordView';
|
|
|
|
navigation.navigate('ModalStackNavigator', { screen });
|
|
|
|
} else {
|
|
|
|
const screen = isSavePassword ? 'E2ESaveYourPasswordStackNavigator' : 'E2EEnterYourPasswordStackNavigator';
|
|
|
|
navigation.navigate(screen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
handleCommands = ({ event }) => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation, server, isMasterDetail } = this.props;
|
2019-11-25 20:01:17 +00:00
|
|
|
const { input } = event;
|
|
|
|
if (handleCommandShowPreferences(event)) {
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation.navigate('SettingsView');
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandSearching(event)) {
|
2020-07-06 20:56:28 +00:00
|
|
|
this.initSearching();
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandSelectRoom(event)) {
|
|
|
|
this.goRoomByIndex(input);
|
|
|
|
} else if (handleCommandPreviousRoom(event)) {
|
|
|
|
this.goOtherRoom(-1);
|
|
|
|
} else if (handleCommandNextRoom(event)) {
|
|
|
|
this.goOtherRoom(1);
|
|
|
|
} else if (handleCommandShowNewMessage(event)) {
|
2020-06-15 14:00:46 +00:00
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('ModalStackNavigator', { screen: 'NewMessageView' });
|
|
|
|
} else {
|
|
|
|
navigation.navigate('NewMessageStack');
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandAddNewServer(event)) {
|
2020-03-30 19:20:50 +00:00
|
|
|
navigation.navigate('NewServerView', { previousServer: server });
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-11 20:13:44 +00:00
|
|
|
onRefresh = () => {
|
2020-02-13 19:24:39 +00:00
|
|
|
const { searching } = this.state;
|
2020-02-11 20:13:44 +00:00
|
|
|
const { roomsRequest } = this.props;
|
2020-02-13 19:24:39 +00:00
|
|
|
if (searching) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-11 20:13:44 +00:00
|
|
|
roomsRequest({ allData: true });
|
|
|
|
}
|
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
onEndReached = () => {
|
|
|
|
// Run only when we're not grouping by anything
|
|
|
|
if (!this.isGrouping) {
|
|
|
|
this.getSubscriptions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
getScrollRef = ref => (this.scroll = ref);
|
2018-09-26 13:56:36 +00:00
|
|
|
|
2019-04-17 18:57:46 +00:00
|
|
|
renderListHeader = () => {
|
2020-02-13 19:24:39 +00:00
|
|
|
const { searching } = this.state;
|
2020-08-21 13:38:50 +00:00
|
|
|
const {
|
2020-09-11 14:31:38 +00:00
|
|
|
sortBy, queueSize, inquiryEnabled, encryptionBanner, user
|
2020-08-21 13:38:50 +00:00
|
|
|
} = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
return (
|
2019-04-17 18:57:46 +00:00
|
|
|
<ListHeader
|
2020-02-13 19:24:39 +00:00
|
|
|
searching={searching}
|
2019-04-17 18:57:46 +00:00
|
|
|
sortBy={sortBy}
|
|
|
|
toggleSort={this.toggleSort}
|
2020-09-11 14:31:38 +00:00
|
|
|
goEncryption={this.goEncryption}
|
2020-07-31 18:22:30 +00:00
|
|
|
goQueue={this.goQueue}
|
|
|
|
queueSize={queueSize}
|
|
|
|
inquiryEnabled={inquiryEnabled}
|
2020-09-11 14:31:38 +00:00
|
|
|
encryptionBanner={encryptionBanner}
|
2020-08-21 13:38:50 +00:00
|
|
|
user={user}
|
2019-04-17 18:57:46 +00:00
|
|
|
/>
|
2018-09-25 19:28:42 +00:00
|
|
|
);
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
renderHeader = () => {
|
|
|
|
const { isMasterDetail, theme } = this.props;
|
|
|
|
|
|
|
|
if (!isMasterDetail) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const options = this.getHeader();
|
|
|
|
return (
|
|
|
|
<Header
|
|
|
|
theme={theme}
|
|
|
|
{...options}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-19 21:15:31 +00:00
|
|
|
renderItem = ({ item }) => {
|
2019-11-25 20:01:17 +00:00
|
|
|
if (item.separator) {
|
|
|
|
return this.renderSectionHeader(item.rid);
|
|
|
|
}
|
|
|
|
|
2020-06-17 17:35:58 +00:00
|
|
|
const { item: currentItem } = this.state;
|
2019-03-29 19:36:07 +00:00
|
|
|
const {
|
2020-02-11 14:09:14 +00:00
|
|
|
user: {
|
|
|
|
id: userId,
|
|
|
|
username,
|
|
|
|
token
|
|
|
|
},
|
|
|
|
server,
|
2019-11-25 20:01:17 +00:00
|
|
|
StoreLastMessage,
|
2020-02-21 16:13:05 +00:00
|
|
|
useRealName,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme,
|
2020-06-17 17:35:58 +00:00
|
|
|
isMasterDetail,
|
|
|
|
width
|
2019-03-29 19:36:07 +00:00
|
|
|
} = this.props;
|
2020-04-01 12:28:54 +00:00
|
|
|
const id = this.getUidDirectMessage(item);
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
return (
|
|
|
|
<RoomItem
|
2020-07-20 16:44:54 +00:00
|
|
|
item={item}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-09-16 20:26:32 +00:00
|
|
|
id={id}
|
2020-07-20 16:44:54 +00:00
|
|
|
type={item.t}
|
2019-09-16 20:26:32 +00:00
|
|
|
userId={userId}
|
|
|
|
username={username}
|
|
|
|
token={token}
|
2020-02-11 14:09:14 +00:00
|
|
|
baseUrl={server}
|
2019-09-16 20:26:32 +00:00
|
|
|
showLastMessage={StoreLastMessage}
|
2020-07-20 16:44:54 +00:00
|
|
|
onPress={this.onPressItem}
|
2019-09-16 20:26:32 +00:00
|
|
|
testID={`rooms-list-view-item-${ item.name }`}
|
2020-06-15 14:00:46 +00:00
|
|
|
width={isMasterDetail ? MAX_SIDEBAR_WIDTH : width}
|
2019-09-16 20:26:32 +00:00
|
|
|
toggleFav={this.toggleFav}
|
|
|
|
toggleRead={this.toggleRead}
|
|
|
|
hideChannel={this.hideChannel}
|
2020-02-21 16:13:05 +00:00
|
|
|
useRealName={useRealName}
|
2020-03-03 21:10:39 +00:00
|
|
|
getUserPresence={this.getUserPresence}
|
2020-07-20 16:44:54 +00:00
|
|
|
getRoomTitle={this.getRoomTitle}
|
|
|
|
getRoomAvatar={this.getRoomAvatar}
|
|
|
|
getIsGroupChat={this.isGroupChat}
|
|
|
|
getIsRead={this.isRead}
|
2020-05-08 17:36:10 +00:00
|
|
|
visitor={item.visitor}
|
2020-06-15 14:00:46 +00:00
|
|
|
isFocused={currentItem?.rid === item.rid}
|
2019-09-16 20:26:32 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderSectionHeader = (header) => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return (
|
|
|
|
<View style={[styles.groupTitleContainer, { backgroundColor: themes[theme].backgroundColor }]}>
|
|
|
|
<Text style={[styles.groupTitle, { color: themes[theme].controlText }]}>{I18n.t(header)}</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
renderScroll = () => {
|
2020-02-11 20:13:44 +00:00
|
|
|
const {
|
2020-02-13 19:24:39 +00:00
|
|
|
loading, chats, search, searching
|
2020-02-11 20:13:44 +00:00
|
|
|
} = this.state;
|
|
|
|
const { theme, refreshing } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
|
|
|
if (loading) {
|
2019-12-04 16:39:53 +00:00
|
|
|
return <ActivityIndicator theme={theme} />;
|
2018-08-01 19:35:06 +00:00
|
|
|
}
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2018-08-01 19:35:06 +00:00
|
|
|
return (
|
2019-11-25 20:01:17 +00:00
|
|
|
<FlatList
|
2018-09-26 13:56:36 +00:00
|
|
|
ref={this.getScrollRef}
|
2020-02-13 19:24:39 +00:00
|
|
|
data={searching ? search : chats}
|
|
|
|
extraData={searching ? search : chats}
|
2019-11-25 20:01:17 +00:00
|
|
|
keyExtractor={keyExtractor}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.list, { backgroundColor: themes[theme].backgroundColor }]}
|
2019-11-25 20:01:17 +00:00
|
|
|
renderItem={this.renderItem}
|
|
|
|
ListHeaderComponent={this.renderListHeader}
|
|
|
|
getItemLayout={getItemLayout}
|
|
|
|
removeClippedSubviews={isIOS}
|
2018-08-01 19:35:06 +00:00
|
|
|
keyboardShouldPersistTaps='always'
|
2019-11-25 20:01:17 +00:00
|
|
|
initialNumToRender={INITIAL_NUM_TO_RENDER}
|
2020-02-11 20:13:44 +00:00
|
|
|
refreshControl={(
|
|
|
|
<RefreshControl
|
|
|
|
refreshing={refreshing}
|
|
|
|
onRefresh={this.onRefresh}
|
|
|
|
tintColor={themes[theme].auxiliaryText}
|
|
|
|
/>
|
|
|
|
)}
|
2019-11-25 20:01:17 +00:00
|
|
|
windowSize={9}
|
2020-07-20 16:44:54 +00:00
|
|
|
onEndReached={this.onEndReached}
|
|
|
|
onEndReachedThreshold={0.5}
|
2019-11-25 20:01:17 +00:00
|
|
|
/>
|
2018-08-01 19:35:06 +00:00
|
|
|
);
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
render = () => {
|
2019-04-17 18:57:46 +00:00
|
|
|
console.count(`${ this.constructor.name }.render calls`);
|
2018-08-31 16:46:33 +00:00
|
|
|
const {
|
2019-09-16 20:26:32 +00:00
|
|
|
sortBy,
|
|
|
|
groupByType,
|
|
|
|
showFavorites,
|
|
|
|
showUnread,
|
|
|
|
showServerDropdown,
|
2019-12-04 16:39:53 +00:00
|
|
|
showSortDropdown,
|
2020-06-15 14:00:46 +00:00
|
|
|
theme,
|
|
|
|
navigation
|
2018-08-31 16:46:33 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
2020-10-30 13:59:44 +00:00
|
|
|
<SafeAreaView testID='rooms-list-view' style={{ backgroundColor: themes[theme].backgroundColor }}>
|
|
|
|
<StatusBar />
|
2020-06-15 14:00:46 +00:00
|
|
|
{this.renderHeader()}
|
2018-08-31 16:46:33 +00:00
|
|
|
{this.renderScroll()}
|
2019-09-16 20:26:32 +00:00
|
|
|
{showSortDropdown ? (
|
|
|
|
<SortDropdown
|
|
|
|
close={this.toggleSort}
|
|
|
|
sortBy={sortBy}
|
|
|
|
groupByType={groupByType}
|
|
|
|
showFavorites={showFavorites}
|
|
|
|
showUnread={showUnread}
|
|
|
|
/>
|
|
|
|
) : null}
|
2020-06-15 14:00:46 +00:00
|
|
|
{showServerDropdown ? <ServerDropdown navigation={navigation} /> : null}
|
2018-08-31 16:46:33 +00:00
|
|
|
</SafeAreaView>
|
|
|
|
);
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2017-08-03 18:23:43 +00:00
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2020-02-11 14:09:14 +00:00
|
|
|
user: getUserSelector(state),
|
2020-06-15 14:00:46 +00:00
|
|
|
isMasterDetail: state.app.isMasterDetail,
|
2019-08-07 13:51:34 +00:00
|
|
|
server: state.server.server,
|
2020-04-03 18:03:53 +00:00
|
|
|
connected: state.server.connected,
|
2019-08-07 13:51:34 +00:00
|
|
|
searchText: state.rooms.searchText,
|
|
|
|
loadingServer: state.server.loading,
|
|
|
|
showServerDropdown: state.rooms.showServerDropdown,
|
|
|
|
showSortDropdown: state.rooms.showSortDropdown,
|
2020-02-11 20:13:44 +00:00
|
|
|
refreshing: state.rooms.refreshing,
|
2019-08-07 13:51:34 +00:00
|
|
|
sortBy: state.sortPreferences.sortBy,
|
|
|
|
groupByType: state.sortPreferences.groupByType,
|
|
|
|
showFavorites: state.sortPreferences.showFavorites,
|
|
|
|
showUnread: state.sortPreferences.showUnread,
|
|
|
|
useRealName: state.settings.UI_Use_Real_Name,
|
|
|
|
appState: state.app.ready && state.app.foreground ? 'foreground' : 'background',
|
2020-06-15 14:00:46 +00:00
|
|
|
StoreLastMessage: state.settings.Store_Last_Message,
|
2020-07-31 18:22:30 +00:00
|
|
|
rooms: state.room.rooms,
|
|
|
|
queueSize: getInquiryQueueSelector(state).length,
|
2020-09-11 14:31:38 +00:00
|
|
|
inquiryEnabled: state.inquiry.enabled,
|
|
|
|
encryptionBanner: state.encryption.banner
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
toggleSortDropdown: () => dispatch(toggleSortDropdownAction()),
|
|
|
|
openSearchHeader: () => dispatch(openSearchHeaderAction()),
|
|
|
|
closeSearchHeader: () => dispatch(closeSearchHeaderAction()),
|
2020-06-15 14:00:46 +00:00
|
|
|
appStart: params => dispatch(appStartAction(params)),
|
2020-02-11 20:13:44 +00:00
|
|
|
roomsRequest: params => dispatch(roomsRequestAction(params)),
|
2019-10-28 12:46:50 +00:00
|
|
|
selectServerRequest: server => dispatch(selectServerRequestAction(server)),
|
|
|
|
closeServerDropdown: () => dispatch(closeServerDropdownAction())
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2020-07-06 20:56:28 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withDimensions(withTheme(withSafeAreaInsets(RoomsListView))));
|