2018-06-05 01:17:02 +00:00
|
|
|
import React from 'react';
|
2019-05-21 12:12:15 +00:00
|
|
|
import {
|
2019-12-17 14:12:55 +00:00
|
|
|
View, Linking, ScrollView, AsyncStorage, SafeAreaView, Switch, Text, Share, Clipboard
|
2019-05-21 12:12:15 +00:00
|
|
|
} from 'react-native';
|
2019-06-11 14:01:40 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-06-13 01:33:00 +00:00
|
|
|
import { connect } from 'react-redux';
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
import { logout as logoutAction } from '../../actions/login';
|
2019-05-21 12:12:15 +00:00
|
|
|
import { toggleMarkdown as toggleMarkdownAction } from '../../actions/markdown';
|
2019-08-23 13:18:47 +00:00
|
|
|
import { toggleCrashReport as toggleCrashReportAction } from '../../actions/crashReport';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { SWITCH_TRACK_COLOR, themes } from '../../constants/colors';
|
2019-11-25 20:01:17 +00:00
|
|
|
import { DrawerButton, CloseModalButton } from '../../containers/HeaderButton';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2019-06-11 14:01:40 +00:00
|
|
|
import ListItem from '../../containers/ListItem';
|
|
|
|
import { DisclosureImage } from '../../containers/DisclosureIndicator';
|
|
|
|
import Separator from '../../containers/Separator';
|
|
|
|
import I18n from '../../i18n';
|
2019-08-23 13:18:47 +00:00
|
|
|
import { MARKDOWN_KEY, CRASH_REPORT_KEY } from '../../lib/rocketchat';
|
2019-11-25 20:01:17 +00:00
|
|
|
import {
|
|
|
|
getReadableVersion, getDeviceModel, isAndroid
|
|
|
|
} from '../../utils/deviceInfo';
|
2019-06-11 14:01:40 +00:00
|
|
|
import openLink from '../../utils/openLink';
|
|
|
|
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
|
|
|
import { showErrorAlert } from '../../utils/info';
|
|
|
|
import styles from './styles';
|
|
|
|
import sharedStyles from '../Styles';
|
2019-08-23 13:18:47 +00:00
|
|
|
import { loggerConfig, analytics } from '../../utils/log';
|
2019-08-08 18:28:51 +00:00
|
|
|
import { PLAY_MARKET_LINK, APP_STORE_LINK, LICENSE_LINK } from '../../constants/links';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { withTheme } from '../../theme';
|
|
|
|
import { themedHeader } from '../../utils/navigation';
|
2019-11-25 20:01:17 +00:00
|
|
|
import SidebarView from '../SidebarView';
|
|
|
|
import { withSplit } from '../../split';
|
|
|
|
import Navigation from '../../lib/Navigation';
|
2019-12-17 14:12:55 +00:00
|
|
|
import { LISTENER } from '../../containers/Toast';
|
|
|
|
import EventEmitter from '../../utils/events';
|
2020-02-03 18:28:18 +00:00
|
|
|
import { onReviewPress } from '../../utils/review';
|
2019-05-21 12:12:15 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
const SectionSeparator = React.memo(({ theme }) => (
|
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.sectionSeparatorBorder,
|
|
|
|
{
|
|
|
|
borderColor: themes[theme].separatorColor,
|
|
|
|
backgroundColor: themes[theme].auxiliaryBackground
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
));
|
|
|
|
SectionSeparator.propTypes = {
|
|
|
|
theme: PropTypes.string
|
|
|
|
};
|
|
|
|
|
|
|
|
const ItemInfo = React.memo(({ info, theme }) => (
|
|
|
|
<View style={[styles.infoContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
|
|
|
<Text style={[styles.infoText, { color: themes[theme].infoText }]}>{info}</Text>
|
2019-08-23 13:18:47 +00:00
|
|
|
</View>
|
|
|
|
));
|
|
|
|
ItemInfo.propTypes = {
|
2019-12-04 16:39:53 +00:00
|
|
|
info: PropTypes.string,
|
|
|
|
theme: PropTypes.string
|
2019-08-23 13:18:47 +00:00
|
|
|
};
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class SettingsView extends React.Component {
|
2019-11-25 20:01:17 +00:00
|
|
|
static navigationOptions = ({ navigation, screenProps }) => ({
|
2019-12-04 16:39:53 +00:00
|
|
|
...themedHeader(screenProps.theme),
|
2019-11-25 20:01:17 +00:00
|
|
|
headerLeft: screenProps.split ? (
|
|
|
|
<CloseModalButton navigation={navigation} testID='settings-view-close' />
|
|
|
|
) : (
|
|
|
|
<DrawerButton navigation={navigation} />
|
|
|
|
),
|
2019-03-12 16:23:06 +00:00
|
|
|
title: I18n.t('Settings')
|
2019-06-11 14:01:40 +00:00
|
|
|
});
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
static propTypes = {
|
2019-06-11 14:01:40 +00:00
|
|
|
navigation: PropTypes.object,
|
|
|
|
server: PropTypes.object,
|
2019-05-21 12:12:15 +00:00
|
|
|
useMarkdown: PropTypes.bool,
|
2019-08-23 13:18:47 +00:00
|
|
|
allowCrashReport: PropTypes.bool,
|
|
|
|
toggleMarkdown: PropTypes.func,
|
2019-11-25 20:01:17 +00:00
|
|
|
toggleCrashReport: PropTypes.func,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2019-11-25 20:01:17 +00:00
|
|
|
split: PropTypes.bool,
|
|
|
|
logout: PropTypes.func.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
logout = () => {
|
|
|
|
const { logout, split } = this.props;
|
|
|
|
if (split) {
|
|
|
|
Navigation.navigate('RoomView');
|
|
|
|
}
|
|
|
|
logout();
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
toggleMarkdown = (value) => {
|
|
|
|
AsyncStorage.setItem(MARKDOWN_KEY, JSON.stringify(value));
|
|
|
|
const { toggleMarkdown } = this.props;
|
|
|
|
toggleMarkdown(value);
|
2018-08-01 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 13:18:47 +00:00
|
|
|
toggleCrashReport = (value) => {
|
|
|
|
AsyncStorage.setItem(CRASH_REPORT_KEY, JSON.stringify(value));
|
|
|
|
const { toggleCrashReport } = this.props;
|
|
|
|
toggleCrashReport(value);
|
|
|
|
loggerConfig.autoNotify = value;
|
|
|
|
analytics().setAnalyticsCollectionEnabled(value);
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
loggerConfig.clearBeforeSendCallbacks();
|
|
|
|
} else {
|
|
|
|
loggerConfig.registerBeforeSendCallback(() => false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
navigateToRoom = (room) => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate(room);
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
sendEmail = async() => {
|
|
|
|
const subject = encodeURI('React Native App Support');
|
|
|
|
const email = encodeURI('support@rocket.chat');
|
|
|
|
const description = encodeURI(`
|
|
|
|
version: ${ getReadableVersion }
|
|
|
|
device: ${ getDeviceModel }
|
|
|
|
`);
|
2018-06-13 01:33:00 +00:00
|
|
|
try {
|
2019-06-11 14:01:40 +00:00
|
|
|
await Linking.openURL(`mailto:${ email }?subject=${ subject }&body=${ description }`);
|
2018-06-13 01:33:00 +00:00
|
|
|
} catch (e) {
|
2019-06-11 14:01:40 +00:00
|
|
|
showErrorAlert(I18n.t('error-email-send-failed', { message: 'support@rocket.chat' }));
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
2018-06-05 01:17:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 18:28:51 +00:00
|
|
|
shareApp = () => {
|
|
|
|
Share.share({ message: isAndroid ? PLAY_MARKET_LINK : APP_STORE_LINK });
|
|
|
|
}
|
|
|
|
|
2019-12-17 14:12:55 +00:00
|
|
|
copyServerVersion = () => {
|
|
|
|
const { server } = this.props;
|
|
|
|
this.saveToClipboard(server.version);
|
|
|
|
}
|
|
|
|
|
|
|
|
copyAppVersion = () => {
|
|
|
|
this.saveToClipboard(getReadableVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
saveToClipboard = async(content) => {
|
|
|
|
await Clipboard.setString(content);
|
|
|
|
EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') });
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
changeTheme = () => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate('ThemeView');
|
|
|
|
}
|
2019-06-11 14:01:40 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
onPressLicense = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
openLink(LICENSE_LINK, theme);
|
|
|
|
}
|
2019-06-11 14:01:40 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderDisclosure = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return <DisclosureImage theme={theme} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderLogout = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Separator theme={theme} />
|
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Logout')}
|
|
|
|
testID='settings-logout'
|
|
|
|
onPress={this.logout}
|
|
|
|
right={this.renderDisclosure}
|
|
|
|
color={themes[theme].dangerColor}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
<Separator theme={theme} />
|
|
|
|
<ItemInfo theme={theme} />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
renderMarkdownSwitch = () => {
|
|
|
|
const { useMarkdown } = this.props;
|
|
|
|
return (
|
|
|
|
<Switch
|
|
|
|
value={useMarkdown}
|
|
|
|
trackColor={SWITCH_TRACK_COLOR}
|
|
|
|
onValueChange={this.toggleMarkdown}
|
|
|
|
/>
|
|
|
|
);
|
2019-05-21 12:12:15 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 13:18:47 +00:00
|
|
|
renderCrashReportSwitch = () => {
|
|
|
|
const { allowCrashReport } = this.props;
|
|
|
|
return (
|
|
|
|
<Switch
|
|
|
|
value={allowCrashReport}
|
|
|
|
trackColor={SWITCH_TRACK_COLOR}
|
|
|
|
onValueChange={this.toggleCrashReport}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:17:02 +00:00
|
|
|
render() {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { server, split, theme } = this.props;
|
2018-06-05 01:17:02 +00:00
|
|
|
return (
|
2019-12-04 16:39:53 +00:00
|
|
|
<SafeAreaView
|
|
|
|
style={[sharedStyles.container, { backgroundColor: themes[theme].auxiliaryBackground }]}
|
|
|
|
testID='settings-view'
|
|
|
|
>
|
|
|
|
<StatusBar theme={theme} />
|
2018-06-13 01:33:00 +00:00
|
|
|
<ScrollView
|
|
|
|
{...scrollPersistTaps}
|
2019-12-04 16:39:53 +00:00
|
|
|
contentContainerStyle={[
|
|
|
|
sharedStyles.listContentContainer,
|
|
|
|
styles.listWithoutBorderBottom,
|
|
|
|
{ borderColor: themes[theme].separatorColor }
|
|
|
|
]}
|
2019-06-11 14:01:40 +00:00
|
|
|
showsVerticalScrollIndicator={false}
|
|
|
|
testID='settings-view-list'
|
2018-06-13 01:33:00 +00:00
|
|
|
>
|
2019-11-25 20:01:17 +00:00
|
|
|
{split ? (
|
|
|
|
<>
|
2019-12-04 16:39:53 +00:00
|
|
|
<SidebarView theme={theme} />
|
|
|
|
<SectionSeparator theme={theme} />
|
2019-11-25 20:01:17 +00:00
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Profile')}
|
|
|
|
onPress={() => this.navigateToRoom('ProfileView')}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-profile'
|
|
|
|
right={this.renderDisclosure}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-11-25 20:01:17 +00:00
|
|
|
/>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Separator theme={theme} />
|
2019-11-25 20:01:17 +00:00
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Contact_us')}
|
|
|
|
onPress={this.sendEmail}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-view-contact'
|
|
|
|
right={this.renderDisclosure}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-06-11 14:01:40 +00:00
|
|
|
/>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Separator theme={theme} />
|
2019-06-11 14:01:40 +00:00
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Language')}
|
|
|
|
onPress={() => this.navigateToRoom('LanguageView')}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-view-language'
|
|
|
|
right={this.renderDisclosure}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-06-11 14:01:40 +00:00
|
|
|
/>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Separator theme={theme} />
|
2020-02-03 18:28:18 +00:00
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Review_this_app')}
|
|
|
|
showActionIndicator
|
|
|
|
onPress={onReviewPress}
|
|
|
|
testID='settings-view-review-app'
|
|
|
|
right={this.renderDisclosure}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
<Separator theme={theme} />
|
2019-06-11 14:01:40 +00:00
|
|
|
<ListItem
|
2019-09-24 20:15:13 +00:00
|
|
|
title={I18n.t('Share_this_app')}
|
2019-06-11 14:01:40 +00:00
|
|
|
showActionIndicator
|
2019-09-24 20:15:13 +00:00
|
|
|
onPress={this.shareApp}
|
|
|
|
testID='settings-view-share-app'
|
|
|
|
right={this.renderDisclosure}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-06-11 14:01:40 +00:00
|
|
|
/>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Separator theme={theme} />
|
2019-06-11 14:01:40 +00:00
|
|
|
<ListItem
|
2019-09-24 20:15:13 +00:00
|
|
|
title={I18n.t('Theme')}
|
2019-06-11 14:01:40 +00:00
|
|
|
showActionIndicator
|
2019-12-04 16:39:53 +00:00
|
|
|
onPress={this.changeTheme}
|
2019-09-24 20:15:13 +00:00
|
|
|
testID='settings-view-theme'
|
2019-12-04 16:39:53 +00:00
|
|
|
right={this.renderDisclosure}
|
|
|
|
theme={theme}
|
2019-06-11 14:01:40 +00:00
|
|
|
/>
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
<SectionSeparator theme={theme} />
|
2019-06-11 14:01:40 +00:00
|
|
|
|
|
|
|
<ListItem
|
|
|
|
title={I18n.t('License')}
|
|
|
|
onPress={this.onPressLicense}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-view-license'
|
|
|
|
right={this.renderDisclosure}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-06-11 14:01:40 +00:00
|
|
|
/>
|
2019-12-17 14:12:55 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
<Separator theme={theme} />
|
2019-12-17 14:12:55 +00:00
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Version_no', { version: getReadableVersion })}
|
|
|
|
onPress={this.copyAppVersion}
|
|
|
|
testID='settings-view-version'
|
|
|
|
theme={theme}
|
|
|
|
/>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Separator theme={theme} />
|
2019-12-17 14:12:55 +00:00
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Server_version', { version: server.version })}
|
2019-12-17 14:12:55 +00:00
|
|
|
onPress={this.copyServerVersion}
|
2019-06-11 14:01:40 +00:00
|
|
|
subtitle={`${ server.server.split('//')[1] }`}
|
|
|
|
testID='settings-view-server-version'
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-06-11 14:01:40 +00:00
|
|
|
/>
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
<SectionSeparator theme={theme} />
|
2019-06-11 14:01:40 +00:00
|
|
|
|
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Enable_markdown')}
|
|
|
|
testID='settings-view-markdown'
|
|
|
|
right={() => this.renderMarkdownSwitch()}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-06-11 14:01:40 +00:00
|
|
|
/>
|
2019-08-23 13:18:47 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
<SectionSeparator theme={theme} />
|
2019-08-23 13:18:47 +00:00
|
|
|
|
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Send_crash_report')}
|
|
|
|
testID='settings-view-crash-report'
|
|
|
|
right={() => this.renderCrashReportSwitch()}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-08-23 13:18:47 +00:00
|
|
|
/>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Separator theme={theme} />
|
2019-08-23 13:18:47 +00:00
|
|
|
<ItemInfo
|
|
|
|
info={I18n.t('Crash_report_disclaimer')}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-08-23 13:18:47 +00:00
|
|
|
/>
|
2019-11-25 20:01:17 +00:00
|
|
|
|
|
|
|
{ split ? this.renderLogout() : null }
|
2018-06-13 01:33:00 +00:00
|
|
|
</ScrollView>
|
2019-06-11 14:01:40 +00:00
|
|
|
</SafeAreaView>
|
2018-06-05 01:17:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
server: state.server,
|
2019-08-23 13:18:47 +00:00
|
|
|
useMarkdown: state.markdown.useMarkdown,
|
|
|
|
allowCrashReport: state.crashReport.allowCrashReport
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
2019-11-25 20:01:17 +00:00
|
|
|
logout: () => dispatch(logoutAction()),
|
2019-08-23 13:18:47 +00:00
|
|
|
toggleMarkdown: params => dispatch(toggleMarkdownAction(params)),
|
|
|
|
toggleCrashReport: params => dispatch(toggleCrashReportAction(params))
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(withSplit(SettingsView)));
|