2019-07-18 17:44:02 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import {
|
2020-06-26 20:22:56 +00:00
|
|
|
View, Text, FlatList, Keyboard, BackHandler, PermissionsAndroid, ScrollView
|
2019-07-18 17:44:02 +00:00
|
|
|
} from 'react-native';
|
|
|
|
import ShareExtension from 'rn-extensions-share';
|
2020-06-26 20:22:56 +00:00
|
|
|
import * as FileSystem from 'expo-file-system';
|
2019-07-18 17:44:02 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import * as mime from 'react-native-mime-types';
|
2020-07-20 16:44:54 +00:00
|
|
|
import isEqual from 'react-fast-compare';
|
2019-09-16 20:26:32 +00:00
|
|
|
import { Q } from '@nozbe/watermelondb';
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
import database from '../../lib/database';
|
2020-06-26 20:22:56 +00:00
|
|
|
import { isIOS, isAndroid } from '../../utils/deviceInfo';
|
2019-07-18 17:44:02 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import DirectoryItem, { ROW_HEIGHT } from '../../presentation/DirectoryItem';
|
2019-07-29 16:33:28 +00:00
|
|
|
import ServerItem from '../../presentation/ServerItem';
|
2020-03-30 20:19:01 +00:00
|
|
|
import { CancelModalButton, CustomHeaderButtons, Item } from '../../containers/HeaderButton';
|
2019-07-18 17:44:02 +00:00
|
|
|
import ShareListHeader from './Header';
|
2019-12-04 16:39:53 +00:00
|
|
|
import ActivityIndicator from '../../containers/ActivityIndicator';
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
import styles from './styles';
|
2019-07-29 16:33:28 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
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';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2020-06-26 20:22:56 +00:00
|
|
|
import RocketChat from '../../lib/rocketchat';
|
|
|
|
|
|
|
|
const permission = {
|
|
|
|
title: I18n.t('Read_External_Permission'),
|
|
|
|
message: I18n.t('Read_External_Permission_Message')
|
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
const getItemLayout = (data, index) => ({ length: ROW_HEIGHT, offset: ROW_HEIGHT * index, index });
|
2019-07-18 17:44:02 +00:00
|
|
|
const keyExtractor = item => item.rid;
|
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class ShareListView extends React.Component {
|
2019-07-18 17:44:02 +00:00
|
|
|
static propTypes = {
|
|
|
|
navigation: PropTypes.object,
|
|
|
|
server: PropTypes.string,
|
|
|
|
token: PropTypes.string,
|
2019-12-04 16:39:53 +00:00
|
|
|
userId: PropTypes.string,
|
|
|
|
theme: PropTypes.string
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-07-20 16:44:54 +00:00
|
|
|
this.chats = [];
|
2019-07-18 17:44:02 +00:00
|
|
|
this.state = {
|
|
|
|
searching: false,
|
2019-07-29 16:33:28 +00:00
|
|
|
searchText: '',
|
|
|
|
searchResults: [],
|
2019-07-18 17:44:02 +00:00
|
|
|
chats: [],
|
2019-07-29 16:33:28 +00:00
|
|
|
servers: [],
|
2020-06-26 20:22:56 +00:00
|
|
|
attachments: [],
|
|
|
|
text: '',
|
2019-07-29 16:33:28 +00:00
|
|
|
loading: true,
|
2020-06-26 20:22:56 +00:00
|
|
|
serverInfo: null,
|
|
|
|
needsPermission: isAndroid || false
|
2019-07-18 17:44:02 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
|
|
|
this.unsubscribeFocus = props.navigation.addListener('focus', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress));
|
2020-06-26 20:22:56 +00:00
|
|
|
this.unsubscribeBlur = props.navigation.addListener('blur', () => BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress));
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 20:22:56 +00:00
|
|
|
async componentDidMount() {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { server } = this.props;
|
2020-06-26 20:22:56 +00:00
|
|
|
try {
|
|
|
|
const data = await ShareExtension.data();
|
|
|
|
if (isAndroid) {
|
|
|
|
await this.askForPermission(data);
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
2020-06-26 20:22:56 +00:00
|
|
|
const info = await Promise.all(data.filter(item => item.type === 'media').map(file => FileSystem.getInfoAsync(this.uriToPath(file.value), { size: true })));
|
|
|
|
const attachments = info.map(file => ({
|
|
|
|
filename: file.uri.substring(file.uri.lastIndexOf('/') + 1),
|
|
|
|
description: '',
|
|
|
|
size: file.size,
|
|
|
|
mime: mime.lookup(file.uri),
|
|
|
|
path: file.uri
|
|
|
|
}));
|
|
|
|
const text = data.filter(item => item.type === 'text').reduce((acc, item) => `${ item.value }\n${ acc }`, '');
|
|
|
|
this.setState({
|
|
|
|
text,
|
|
|
|
attachments
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2019-07-29 16:33:28 +00:00
|
|
|
|
2020-06-26 20:22:56 +00:00
|
|
|
this.getSubscriptions(server);
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 16:37:49 +00:00
|
|
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
2019-07-29 16:33:28 +00:00
|
|
|
const { server } = this.props;
|
|
|
|
if (nextProps.server !== server) {
|
|
|
|
this.getSubscriptions(nextProps.server);
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
2020-06-26 20:22:56 +00:00
|
|
|
const { searching, needsPermission } = this.state;
|
2019-07-29 16:33:28 +00:00
|
|
|
if (nextState.searching !== searching) {
|
2019-07-18 17:44:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-06-26 20:22:56 +00:00
|
|
|
if (nextState.needsPermission !== needsPermission) {
|
2019-07-29 16:33:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
const { server, theme } = this.props;
|
2019-07-29 16:33:28 +00:00
|
|
|
if (server !== nextProps.server) {
|
2019-07-18 17:44:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-12-04 16:39:53 +00:00
|
|
|
if (theme !== nextProps.theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
const { searchResults } = this.state;
|
|
|
|
if (!isEqual(nextState.searchResults, searchResults)) {
|
2019-07-18 17:44:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.unsubscribeFocus) {
|
|
|
|
this.unsubscribeFocus();
|
|
|
|
}
|
|
|
|
if (this.unsubscribeBlur) {
|
|
|
|
this.unsubscribeBlur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setHeader = () => {
|
|
|
|
const { searching } = this.state;
|
|
|
|
const { navigation, theme } = this.props;
|
|
|
|
|
|
|
|
if (isIOS) {
|
|
|
|
navigation.setOptions({
|
|
|
|
header: () => (
|
|
|
|
<ShareListHeader
|
|
|
|
searching={searching}
|
|
|
|
initSearch={this.initSearch}
|
|
|
|
cancelSearch={this.cancelSearch}
|
|
|
|
search={this.search}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
navigation.setOptions({
|
|
|
|
headerLeft: () => (searching
|
|
|
|
? (
|
|
|
|
<CustomHeaderButtons left>
|
2020-07-27 19:53:33 +00:00
|
|
|
<Item title='cancel' iconName='close' onPress={this.cancelSearch} />
|
2020-06-15 14:00:46 +00:00
|
|
|
</CustomHeaderButtons>
|
|
|
|
)
|
|
|
|
: (
|
|
|
|
<CancelModalButton
|
|
|
|
onPress={ShareExtension.close}
|
|
|
|
testID='share-extension-close'
|
|
|
|
/>
|
|
|
|
)),
|
|
|
|
headerTitle: () => <ShareListHeader searching={searching} search={this.search} theme={theme} />,
|
|
|
|
headerRight: () => (
|
|
|
|
searching
|
|
|
|
? null
|
|
|
|
: (
|
|
|
|
<CustomHeaderButtons>
|
2020-08-21 18:11:10 +00:00
|
|
|
<Item title='search' iconName='search' onPress={this.initSearch} />
|
2020-06-15 14:00:46 +00:00
|
|
|
</CustomHeaderButtons>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:44:02 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
|
|
|
internalSetState = (...args) => {
|
|
|
|
const { navigation } = this.props;
|
2019-09-19 13:32:24 +00:00
|
|
|
if (navigation.isFocused()) {
|
|
|
|
animateNextTransition();
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
this.setState(...args);
|
|
|
|
}
|
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
query = (text) => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
2020-07-20 16:44:54 +00:00
|
|
|
const defaultWhereClause = [
|
|
|
|
Q.where('archived', false),
|
|
|
|
Q.where('open', true),
|
|
|
|
Q.experimentalSkip(0),
|
|
|
|
Q.experimentalTake(50),
|
|
|
|
Q.experimentalSortBy('room_updated_at', Q.desc)
|
|
|
|
];
|
|
|
|
if (text) {
|
|
|
|
return db.collections
|
2019-09-16 20:26:32 +00:00
|
|
|
.get('subscriptions')
|
|
|
|
.query(
|
2020-07-20 16:44:54 +00:00
|
|
|
...defaultWhereClause,
|
|
|
|
Q.or(
|
|
|
|
Q.where('name', Q.like(`%${ Q.sanitizeLikeString(text) }%`)),
|
|
|
|
Q.where('fname', Q.like(`%${ Q.sanitizeLikeString(text) }%`))
|
|
|
|
)
|
2019-09-16 20:26:32 +00:00
|
|
|
).fetch();
|
2020-07-20 16:44:54 +00:00
|
|
|
}
|
|
|
|
return db.collections.get('subscriptions').query(...defaultWhereClause).fetch();
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
getSubscriptions = async(server) => {
|
|
|
|
const serversDB = database.servers;
|
|
|
|
|
|
|
|
if (server) {
|
|
|
|
this.chats = await this.query();
|
2019-09-16 20:26:32 +00:00
|
|
|
const serversCollection = serversDB.collections.get('servers');
|
|
|
|
this.servers = await serversCollection.query().fetch();
|
2019-10-08 12:36:15 +00:00
|
|
|
let serverInfo = {};
|
|
|
|
try {
|
|
|
|
serverInfo = await serversCollection.find(server);
|
|
|
|
} catch (error) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:44:02 +00:00
|
|
|
this.internalSetState({
|
2020-07-20 16:44:54 +00:00
|
|
|
chats: this.chats ?? [],
|
|
|
|
servers: this.servers ?? [],
|
2019-07-29 16:33:28 +00:00
|
|
|
loading: false,
|
|
|
|
serverInfo
|
2019-07-18 17:44:02 +00:00
|
|
|
});
|
|
|
|
this.forceUpdate();
|
2019-07-29 16:33:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-26 20:22:56 +00:00
|
|
|
askForPermission = async(data) => {
|
|
|
|
const mediaIndex = data.findIndex(item => item.type === 'media');
|
|
|
|
if (mediaIndex !== -1) {
|
|
|
|
const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE, permission);
|
|
|
|
if (result !== PermissionsAndroid.RESULTS.GRANTED) {
|
|
|
|
this.setState({ needsPermission: true });
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.setState({ needsPermission: false });
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
uriToPath = uri => decodeURIComponent(isIOS ? uri.replace(/^file:\/\//, '') : uri);
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
getRoomTitle = (item) => {
|
2019-07-29 16:33:28 +00:00
|
|
|
const { serverInfo } = this.state;
|
|
|
|
const { useRealName } = serverInfo;
|
2019-07-18 17:44:02 +00:00
|
|
|
return ((item.prid || useRealName) && item.fname) || item.name;
|
|
|
|
}
|
|
|
|
|
2020-06-26 20:22:56 +00:00
|
|
|
shareMessage = (room) => {
|
|
|
|
const { attachments, text, serverInfo } = this.state;
|
2019-07-18 17:44:02 +00:00
|
|
|
const { navigation } = this.props;
|
|
|
|
|
|
|
|
navigation.navigate('ShareView', {
|
2020-06-26 20:22:56 +00:00
|
|
|
room,
|
|
|
|
text,
|
|
|
|
attachments,
|
|
|
|
serverInfo,
|
|
|
|
isShareExtension: true
|
2019-07-18 17:44:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
search = async(text) => {
|
|
|
|
const result = await this.query(text);
|
2019-07-18 17:44:02 +00:00
|
|
|
this.internalSetState({
|
2020-07-20 16:44:54 +00:00
|
|
|
searchResults: result,
|
2019-07-29 16:33:28 +00:00
|
|
|
searchText: text
|
2019-07-18 17:44:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
initSearch = () => {
|
|
|
|
const { chats } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setState({ searching: true, searchResults: chats }, () => this.setHeader());
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
cancelSearch = () => {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.internalSetState({ searching: false, searchResults: [], searchText: '' }, () => this.setHeader());
|
2019-07-29 16:33:28 +00:00
|
|
|
Keyboard.dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleBackPress = () => {
|
|
|
|
const { searching } = this.state;
|
|
|
|
if (searching) {
|
|
|
|
this.cancelSearch();
|
|
|
|
return true;
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
2019-07-29 16:33:28 +00:00
|
|
|
return false;
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderSectionHeader = (header) => {
|
|
|
|
const { searching } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2019-07-29 16:33:28 +00:00
|
|
|
if (searching) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
return (
|
2019-12-04 16:39:53 +00:00
|
|
|
<View style={[styles.headerContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
|
|
|
<Text style={[styles.headerText, { color: themes[theme].titleText }]}>
|
2019-07-29 16:33:28 +00:00
|
|
|
{I18n.t(header)}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
renderItem = ({ item }) => {
|
2020-07-20 16:44:54 +00:00
|
|
|
const { serverInfo } = this.state;
|
|
|
|
const { useRealName } = serverInfo;
|
2019-12-04 16:39:53 +00:00
|
|
|
const {
|
2020-02-11 14:09:14 +00:00
|
|
|
userId, token, server, theme
|
2019-12-04 16:39:53 +00:00
|
|
|
} = this.props;
|
2020-07-20 16:44:54 +00:00
|
|
|
let description;
|
|
|
|
switch (item.t) {
|
|
|
|
case 'c':
|
|
|
|
description = item.topic || item.description;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
description = item.topic || item.description;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
description = useRealName ? item.name : item.fname;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
description = item.fname;
|
|
|
|
break;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
|
|
|
<DirectoryItem
|
|
|
|
user={{
|
2019-10-29 18:14:41 +00:00
|
|
|
id: userId,
|
2019-07-18 17:44:02 +00:00
|
|
|
token
|
|
|
|
}}
|
|
|
|
title={this.getRoomTitle(item)}
|
2020-02-11 14:09:14 +00:00
|
|
|
baseUrl={server}
|
2020-06-26 20:22:56 +00:00
|
|
|
avatar={RocketChat.getRoomAvatar(item)}
|
2020-07-20 16:44:54 +00:00
|
|
|
description={description}
|
2020-06-26 20:22:56 +00:00
|
|
|
type={item.prid ? 'discussion' : item.t}
|
2019-07-18 17:44:02 +00:00
|
|
|
onPress={() => this.shareMessage(item)}
|
|
|
|
testID={`share-extension-item-${ item.name }`}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-07-18 17:44:02 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderSeparator = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return <View style={[styles.separator, { borderColor: themes[theme].separatorColor }]} />;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderBorderBottom = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return <View style={[styles.borderBottom, { borderColor: themes[theme].separatorColor }]} />;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderSelectServer = () => {
|
2019-07-18 17:44:02 +00:00
|
|
|
const { servers } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { server, theme, navigation } = this.props;
|
2019-07-18 17:44:02 +00:00
|
|
|
const currentServer = servers.find(serverFiltered => serverFiltered.id === server);
|
|
|
|
return currentServer ? (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-07-18 17:44:02 +00:00
|
|
|
{this.renderSectionHeader('Select_Server')}
|
2019-12-04 16:39:53 +00:00
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.bordered,
|
|
|
|
{
|
|
|
|
borderColor: themes[theme].separatorColor,
|
|
|
|
backgroundColor: themes[theme].auxiliaryBackground
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
>
|
2019-07-18 17:44:02 +00:00
|
|
|
<ServerItem
|
|
|
|
server={server}
|
2020-06-15 14:00:46 +00:00
|
|
|
onPress={() => navigation.navigate('SelectServerView', { servers: this.servers })}
|
2019-07-18 17:44:02 +00:00
|
|
|
item={currentServer}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-07-18 17:44:02 +00:00
|
|
|
/>
|
|
|
|
</View>
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-07-18 17:44:02 +00:00
|
|
|
) : null;
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderEmptyComponent = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return (
|
|
|
|
<View style={[styles.container, styles.emptyContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
|
|
|
<Text style={[styles.title, { color: themes[theme].titleText }]}>{I18n.t('No_results_found')}</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderHeader = () => {
|
|
|
|
const { searching } = this.state;
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-07-29 16:33:28 +00:00
|
|
|
{ !searching
|
|
|
|
? (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-07-29 16:33:28 +00:00
|
|
|
{this.renderSelectServer()}
|
|
|
|
{this.renderSectionHeader('Chats')}
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-07-29 16:33:28 +00:00
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-07-18 17:44:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderContent = () => {
|
|
|
|
const {
|
2020-06-26 20:22:56 +00:00
|
|
|
chats, loading, searchResults, searching, searchText, needsPermission
|
2019-07-29 16:33:28 +00:00
|
|
|
} = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2020-06-26 20:22:56 +00:00
|
|
|
if (loading) {
|
2019-12-04 16:39:53 +00:00
|
|
|
return <ActivityIndicator theme={theme} />;
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 20:22:56 +00:00
|
|
|
if (needsPermission) {
|
|
|
|
return (
|
|
|
|
<ScrollView
|
|
|
|
style={{ backgroundColor: themes[theme].auxiliaryBackground }}
|
|
|
|
contentContainerStyle={[styles.container, styles.centered, { backgroundColor: themes[theme].backgroundColor }]}
|
|
|
|
>
|
|
|
|
<Text style={[styles.permissionTitle, { color: themes[theme].titleText }]}>{permission.title}</Text>
|
|
|
|
<Text style={[styles.permissionMessage, { color: themes[theme].bodyText }]}>{permission.message}</Text>
|
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
2019-07-29 16:33:28 +00:00
|
|
|
<FlatList
|
|
|
|
data={searching ? searchResults : chats}
|
|
|
|
keyExtractor={keyExtractor}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.flatlist, { backgroundColor: themes[theme].auxiliaryBackground }]}
|
|
|
|
contentContainerStyle={{ backgroundColor: themes[theme].backgroundColor }}
|
2019-07-29 16:33:28 +00:00
|
|
|
renderItem={this.renderItem}
|
|
|
|
getItemLayout={getItemLayout}
|
|
|
|
ItemSeparatorComponent={this.renderSeparator}
|
|
|
|
ListHeaderComponent={this.renderHeader}
|
|
|
|
ListFooterComponent={!searching && this.renderBorderBottom}
|
2019-12-04 16:39:53 +00:00
|
|
|
ListHeaderComponentStyle={!searching ? { ...styles.borderBottom, borderColor: themes[theme].separatorColor } : {}}
|
2019-07-29 16:33:28 +00:00
|
|
|
ListEmptyComponent={searching && searchText ? this.renderEmptyComponent : null}
|
|
|
|
enableEmptySections
|
|
|
|
removeClippedSubviews
|
2019-07-18 17:44:02 +00:00
|
|
|
keyboardShouldPersistTaps='always'
|
2019-07-29 16:33:28 +00:00
|
|
|
initialNumToRender={12}
|
|
|
|
windowSize={20}
|
|
|
|
/>
|
2019-07-18 17:44:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
2020-06-15 14:00:46 +00:00
|
|
|
<SafeAreaView theme={theme}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<StatusBar theme={theme} />
|
2020-06-26 20:22:56 +00:00
|
|
|
{this.renderContent()}
|
2019-07-18 17:44:02 +00:00
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = (({ share }) => ({
|
|
|
|
userId: share.user && share.user.id,
|
|
|
|
token: share.user && share.user.token,
|
2020-02-11 14:09:14 +00:00
|
|
|
server: share.server
|
2019-08-07 13:51:34 +00:00
|
|
|
}));
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(ShareListView));
|