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,
|
|
|
|
ActivityIndicator,
|
|
|
|
Text,
|
|
|
|
Keyboard,
|
|
|
|
Dimensions
|
2018-09-25 19:28:42 +00:00
|
|
|
} from 'react-native';
|
2019-01-31 16:08:38 +00:00
|
|
|
import { connect } from 'react-redux';
|
2019-09-16 20:26:32 +00:00
|
|
|
import { isEqual, orderBy } from 'lodash';
|
2019-10-02 12:18:08 +00:00
|
|
|
import { SafeAreaView } from 'react-navigation';
|
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';
|
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';
|
2018-05-18 17:55:08 +00:00
|
|
|
import log 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';
|
2018-11-27 19:40:53 +00:00
|
|
|
import { appStart as appStartAction } from '../../actions';
|
2018-12-21 10:55:35 +00:00
|
|
|
import debounce from '../../utils/debounce';
|
2019-11-25 20:01:17 +00:00
|
|
|
import { isIOS, isAndroid, 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-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-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';
|
|
|
|
import { withSplit } from '../../split';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2018-09-05 18:15:03 +00:00
|
|
|
const SCROLL_OFFSET = 56;
|
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';
|
2018-08-31 16:46:33 +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',
|
|
|
|
'split'
|
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 {
|
2019-03-12 16:23:06 +00:00
|
|
|
static navigationOptions = ({ navigation }) => {
|
|
|
|
const searching = navigation.getParam('searching');
|
2019-09-16 20:26:32 +00:00
|
|
|
const cancelSearchingAndroid = navigation.getParam(
|
|
|
|
'cancelSearchingAndroid'
|
|
|
|
);
|
2019-03-12 16:23:06 +00:00
|
|
|
const onPressItem = navigation.getParam('onPressItem', () => {});
|
2019-09-16 20:26:32 +00:00
|
|
|
const initSearchingAndroid = navigation.getParam(
|
|
|
|
'initSearchingAndroid',
|
|
|
|
() => {}
|
|
|
|
);
|
2019-03-12 16:23:06 +00:00
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
return {
|
2019-09-16 20:26:32 +00:00
|
|
|
headerLeft: searching ? (
|
|
|
|
<CustomHeaderButtons left>
|
|
|
|
<Item
|
|
|
|
title='cancel'
|
|
|
|
iconName='cross'
|
|
|
|
onPress={cancelSearchingAndroid}
|
|
|
|
/>
|
|
|
|
</CustomHeaderButtons>
|
|
|
|
) : (
|
|
|
|
<DrawerButton
|
|
|
|
navigation={navigation}
|
|
|
|
testID='rooms-list-view-sidebar'
|
|
|
|
/>
|
2019-03-12 16:23:06 +00:00
|
|
|
),
|
|
|
|
headerTitle: <RoomsListHeaderView />,
|
2019-09-16 20:26:32 +00:00
|
|
|
headerRight: searching ? null : (
|
|
|
|
<CustomHeaderButtons>
|
|
|
|
{isAndroid ? (
|
|
|
|
<Item
|
|
|
|
title='search'
|
|
|
|
iconName='magnifier'
|
|
|
|
onPress={initSearchingAndroid}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<Item
|
|
|
|
title='new'
|
|
|
|
iconName='edit-rounded'
|
|
|
|
onPress={() => navigation.navigate('NewMessageView', {
|
|
|
|
onPressItem
|
|
|
|
})}
|
|
|
|
testID='rooms-list-view-create-channel'
|
|
|
|
/>
|
|
|
|
</CustomHeaderButtons>
|
2019-03-12 16:23:06 +00:00
|
|
|
)
|
2018-10-23 21:39:48 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2017-08-05 18:16:32 +00:00
|
|
|
static propTypes = {
|
2019-03-12 16:23:06 +00:00
|
|
|
navigation: PropTypes.object,
|
2018-07-10 13:40:32 +00:00
|
|
|
userId: PropTypes.string,
|
2019-07-15 16:54:28 +00:00
|
|
|
username: PropTypes.string,
|
|
|
|
token: PropTypes.string,
|
2018-09-11 16:32:52 +00:00
|
|
|
baseUrl: PropTypes.string,
|
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,
|
2018-10-02 12:33:21 +00:00
|
|
|
useRealName: PropTypes.bool,
|
2019-03-29 19:36:07 +00:00
|
|
|
StoreLastMessage: PropTypes.bool,
|
2019-06-05 13:39:12 +00:00
|
|
|
appState: 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,
|
|
|
|
split: PropTypes.bool
|
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;
|
2019-07-04 16:15:30 +00:00
|
|
|
const { width } = Dimensions.get('window');
|
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,
|
2019-09-16 20:26:32 +00:00
|
|
|
allChats: [],
|
2018-08-31 16:46:33 +00:00
|
|
|
chats: [],
|
2019-07-04 16:15:30 +00:00
|
|
|
width
|
2017-08-10 16:16:32 +00:00
|
|
|
};
|
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() {
|
|
|
|
this.getSubscriptions();
|
2019-11-25 20:01:17 +00:00
|
|
|
const { navigation, closeServerDropdown } = this.props;
|
2019-03-12 16:23:06 +00:00
|
|
|
navigation.setParams({
|
2019-05-20 20:43:50 +00:00
|
|
|
onPressItem: this._onPressItem,
|
|
|
|
initSearchingAndroid: this.initSearchingAndroid,
|
2019-05-21 12:12:15 +00:00
|
|
|
cancelSearchingAndroid: this.cancelSearchingAndroid
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
2019-07-04 16:15:30 +00:00
|
|
|
Dimensions.addEventListener('change', this.onDimensionsChange);
|
2019-11-25 20:01:17 +00:00
|
|
|
Orientation.unlockAllOrientations();
|
|
|
|
this.willFocusListener = navigation.addListener('willFocus', () => {
|
|
|
|
// Check if there were changes while not focused (it's set on sCU)
|
|
|
|
if (this.shouldUpdate) {
|
|
|
|
// animateNextTransition();
|
|
|
|
this.forceUpdate();
|
|
|
|
this.shouldUpdate = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.didFocusListener = navigation.addListener('didFocus', () => {
|
|
|
|
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
|
|
|
|
});
|
|
|
|
this.willBlurListener = navigation.addListener('willBlur', () => {
|
|
|
|
closeServerDropdown();
|
|
|
|
this.backHandler.remove();
|
|
|
|
});
|
2019-04-17 18:57:46 +00:00
|
|
|
console.timeEnd(`${ this.constructor.name } mount`);
|
2018-07-18 20:34:59 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
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) {
|
2019-09-24 18:19:33 +00:00
|
|
|
const { allChats } = 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
|
|
|
|
const chatsNotEqual = !isEqual(nextState.allChats, allChats);
|
|
|
|
|
|
|
|
// If they aren't equal, set to update if focused
|
|
|
|
if (chatsNotEqual) {
|
|
|
|
this.shouldUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Abort if it's not focused
|
2019-09-16 20:26:32 +00:00
|
|
|
if (!nextProps.navigation.isFocused()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
loading,
|
|
|
|
searching,
|
|
|
|
width,
|
|
|
|
search
|
|
|
|
} = this.state;
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextState.loading !== loading) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextState.searching !== searching) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-04 16:15:30 +00:00
|
|
|
if (nextState.width !== width) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
if (!isEqual(nextState.search, search)) {
|
|
|
|
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,
|
2019-09-25 21:32:30 +00:00
|
|
|
roomsRequest
|
2018-09-25 19:28:42 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
if (
|
|
|
|
!(
|
|
|
|
prevProps.sortBy === sortBy
|
|
|
|
&& prevProps.groupByType === groupByType
|
|
|
|
&& prevProps.showFavorites === showFavorites
|
|
|
|
&& prevProps.showUnread === showUnread
|
|
|
|
)
|
|
|
|
) {
|
2019-11-25 20:01:17 +00:00
|
|
|
this.getSubscriptions(true);
|
2019-09-16 20:26:32 +00:00
|
|
|
} else if (
|
|
|
|
appState === 'foreground'
|
|
|
|
&& appState !== prevProps.appState
|
|
|
|
) {
|
2019-06-05 13:39:12 +00:00
|
|
|
roomsRequest();
|
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() {
|
2019-09-16 20:26:32 +00:00
|
|
|
if (this.querySubscription && this.querySubscription.unsubscribe) {
|
|
|
|
this.querySubscription.unsubscribe();
|
2019-04-17 18:57:46 +00:00
|
|
|
}
|
2019-09-24 18:19:33 +00:00
|
|
|
if (this.willFocusListener && this.willFocusListener.remove) {
|
|
|
|
this.willFocusListener.remove();
|
|
|
|
}
|
2019-05-03 14:54:57 +00:00
|
|
|
if (this.didFocusListener && this.didFocusListener.remove) {
|
|
|
|
this.didFocusListener.remove();
|
|
|
|
}
|
|
|
|
if (this.willBlurListener && this.willBlurListener.remove) {
|
|
|
|
this.willBlurListener.remove();
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.removeListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
2019-07-04 16:15:30 +00:00
|
|
|
Dimensions.removeEventListener('change', this.onDimensionsChange);
|
2019-04-17 18:57:46 +00:00
|
|
|
console.countReset(`${ this.constructor.name }.render calls`);
|
2017-08-12 20:52:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
onDimensionsChange = ({ window: { width } }) => this.setState({ width });
|
2019-07-04 16:15:30 +00:00
|
|
|
|
2019-04-17 18:57:46 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
2018-10-23 21:39:48 +00:00
|
|
|
internalSetState = (...args) => {
|
2019-03-27 20:06:57 +00:00
|
|
|
const { navigation } = this.props;
|
2019-09-19 13:32:24 +00:00
|
|
|
if (navigation.isFocused()) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
getSubscriptions = async(force = false) => {
|
|
|
|
if (this.gotSubscriptions && !force) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.gotSubscriptions = true;
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
if (this.querySubscription && this.querySubscription.unsubscribe) {
|
|
|
|
this.querySubscription.unsubscribe();
|
2019-04-17 18:57:46 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
this.setState({ loading: true });
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
const {
|
2019-09-16 20:26:32 +00:00
|
|
|
sortBy,
|
|
|
|
showUnread,
|
|
|
|
showFavorites,
|
|
|
|
groupByType
|
2018-09-25 19:28:42 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
|
|
|
const observable = await db.collections
|
|
|
|
.get('subscriptions')
|
|
|
|
.query(
|
|
|
|
Q.where('archived', false),
|
|
|
|
Q.where('open', true),
|
|
|
|
Q.where('t', Q.notEq('l'))
|
|
|
|
)
|
|
|
|
.observeWithColumns(['room_updated_at', 'unread', 'alert', 'user_mentions', 'f', 't']);
|
|
|
|
|
|
|
|
this.querySubscription = observable.subscribe((data) => {
|
2019-11-25 20:01:17 +00:00
|
|
|
let tempChats = [];
|
2019-09-16 20:26:32 +00:00
|
|
|
let chats = [];
|
2018-09-25 19:28:42 +00:00
|
|
|
if (sortBy === 'alphabetical') {
|
2019-09-16 20:26:32 +00:00
|
|
|
chats = orderBy(data, ['name'], ['asc']);
|
2018-08-31 16:46:33 +00:00
|
|
|
} else {
|
2019-09-16 20:26:32 +00:00
|
|
|
chats = orderBy(data, ['roomUpdatedAt'], ['desc']);
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
// it's better to map and test all subs altogether then testing them individually
|
|
|
|
const allChats = data.map(item => ({
|
|
|
|
alert: item.alert,
|
|
|
|
unread: item.unread,
|
|
|
|
userMentions: item.userMentions,
|
|
|
|
isRead: this.getIsRead(item),
|
|
|
|
favorite: item.f,
|
|
|
|
lastMessage: item.lastMessage,
|
|
|
|
name: this.getRoomTitle(item),
|
|
|
|
_updatedAt: item.roomUpdatedAt,
|
|
|
|
key: item._id,
|
|
|
|
rid: item.rid,
|
|
|
|
type: item.t,
|
|
|
|
prid: item.prid
|
|
|
|
}));
|
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
// unread
|
2018-09-25 19:28:42 +00:00
|
|
|
if (showUnread) {
|
2019-11-25 20:01:17 +00:00
|
|
|
const unread = chats.filter(s => (s.unread > 0 || s.alert) && !s.hideUnreadStatus);
|
|
|
|
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-11-25 20:01:17 +00:00
|
|
|
const favorites = chats.filter(s => s.f);
|
|
|
|
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);
|
|
|
|
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);
|
2019-04-17 18:57:46 +00:00
|
|
|
} else if (showUnread) {
|
2019-10-28 20:04:44 +00:00
|
|
|
chats = chats.filter(s => (!s.unread && !s.alert) || s.hideUnreadStatus);
|
2019-11-25 20:01:17 +00:00
|
|
|
tempChats = this.addRoomsGroup(chats, CHATS_HEADER, tempChats);
|
|
|
|
} else if (showFavorites) {
|
|
|
|
chats = chats.filter(s => !s.f);
|
|
|
|
tempChats = this.addRoomsGroup(chats, CHATS_HEADER, tempChats);
|
|
|
|
} else {
|
|
|
|
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,
|
2019-09-16 20:26:32 +00:00
|
|
|
allChats,
|
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
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
initSearchingAndroid = () => {
|
2019-03-12 16:23:06 +00:00
|
|
|
const { openSearchHeader, navigation } = this.props;
|
2018-11-27 19:40:53 +00:00
|
|
|
this.setState({ searching: true });
|
2019-03-12 16:23:06 +00:00
|
|
|
navigation.setParams({ searching: true });
|
2018-10-23 21:39:48 +00:00
|
|
|
openSearchHeader();
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-07-10 13:40:32 +00:00
|
|
|
|
|
|
|
cancelSearchingAndroid = () => {
|
2019-01-29 19:52:56 +00:00
|
|
|
if (isAndroid) {
|
2019-03-12 16:23:06 +00:00
|
|
|
const { closeSearchHeader, navigation } = this.props;
|
2018-11-27 19:40:53 +00:00
|
|
|
this.setState({ searching: false });
|
2019-03-12 16:23:06 +00:00
|
|
|
navigation.setParams({ searching: false });
|
2018-10-23 21:39:48 +00:00
|
|
|
closeSearchHeader();
|
|
|
|
this.internalSetState({ search: [] });
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
Keyboard.dismiss();
|
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) {
|
|
|
|
this.cancelSearchingAndroid();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
appStart('background');
|
|
|
|
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 });
|
2018-10-23 21:39:48 +00:00
|
|
|
this.internalSetState({
|
2018-08-31 18:13:30 +00:00
|
|
|
search: result
|
|
|
|
});
|
2019-09-16 20:26:32 +00:00
|
|
|
}, 300);
|
2017-08-10 16:16:32 +00:00
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
getRoomTitle = (item) => {
|
|
|
|
const { useRealName } = this.props;
|
|
|
|
return ((item.prid || useRealName) && item.fname) || item.name;
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2019-04-08 12:35:28 +00:00
|
|
|
|
|
|
|
goRoom = (item) => {
|
2018-11-05 19:02:54 +00:00
|
|
|
this.cancelSearchingAndroid();
|
2019-03-12 16:23:06 +00:00
|
|
|
const { navigation } = this.props;
|
2019-11-25 20:01:17 +00:00
|
|
|
this.item = item;
|
2019-04-08 12:35:28 +00:00
|
|
|
navigation.navigate('RoomView', {
|
2019-09-16 20:26:32 +00:00
|
|
|
rid: item.rid,
|
|
|
|
name: this.getRoomTitle(item),
|
|
|
|
t: item.t,
|
|
|
|
prid: item.prid,
|
|
|
|
room: item
|
2019-04-08 12:35:28 +00:00
|
|
|
});
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-05-24 20:17:00 +00:00
|
|
|
|
2018-03-02 21:31:44 +00:00
|
|
|
_onPressItem = async(item = {}) => {
|
|
|
|
if (!item.search) {
|
2019-04-08 12:35:28 +00:00
|
|
|
return this.goRoom(item);
|
2017-08-10 16:16:32 +00:00
|
|
|
}
|
2018-03-02 21:31:44 +00:00
|
|
|
if (item.t === 'd') {
|
2018-05-07 20:43:26 +00:00
|
|
|
// if user is using the search we need first to join/create room
|
|
|
|
try {
|
2018-05-24 20:17:00 +00:00
|
|
|
const { username } = item;
|
2018-12-05 20:52:08 +00:00
|
|
|
const result = await RocketChat.createDirectMessage(username);
|
|
|
|
if (result.success) {
|
2019-09-16 20:26:32 +00:00
|
|
|
return this.goRoom({
|
|
|
|
rid: result.room._id,
|
|
|
|
name: username,
|
|
|
|
t: 'd'
|
|
|
|
});
|
2018-12-05 20:52:08 +00:00
|
|
|
}
|
2018-05-18 17:55:08 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2018-05-07 20:43:26 +00:00
|
|
|
}
|
2018-05-24 20:17:00 +00:00
|
|
|
} else {
|
2019-04-08 12:35:28 +00:00
|
|
|
return this.goRoom(item);
|
2018-03-02 21:31:44 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2018-09-05 18:15:03 +00:00
|
|
|
toggleSort = () => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { toggleSortDropdown } = this.props;
|
|
|
|
|
2019-01-29 19:52:56 +00:00
|
|
|
const offset = isAndroid ? 0 : SCROLL_OFFSET;
|
2018-12-21 10:55:35 +00:00
|
|
|
if (this.scroll.scrollTo) {
|
|
|
|
this.scroll.scrollTo({ x: 0, y: offset, animated: true });
|
|
|
|
} else if (this.scroll.scrollToOffset) {
|
|
|
|
this.scroll.scrollToOffset({ offset });
|
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) => {
|
|
|
|
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) {
|
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) => {
|
|
|
|
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) {
|
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) => {
|
|
|
|
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) {
|
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 = () => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate('DirectoryView');
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2019-06-10 16:22:35 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
goRoomByIndex = (index) => {
|
|
|
|
const { chats } = this.state;
|
|
|
|
const filteredChats = chats.filter(c => !c.separator);
|
|
|
|
const room = filteredChats[index - 1];
|
|
|
|
if (room) {
|
|
|
|
this.goRoom(room);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) => {
|
|
|
|
if (!this.item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Don't run during search
|
|
|
|
const { search } = this.state;
|
|
|
|
if (search.length > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { chats } = this.state;
|
|
|
|
const index = chats.findIndex(c => c.rid === this.item.rid);
|
|
|
|
const otherRoom = this.findOtherRoom(index, sign);
|
|
|
|
if (otherRoom) {
|
|
|
|
this.goRoom(otherRoom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCommands = ({ event }) => {
|
|
|
|
const { navigation, server } = this.props;
|
|
|
|
const { input } = event;
|
|
|
|
if (handleCommandShowPreferences(event)) {
|
|
|
|
navigation.toggleDrawer();
|
|
|
|
} else if (handleCommandSearching(event)) {
|
|
|
|
this.scroll.scrollToOffset({ animated: true, offset: 0 });
|
|
|
|
this.inputRef.focus();
|
|
|
|
} 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)) {
|
|
|
|
navigation.navigate('NewMessageView', { onPressItem: this._onPressItem });
|
|
|
|
} else if (handleCommandAddNewServer(event)) {
|
|
|
|
navigation.navigate('OnboardingView', { previousServer: server });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 = () => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { search } = this.state;
|
|
|
|
const { sortBy } = this.props;
|
|
|
|
return (
|
2019-04-17 18:57:46 +00:00
|
|
|
<ListHeader
|
2019-11-25 20:01:17 +00:00
|
|
|
inputRef={(ref) => { this.inputRef = ref; }}
|
2019-04-17 18:57:46 +00:00
|
|
|
searchLength={search.length}
|
|
|
|
sortBy={sortBy}
|
|
|
|
onChangeSearchText={this.search}
|
|
|
|
toggleSort={this.toggleSort}
|
2019-06-10 16:22:35 +00:00
|
|
|
goDirectory={this.goDirectory}
|
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
|
|
|
|
2019-07-01 14:20:38 +00:00
|
|
|
getIsRead = (item) => {
|
2019-09-16 20:26:32 +00:00
|
|
|
let isUnread = item.archived !== true && item.open === true; // item is not archived and not opened
|
2019-07-01 14:20:38 +00:00
|
|
|
isUnread = isUnread && (item.unread > 0 || item.alert === true); // either its unread count > 0 or its alert
|
|
|
|
return !isUnread;
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2019-07-01 14:20:38 +00:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-07-04 16:15:30 +00:00
|
|
|
const { width } = this.state;
|
2019-03-29 19:36:07 +00:00
|
|
|
const {
|
2019-09-16 20:26:32 +00:00
|
|
|
userId,
|
|
|
|
username,
|
|
|
|
token,
|
|
|
|
baseUrl,
|
2019-11-25 20:01:17 +00:00
|
|
|
StoreLastMessage,
|
|
|
|
split
|
2019-03-29 19:36:07 +00:00
|
|
|
} = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
const id = item.rid.replace(userId, '').trim();
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
return (
|
|
|
|
<RoomItem
|
|
|
|
alert={item.alert}
|
|
|
|
unread={item.unread}
|
2019-10-28 20:04:44 +00:00
|
|
|
hideUnreadStatus={item.hideUnreadStatus}
|
2019-09-16 20:26:32 +00:00
|
|
|
userMentions={item.userMentions}
|
|
|
|
isRead={this.getIsRead(item)}
|
|
|
|
favorite={item.f}
|
2019-09-26 18:35:33 +00:00
|
|
|
avatar={item.name}
|
2019-09-16 20:26:32 +00:00
|
|
|
lastMessage={item.lastMessage}
|
|
|
|
name={this.getRoomTitle(item)}
|
|
|
|
_updatedAt={item.roomUpdatedAt}
|
|
|
|
key={item._id}
|
|
|
|
id={id}
|
|
|
|
userId={userId}
|
|
|
|
username={username}
|
|
|
|
token={token}
|
|
|
|
rid={item.rid}
|
|
|
|
type={item.t}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
prid={item.prid}
|
|
|
|
showLastMessage={StoreLastMessage}
|
|
|
|
onPress={() => this._onPressItem(item)}
|
|
|
|
testID={`rooms-list-view-item-${ item.name }`}
|
2019-11-25 20:01:17 +00:00
|
|
|
width={split ? MAX_SIDEBAR_WIDTH : width}
|
2019-09-16 20:26:32 +00:00
|
|
|
toggleFav={this.toggleFav}
|
|
|
|
toggleRead={this.toggleRead}
|
|
|
|
hideChannel={this.hideChannel}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
renderSectionHeader = header => (
|
|
|
|
<View style={styles.groupTitleContainer}>
|
|
|
|
<Text style={styles.groupTitle}>{I18n.t(header)}</Text>
|
|
|
|
</View>
|
2019-09-16 20:26:32 +00:00
|
|
|
);
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
renderScroll = () => {
|
2019-11-25 20:01:17 +00:00
|
|
|
const { loading, chats, search } = this.state;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
|
|
|
if (loading) {
|
2018-08-01 19:35:06 +00:00
|
|
|
return <ActivityIndicator style={styles.loading} />;
|
|
|
|
}
|
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}
|
2019-11-25 20:01:17 +00:00
|
|
|
data={search.length ? search : chats}
|
|
|
|
extraData={search.length ? search : chats}
|
2019-01-29 19:52:56 +00:00
|
|
|
contentOffset={isIOS ? { x: 0, y: SCROLL_OFFSET } : {}}
|
2019-11-25 20:01:17 +00:00
|
|
|
keyExtractor={keyExtractor}
|
|
|
|
style={styles.list}
|
|
|
|
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}
|
|
|
|
windowSize={9}
|
|
|
|
/>
|
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,
|
|
|
|
showSortDropdown
|
2018-08-31 16:46:33 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
2019-09-16 20:26:32 +00:00
|
|
|
<SafeAreaView
|
|
|
|
style={styles.container}
|
|
|
|
testID='rooms-list-view'
|
|
|
|
forceInset={{ vertical: 'never' }}
|
|
|
|
>
|
2019-03-12 16:23:06 +00:00
|
|
|
<StatusBar />
|
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}
|
2019-04-17 18:57:46 +00:00
|
|
|
{showServerDropdown ? <ServerDropdown /> : 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 => ({
|
|
|
|
userId: state.login.user && state.login.user.id,
|
|
|
|
username: state.login.user && state.login.user.username,
|
|
|
|
token: state.login.user && state.login.user.token,
|
|
|
|
server: state.server.server,
|
|
|
|
baseUrl: state.settings.baseUrl || state.server ? state.server.server : '',
|
|
|
|
searchText: state.rooms.searchText,
|
|
|
|
loadingServer: state.server.loading,
|
|
|
|
showServerDropdown: state.rooms.showServerDropdown,
|
|
|
|
showSortDropdown: state.rooms.showSortDropdown,
|
|
|
|
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',
|
|
|
|
StoreLastMessage: state.settings.Store_Last_Message
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
toggleSortDropdown: () => dispatch(toggleSortDropdownAction()),
|
|
|
|
openSearchHeader: () => dispatch(openSearchHeaderAction()),
|
|
|
|
closeSearchHeader: () => dispatch(closeSearchHeaderAction()),
|
|
|
|
appStart: () => dispatch(appStartAction()),
|
|
|
|
roomsRequest: () => dispatch(roomsRequestAction()),
|
2019-10-28 12:46:50 +00:00
|
|
|
selectServerRequest: server => dispatch(selectServerRequestAction(server)),
|
|
|
|
closeServerDropdown: () => dispatch(closeServerDropdownAction())
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withSplit(RoomsListView));
|