2019-07-18 17:44:02 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-10-01 18:12:19 +00:00
|
|
|
import { BackHandler, FlatList, Keyboard, PermissionsAndroid, ScrollView, Text, View } from 'react-native';
|
2019-07-18 17:44:02 +00:00
|
|
|
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';
|
2021-03-15 20:16:34 +00:00
|
|
|
import { dequal } from 'dequal';
|
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';
|
2021-10-01 18:12:19 +00:00
|
|
|
import { isAndroid, isIOS } 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-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../containers/HeaderButton';
|
2019-12-04 16:39:53 +00:00
|
|
|
import ActivityIndicator from '../../containers/ActivityIndicator';
|
2021-02-10 13:35:44 +00:00
|
|
|
import * as List from '../../containers/List';
|
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';
|
2020-09-15 13:01:43 +00:00
|
|
|
import { sanitizeLikeString } from '../../lib/database/utils';
|
2021-10-01 18:12:19 +00:00
|
|
|
import styles from './styles';
|
|
|
|
import ShareListHeader from './Header';
|
2020-06-26 20:22:56 +00:00
|
|
|
|
|
|
|
const permission = {
|
|
|
|
title: I18n.t('Read_External_Permission'),
|
|
|
|
message: I18n.t('Read_External_Permission_Message')
|
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-02-10 13:35:44 +00:00
|
|
|
const getItemLayout = (data, index) => ({ length: data.length, 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
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
searching: false,
|
2019-07-29 16:33:28 +00:00
|
|
|
searchText: '',
|
|
|
|
searchResults: [],
|
2019-07-18 17:44:02 +00:00
|
|
|
chats: [],
|
2021-02-10 13:35:44 +00:00
|
|
|
serversCount: 0,
|
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();
|
2021-02-10 13:35:44 +00:00
|
|
|
if (isAndroid) {
|
2021-10-01 18:12:19 +00:00
|
|
|
this.unsubscribeFocus = props.navigation.addListener('focus', () =>
|
|
|
|
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)
|
|
|
|
);
|
|
|
|
this.unsubscribeBlur = props.navigation.addListener('blur', () =>
|
|
|
|
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress)
|
|
|
|
);
|
2021-02-10 13:35:44 +00:00
|
|
|
}
|
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
|
|
|
}
|
2021-10-01 18:12:19 +00:00
|
|
|
const info = await Promise.all(
|
|
|
|
data
|
|
|
|
.filter(item => item.type === 'media')
|
|
|
|
.map(file => FileSystem.getInfoAsync(this.uriToPath(file.value), { size: true }))
|
|
|
|
);
|
2020-06-26 20:22:56 +00:00
|
|
|
const attachments = info.map(file => ({
|
2020-12-01 20:19:48 +00:00
|
|
|
filename: decodeURIComponent(file.uri.substring(file.uri.lastIndexOf('/') + 1)),
|
2020-06-26 20:22:56 +00:00
|
|
|
description: '',
|
|
|
|
size: file.size,
|
|
|
|
mime: mime.lookup(file.uri),
|
|
|
|
path: file.uri
|
|
|
|
}));
|
2021-10-01 18:12:19 +00:00
|
|
|
const text = data.filter(item => item.type === 'text').reduce((acc, item) => `${item.value}\n${acc}`, '');
|
2020-06-26 20:22:56 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-02-10 13:35:44 +00:00
|
|
|
const { server, userId } = this.props;
|
2019-07-29 16:33:28 +00:00
|
|
|
if (server !== nextProps.server) {
|
2019-07-18 17:44:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-10-30 15:54:02 +00:00
|
|
|
if (userId !== nextProps.userId) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
const { searchResults } = this.state;
|
2021-02-10 13:35:44 +00:00
|
|
|
if (nextState.searching) {
|
2021-03-15 20:16:34 +00:00
|
|
|
if (!dequal(nextState.searchResults, searchResults)) {
|
2021-02-10 13:35:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
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({
|
2021-10-01 18:12:19 +00:00
|
|
|
headerLeft: () =>
|
|
|
|
searching ? (
|
2020-10-30 16:15:58 +00:00
|
|
|
<HeaderButton.Container left>
|
|
|
|
<HeaderButton.Item title='cancel' iconName='close' onPress={this.cancelSearch} />
|
|
|
|
</HeaderButton.Container>
|
2021-10-01 18:12:19 +00:00
|
|
|
) : (
|
|
|
|
<HeaderButton.CancelModal onPress={ShareExtension.close} testID='share-extension-close' />
|
|
|
|
),
|
2020-06-15 14:00:46 +00:00
|
|
|
headerTitle: () => <ShareListHeader searching={searching} search={this.search} theme={theme} />,
|
2021-10-01 18:12:19 +00:00
|
|
|
headerRight: () =>
|
|
|
|
searching ? null : (
|
|
|
|
<HeaderButton.Container>
|
|
|
|
<HeaderButton.Item iconName='search' onPress={this.initSearch} />
|
|
|
|
</HeaderButton.Container>
|
|
|
|
)
|
2020-06-15 14:00:46 +00:00
|
|
|
});
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
|
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);
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
query = async 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),
|
2021-01-25 17:14:45 +00:00
|
|
|
Q.experimentalTake(20),
|
2020-07-20 16:44:54 +00:00
|
|
|
Q.experimentalSortBy('room_updated_at', Q.desc)
|
|
|
|
];
|
|
|
|
if (text) {
|
2020-09-15 13:01:43 +00:00
|
|
|
const likeString = sanitizeLikeString(text);
|
2021-10-01 18:12:19 +00:00
|
|
|
defaultWhereClause.push(Q.or(Q.where('name', Q.like(`%${likeString}%`)), Q.where('fname', Q.like(`%${likeString}%`))));
|
2020-07-20 16:44:54 +00:00
|
|
|
}
|
2021-10-01 18:12:19 +00:00
|
|
|
const data = await db
|
|
|
|
.get('subscriptions')
|
|
|
|
.query(...defaultWhereClause)
|
|
|
|
.fetch();
|
2021-02-10 13:35:44 +00:00
|
|
|
return data.map(item => ({
|
|
|
|
rid: item.rid,
|
|
|
|
t: item.t,
|
|
|
|
name: item.name,
|
|
|
|
fname: item.fname,
|
|
|
|
blocked: item.blocked,
|
|
|
|
blocker: item.blocker,
|
|
|
|
prid: item.prid,
|
|
|
|
uids: item.uids,
|
|
|
|
usernames: item.usernames,
|
|
|
|
topic: item.topic
|
|
|
|
}));
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
getSubscriptions = async server => {
|
2020-07-20 16:44:54 +00:00
|
|
|
const serversDB = database.servers;
|
|
|
|
|
|
|
|
if (server) {
|
2021-02-10 13:35:44 +00:00
|
|
|
const chats = await this.query();
|
2021-03-15 20:16:34 +00:00
|
|
|
const serversCollection = serversDB.get('servers');
|
2021-02-10 13:35:44 +00:00
|
|
|
const serversCount = await serversCollection.query(Q.where('rooms_updated_at', Q.notEq(null))).fetchCount();
|
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({
|
2021-02-10 13:35:44 +00:00
|
|
|
chats: chats ?? [],
|
|
|
|
serversCount,
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
askForPermission = async data => {
|
2020-06-26 20:22:56 +00:00
|
|
|
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();
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2020-06-26 20:22:56 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
uriToPath = uri => decodeURIComponent(isIOS ? uri.replace(/^file:\/\//, '') : uri);
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-10-01 18:12:19 +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;
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
shareMessage = room => {
|
2020-06-26 20:22:56 +00:00
|
|
|
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
|
|
|
});
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
search = async text => {
|
2020-07-20 16:44:54 +00:00
|
|
|
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
|
|
|
});
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
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());
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
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();
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-07-29 16:33:28 +00:00
|
|
|
|
|
|
|
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;
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
renderSectionHeader = header => {
|
2019-07-29 16:33:28 +00:00
|
|
|
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 (
|
2021-02-10 13:35:44 +00:00
|
|
|
<>
|
|
|
|
<View style={[styles.headerContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
2021-10-01 18:12:19 +00:00
|
|
|
<Text style={[styles.headerText, { color: themes[theme].titleText }]}>{I18n.t(header)}</Text>
|
2021-02-10 13:35:44 +00:00
|
|
|
</View>
|
|
|
|
<List.Separator />
|
|
|
|
</>
|
2019-07-29 16:33:28 +00:00
|
|
|
);
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
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;
|
2021-10-01 18:12:19 +00:00
|
|
|
const { userId, token, server, theme } = 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)}
|
2021-10-01 18:12:19 +00:00
|
|
|
testID={`share-extension-item-${item.name}`}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-07-18 17:44:02 +00:00
|
|
|
/>
|
|
|
|
);
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderSelectServer = () => {
|
2021-02-10 13:35:44 +00:00
|
|
|
const { serverInfo } = this.state;
|
|
|
|
const { navigation } = this.props;
|
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-07-18 17:44:02 +00:00
|
|
|
{this.renderSectionHeader('Select_Server')}
|
2021-10-01 18:12:19 +00:00
|
|
|
<ServerItem onPress={() => navigation.navigate('SelectServerView')} item={serverInfo} />
|
2021-02-10 13:35:44 +00:00
|
|
|
<List.Separator />
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2021-02-10 13:35:44 +00:00
|
|
|
);
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
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>
|
|
|
|
);
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderHeader = () => {
|
2021-02-10 13:35:44 +00:00
|
|
|
const { searching, serversCount } = this.state;
|
|
|
|
|
|
|
|
if (searching) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serversCount === 1) {
|
|
|
|
return this.renderSectionHeader('Chats');
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2021-02-10 13:35:44 +00:00
|
|
|
{this.renderSelectServer()}
|
|
|
|
{this.renderSectionHeader('Chats')}
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-07-18 17:44:02 +00:00
|
|
|
);
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-02-10 13:35:44 +00:00
|
|
|
render = () => {
|
2021-10-01 18:12:19 +00:00
|
|
|
const { chats, loading, searchResults, searching, searchText, needsPermission } = 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 (
|
2021-02-10 13:35:44 +00:00
|
|
|
<SafeAreaView>
|
|
|
|
<ScrollView
|
|
|
|
style={{ backgroundColor: themes[theme].backgroundColor }}
|
2021-10-01 18:12:19 +00:00
|
|
|
contentContainerStyle={[styles.container, styles.centered, { backgroundColor: themes[theme].backgroundColor }]}>
|
2021-02-10 13:35:44 +00:00
|
|
|
<Text style={[styles.permissionTitle, { color: themes[theme].titleText }]}>{permission.title}</Text>
|
|
|
|
<Text style={[styles.permissionMessage, { color: themes[theme].bodyText }]}>{permission.message}</Text>
|
|
|
|
</ScrollView>
|
|
|
|
</SafeAreaView>
|
2020-06-26 20:22:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
2020-10-30 13:59:44 +00:00
|
|
|
<SafeAreaView>
|
2021-02-10 13:35:44 +00:00
|
|
|
<FlatList
|
|
|
|
data={searching ? searchResults : chats}
|
|
|
|
keyExtractor={keyExtractor}
|
|
|
|
style={[styles.flatlist, { backgroundColor: themes[theme].auxiliaryBackground }]}
|
|
|
|
contentContainerStyle={{ backgroundColor: themes[theme].backgroundColor }}
|
|
|
|
renderItem={this.renderItem}
|
|
|
|
getItemLayout={getItemLayout}
|
|
|
|
ItemSeparatorComponent={List.Separator}
|
2021-03-15 20:16:34 +00:00
|
|
|
ListHeaderComponent={this.renderHeader}
|
2021-02-10 13:35:44 +00:00
|
|
|
ListFooterComponent={!searching || searchResults.length > 0 ? <List.Separator /> : null}
|
|
|
|
ListEmptyComponent={searching && searchText ? this.renderEmptyComponent : null}
|
|
|
|
removeClippedSubviews
|
|
|
|
keyboardShouldPersistTaps='always'
|
|
|
|
/>
|
2019-07-18 17:44:02 +00:00
|
|
|
</SafeAreaView>
|
|
|
|
);
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
const mapStateToProps = ({ share }) => ({
|
2019-08-07 13:51:34 +00:00
|
|
|
userId: share.user && share.user.id,
|
|
|
|
token: share.user && share.user.token,
|
2020-11-04 16:53:44 +00:00
|
|
|
server: share.server.server
|
2021-10-01 18:12:19 +00:00
|
|
|
});
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(ShareListView));
|