2019-07-18 17:44:02 +00:00
|
|
|
import React from 'react';
|
2021-12-02 13:39:48 +00:00
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
|
|
|
import { BackHandler, FlatList, Keyboard, PermissionsAndroid, ScrollView, Text, View, Rationale } 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-02-26 16:01:45 +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';
|
2019-07-18 17:44:02 +00:00
|
|
|
import I18n from '../../i18n';
|
2022-04-07 20:25:25 +00:00
|
|
|
import DirectoryItem, { ROW_HEIGHT } from '../../containers/DirectoryItem';
|
2022-04-07 17:07:16 +00:00
|
|
|
import ServerItem from '../../containers/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-01 17:18:55 +00:00
|
|
|
import * as List from '../../containers/List';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { animateNextTransition } from '../../lib/methods/helpers/layoutAnimation';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, withTheme } from '../../theme';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2020-09-15 13:01:43 +00:00
|
|
|
import { sanitizeLikeString } from '../../lib/database/utils';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
|
|
|
import ShareListHeader from './Header';
|
2022-05-03 01:06:19 +00:00
|
|
|
import { TServerModel, TSubscriptionModel } from '../../definitions';
|
2023-08-18 17:48:33 +00:00
|
|
|
import { ShareInsideStackParamList } from '../../definitions/navigationTypes';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { getRoomAvatar, isAndroid, isIOS } from '../../lib/methods/helpers';
|
2020-06-26 20:22:56 +00:00
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
interface IDataFromShare {
|
2021-12-02 13:39:48 +00:00
|
|
|
value: string;
|
|
|
|
type: string;
|
|
|
|
}
|
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
interface IFileToShare {
|
2021-12-02 13:39:48 +00:00
|
|
|
filename: string;
|
|
|
|
description: string;
|
|
|
|
size: number;
|
2022-05-03 01:06:19 +00:00
|
|
|
mime: string;
|
2021-12-02 13:39:48 +00:00
|
|
|
path: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
searching: boolean;
|
|
|
|
searchText: string;
|
2022-05-03 01:06:19 +00:00
|
|
|
searchResults: TSubscriptionModel[];
|
|
|
|
chats: TSubscriptionModel[];
|
2021-12-02 13:39:48 +00:00
|
|
|
serversCount: number;
|
2022-01-12 12:54:04 +00:00
|
|
|
attachments: IFileToShare[];
|
2021-12-02 13:39:48 +00:00
|
|
|
text: string;
|
|
|
|
loading: boolean;
|
2022-05-03 01:06:19 +00:00
|
|
|
serverInfo: TServerModel;
|
2021-12-02 13:39:48 +00:00
|
|
|
needsPermission: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface INavigationOption {
|
2022-05-03 01:06:19 +00:00
|
|
|
navigation: StackNavigationProp<ShareInsideStackParamList, 'ShareListView'>;
|
2021-12-02 13:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IShareListViewProps extends INavigationOption {
|
2023-08-18 17:48:33 +00:00
|
|
|
server: string;
|
|
|
|
token: string;
|
|
|
|
userId: string;
|
|
|
|
theme: TSupportedThemes;
|
2021-12-02 13:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const permission: Rationale = {
|
2020-06-26 20:22:56 +00:00
|
|
|
title: I18n.t('Read_External_Permission'),
|
2021-12-02 13:39:48 +00:00
|
|
|
message: I18n.t('Read_External_Permission_Message'),
|
|
|
|
buttonPositive: 'Ok'
|
2020-06-26 20:22:56 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-12-02 13:39:48 +00:00
|
|
|
const getItemLayout = (data: any, index: number) => ({ length: data.length, offset: ROW_HEIGHT * index, index });
|
2022-05-03 01:06:19 +00:00
|
|
|
const keyExtractor = (item: TSubscriptionModel) => item.rid;
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-12-02 13:39:48 +00:00
|
|
|
class ShareListView extends React.Component<IShareListViewProps, IState> {
|
|
|
|
private unsubscribeFocus: (() => void) | undefined;
|
|
|
|
|
|
|
|
private unsubscribeBlur: (() => void) | undefined;
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-12-02 13:39:48 +00:00
|
|
|
constructor(props: IShareListViewProps) {
|
2019-07-18 17:44:02 +00:00
|
|
|
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-01 17:18:55 +00:00
|
|
|
serversCount: 0,
|
2020-06-26 20:22:56 +00:00
|
|
|
attachments: [],
|
|
|
|
text: '',
|
2019-07-29 16:33:28 +00:00
|
|
|
loading: true,
|
2022-05-03 01:06:19 +00:00
|
|
|
serverInfo: {} as TServerModel,
|
2020-06-26 20:22:56 +00:00
|
|
|
needsPermission: isAndroid || false
|
2019-07-18 17:44:02 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
2021-02-01 17:18:55 +00:00
|
|
|
if (isAndroid) {
|
2021-09-13 20:41:05 +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-01 17:18:55 +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 {
|
2022-01-12 12:54:04 +00:00
|
|
|
const data = (await ShareExtension.data()) as IDataFromShare[];
|
2020-06-26 20:22:56 +00:00
|
|
|
if (isAndroid) {
|
|
|
|
await this.askForPermission(data);
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +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: '',
|
2023-08-18 17:48:33 +00:00
|
|
|
size: file.size,
|
2020-06-26 20:22:56 +00:00
|
|
|
mime: mime.lookup(file.uri),
|
|
|
|
path: file.uri
|
2022-01-12 12:54:04 +00:00
|
|
|
})) as IFileToShare[];
|
2021-09-13 20:41:05 +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
|
|
|
}
|
|
|
|
|
2021-12-02 13:39:48 +00:00
|
|
|
UNSAFE_componentWillReceiveProps(nextProps: IShareListViewProps) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-02 13:39:48 +00:00
|
|
|
shouldComponentUpdate(nextProps: IShareListViewProps, nextState: IState) {
|
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-01 17:18:55 +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-01 17:18:55 +00:00
|
|
|
if (nextState.searching) {
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextState.searchResults, searchResults)) {
|
2021-02-01 17:18:55 +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}
|
2021-12-02 13:39:48 +00:00
|
|
|
onChangeSearchText={this.search}
|
2023-08-18 17:48:33 +00:00
|
|
|
theme={theme}
|
2020-06-15 14:00:46 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
navigation.setOptions({
|
2021-09-13 20:41:05 +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-09-13 20:41:05 +00:00
|
|
|
) : (
|
|
|
|
<HeaderButton.CancelModal onPress={ShareExtension.close} testID='share-extension-close' />
|
|
|
|
),
|
2023-08-18 17:48:33 +00:00
|
|
|
headerTitle: () => <ShareListHeader searching={searching} onChangeSearchText={this.search} theme={theme} />,
|
2021-09-13 20:41:05 +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-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2021-12-02 13:39:48 +00:00
|
|
|
internalSetState = (...args: object[]) => {
|
2019-07-18 17:44:02 +00:00
|
|
|
const { navigation } = this.props;
|
2019-09-19 13:32:24 +00:00
|
|
|
if (navigation.isFocused()) {
|
|
|
|
animateNextTransition();
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
2021-12-02 13:39:48 +00:00
|
|
|
// @ts-ignore
|
2019-07-18 17:44:02 +00:00
|
|
|
this.setState(...args);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-12-02 13:39:48 +00:00
|
|
|
query = async (text?: string) => {
|
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),
|
2023-08-18 17:48:33 +00:00
|
|
|
Q.experimentalSkip(0),
|
|
|
|
Q.experimentalTake(20),
|
|
|
|
Q.experimentalSortBy('room_updated_at', Q.desc)
|
2021-12-02 13:39:48 +00:00
|
|
|
] as (Q.WhereDescription | Q.Skip | Q.Take | Q.SortBy | Q.Or)[];
|
2020-07-20 16:44:54 +00:00
|
|
|
if (text) {
|
2020-09-15 13:01:43 +00:00
|
|
|
const likeString = sanitizeLikeString(text);
|
2021-09-13 20:41:05 +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-12-02 13:39:48 +00:00
|
|
|
const data = (await db
|
2021-09-13 20:41:05 +00:00
|
|
|
.get('subscriptions')
|
|
|
|
.query(...defaultWhereClause)
|
2022-05-03 01:06:19 +00:00
|
|
|
.fetch()) as TSubscriptionModel[];
|
2021-12-02 13:39:48 +00:00
|
|
|
|
2021-02-01 17:18:55 +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,
|
2023-02-02 03:04:17 +00:00
|
|
|
topic: item.topic,
|
|
|
|
teamMain: item.teamMain
|
2021-02-01 17:18:55 +00:00
|
|
|
}));
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2023-08-18 17:48:33 +00:00
|
|
|
getSubscriptions = async (server: string) => {
|
2020-07-20 16:44:54 +00:00
|
|
|
const serversDB = database.servers;
|
|
|
|
|
|
|
|
if (server) {
|
2021-02-01 17:18:55 +00:00
|
|
|
const chats = await this.query();
|
2021-02-26 16:25:51 +00:00
|
|
|
const serversCollection = serversDB.get('servers');
|
2021-02-01 17:18:55 +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-01 17:18:55 +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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
askForPermission = async (data: IDataFromShare[]) => {
|
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-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-26 20:22:56 +00:00
|
|
|
|
2021-12-02 13:39:48 +00:00
|
|
|
uriToPath = (uri: string) => decodeURIComponent(isIOS ? uri.replace(/^file:\/\//, '') : uri);
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2022-05-03 01:06:19 +00:00
|
|
|
getRoomTitle = (item: TSubscriptionModel) => {
|
2019-07-29 16:33:28 +00:00
|
|
|
const { serverInfo } = this.state;
|
2021-12-02 13:39:48 +00:00
|
|
|
return ((item.prid || serverInfo?.useRealName) && item.fname) || item.name;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2022-05-03 01:06:19 +00:00
|
|
|
shareMessage = (room: TSubscriptionModel) => {
|
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-09-13 20:41:05 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-12-02 13:39:48 +00:00
|
|
|
search = async (text: string) => {
|
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-09-13 20:41:05 +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-09-13 20:41:05 +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-09-13 20:41:05 +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-09-13 20:41:05 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-12-02 13:39:48 +00:00
|
|
|
renderSectionHeader = (header: string) => {
|
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-01 17:18:55 +00:00
|
|
|
<>
|
2023-08-18 17:48:33 +00:00
|
|
|
<View style={[styles.headerContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
|
|
|
<Text style={[styles.headerText, { color: themes[theme].titleText }]}>{I18n.t(header)}</Text>
|
2021-02-01 17:18:55 +00:00
|
|
|
</View>
|
|
|
|
<List.Separator />
|
|
|
|
</>
|
2019-07-29 16:33:28 +00:00
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2022-05-03 01:06:19 +00:00
|
|
|
renderItem = ({ item }: { item: TSubscriptionModel }) => {
|
2020-07-20 16:44:54 +00:00
|
|
|
const { serverInfo } = this.state;
|
|
|
|
let description;
|
|
|
|
switch (item.t) {
|
|
|
|
case 'c':
|
|
|
|
description = item.topic || item.description;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
description = item.topic || item.description;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2021-12-02 13:39:48 +00:00
|
|
|
description = serverInfo?.useRealName ? item.name : item.fname;
|
2020-07-20 16:44:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
description = item.fname;
|
|
|
|
break;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
|
|
|
<DirectoryItem
|
|
|
|
title={this.getRoomTitle(item)}
|
2022-04-28 20:37:25 +00:00
|
|
|
avatar={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-09-13 20:41:05 +00:00
|
|
|
testID={`share-extension-item-${item.name}`}
|
2023-02-02 03:04:17 +00:00
|
|
|
teamMain={item.teamMain}
|
2019-07-18 17:44:02 +00:00
|
|
|
/>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderSelectServer = () => {
|
2021-02-01 17:18:55 +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-09-13 20:41:05 +00:00
|
|
|
<ServerItem onPress={() => navigation.navigate('SelectServerView')} item={serverInfo} />
|
2021-02-01 17:18:55 +00:00
|
|
|
<List.Separator />
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2021-02-01 17:18:55 +00:00
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderEmptyComponent = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return (
|
2023-08-18 17:48:33 +00:00
|
|
|
<View style={[styles.container, styles.emptyContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
|
|
|
<Text style={[styles.title, { color: themes[theme].titleText }]}>{I18n.t('No_results_found')}</Text>
|
2019-12-04 16:39:53 +00:00
|
|
|
</View>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderHeader = () => {
|
2021-02-01 17:18:55 +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-01 17:18:55 +00:00
|
|
|
{this.renderSelectServer()}
|
|
|
|
{this.renderSectionHeader('Chats')}
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-07-18 17:44:02 +00:00
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2021-02-01 17:18:55 +00:00
|
|
|
render = () => {
|
2021-09-13 20:41:05 +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) {
|
2022-03-18 02:37:10 +00:00
|
|
|
return <ActivityIndicator />;
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 20:22:56 +00:00
|
|
|
if (needsPermission) {
|
|
|
|
return (
|
2021-02-01 17:18:55 +00:00
|
|
|
<SafeAreaView>
|
|
|
|
<ScrollView
|
2023-08-18 17:48:33 +00:00
|
|
|
style={{ backgroundColor: themes[theme].backgroundColor }}
|
|
|
|
contentContainerStyle={[styles.container, styles.centered, { backgroundColor: themes[theme].backgroundColor }]}
|
2022-08-08 21:02:08 +00:00
|
|
|
>
|
2023-08-18 17:48:33 +00:00
|
|
|
<Text style={[styles.permissionTitle, { color: themes[theme].titleText }]}>{permission.title}</Text>
|
|
|
|
<Text style={[styles.permissionMessage, { color: themes[theme].bodyText }]}>{permission.message}</Text>
|
2021-02-01 17:18:55 +00:00
|
|
|
</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-01 17:18:55 +00:00
|
|
|
<FlatList
|
|
|
|
data={searching ? searchResults : chats}
|
|
|
|
keyExtractor={keyExtractor}
|
2023-08-18 17:48:33 +00:00
|
|
|
style={[styles.flatlist, { backgroundColor: themes[theme].auxiliaryBackground }]}
|
|
|
|
contentContainerStyle={{ backgroundColor: themes[theme].backgroundColor }}
|
2021-02-01 17:18:55 +00:00
|
|
|
renderItem={this.renderItem}
|
|
|
|
getItemLayout={getItemLayout}
|
|
|
|
ItemSeparatorComponent={List.Separator}
|
|
|
|
ListHeaderComponent={this.renderHeader}
|
|
|
|
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-09-13 20:41:05 +00:00
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2021-12-02 13:39:48 +00:00
|
|
|
const mapStateToProps = ({ share }: any) => ({
|
2023-08-18 17:48:33 +00:00
|
|
|
userId: share.user && share.user.id,
|
|
|
|
token: share.user && share.user.token,
|
|
|
|
server: share.server.server
|
2021-09-13 20:41:05 +00:00
|
|
|
});
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(ShareListView));
|