2018-06-05 01:17:02 +00:00
|
|
|
import React from 'react';
|
2019-05-21 12:12:15 +00:00
|
|
|
import {
|
2020-10-30 18:31:04 +00:00
|
|
|
Linking, 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';
|
2020-07-17 17:39:06 +00:00
|
|
|
import FastImage from '@rocket.chat/react-native-fast-image';
|
2020-08-25 20:04:18 +00:00
|
|
|
import CookieManager from '@react-native-community/cookies';
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2020-03-10 11:49:54 +00:00
|
|
|
import { logout as logoutAction } from '../../actions/login';
|
|
|
|
import { selectServerRequest as selectServerRequestAction } from '../../actions/server';
|
2020-10-30 18:31:04 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../containers/HeaderButton';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2020-10-30 13:59:44 +00:00
|
|
|
import * as List from '../../containers/List';
|
2019-06-11 14:01:40 +00:00
|
|
|
import I18n from '../../i18n';
|
2020-10-30 18:31:04 +00:00
|
|
|
import RocketChat 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';
|
2020-02-10 14:53:42 +00:00
|
|
|
import { showErrorAlert, showConfirmationAlert } from '../../utils/info';
|
2020-10-30 18:31:04 +00:00
|
|
|
import { logEvent, events } from '../../utils/log';
|
2020-08-24 12:24:10 +00:00
|
|
|
import {
|
|
|
|
PLAY_MARKET_LINK, FDROID_MARKET_LINK, APP_STORE_LINK, LICENSE_LINK
|
|
|
|
} from '../../constants/links';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { withTheme } from '../../theme';
|
2019-11-25 20:01:17 +00:00
|
|
|
import SidebarView from '../SidebarView';
|
2019-12-17 14:12:55 +00:00
|
|
|
import { LISTENER } from '../../containers/Toast';
|
|
|
|
import EventEmitter from '../../utils/events';
|
2020-06-15 14:00:46 +00:00
|
|
|
import { appStart as appStartAction, ROOT_LOADING } from '../../actions/app';
|
2020-02-03 18:28:18 +00:00
|
|
|
import { onReviewPress } from '../../utils/review';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2020-08-25 20:04:18 +00:00
|
|
|
import database from '../../lib/database';
|
2020-08-24 12:24:10 +00:00
|
|
|
import { isFDroidBuild } from '../../constants/environment';
|
2020-08-25 20:04:18 +00:00
|
|
|
import { getUserSelector } from '../../selectors/login';
|
2020-08-24 12:24:10 +00:00
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class SettingsView extends React.Component {
|
2020-06-15 14:00:46 +00:00
|
|
|
static navigationOptions = ({ navigation, isMasterDetail }) => ({
|
|
|
|
headerLeft: () => (isMasterDetail ? (
|
2020-10-30 16:15:58 +00:00
|
|
|
<HeaderButton.CloseModal navigation={navigation} testID='settings-view-close' />
|
2019-11-25 20:01:17 +00:00
|
|
|
) : (
|
2020-10-30 18:31:04 +00:00
|
|
|
<HeaderButton.Drawer navigation={navigation} testID='settings-view-drawer' />
|
2020-06-15 14:00:46 +00:00
|
|
|
)),
|
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,
|
2020-08-25 20:04:18 +00:00
|
|
|
server: PropTypes.object,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2020-06-15 14:00:46 +00:00
|
|
|
isMasterDetail: PropTypes.bool,
|
2020-02-05 15:12:40 +00:00
|
|
|
logout: PropTypes.func.isRequired,
|
2020-03-10 11:49:54 +00:00
|
|
|
selectServerRequest: PropTypes.func,
|
2020-08-25 20:04:18 +00:00
|
|
|
user: PropTypes.shape({
|
|
|
|
roles: PropTypes.array,
|
|
|
|
id: PropTypes.string
|
|
|
|
}),
|
2020-02-05 15:12:40 +00:00
|
|
|
appStart: PropTypes.func
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 20:04:18 +00:00
|
|
|
checkCookiesAndLogout = async() => {
|
|
|
|
const { logout, user } = this.props;
|
|
|
|
const db = database.servers;
|
2021-02-26 16:25:51 +00:00
|
|
|
const usersCollection = db.get('users');
|
2020-08-25 20:04:18 +00:00
|
|
|
try {
|
|
|
|
const userRecord = await usersCollection.find(user.id);
|
|
|
|
if (!userRecord.loginEmailPassword) {
|
|
|
|
showConfirmationAlert({
|
|
|
|
title: I18n.t('Clear_cookies_alert'),
|
|
|
|
message: I18n.t('Clear_cookies_desc'),
|
|
|
|
confirmationText: I18n.t('Clear_cookies_yes'),
|
|
|
|
dismissText: I18n.t('Clear_cookies_no'),
|
|
|
|
onPress: async() => {
|
|
|
|
await CookieManager.clearAll(true);
|
|
|
|
logout();
|
|
|
|
},
|
|
|
|
onCancel: () => {
|
|
|
|
logout();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
logout();
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// Do nothing: user not found
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 14:53:42 +00:00
|
|
|
handleLogout = () => {
|
2020-07-30 19:51:13 +00:00
|
|
|
logEvent(events.SE_LOG_OUT);
|
2020-02-10 14:53:42 +00:00
|
|
|
showConfirmationAlert({
|
|
|
|
message: I18n.t('You_will_be_logged_out_of_this_application'),
|
2020-08-25 20:04:18 +00:00
|
|
|
confirmationText: I18n.t('Logout'),
|
|
|
|
onPress: this.checkCookiesAndLogout
|
2020-02-10 14:53:42 +00:00
|
|
|
});
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2020-02-10 14:53:42 +00:00
|
|
|
handleClearCache = () => {
|
2020-07-30 19:51:13 +00:00
|
|
|
logEvent(events.SE_CLEAR_LOCAL_SERVER_CACHE);
|
2020-02-10 14:53:42 +00:00
|
|
|
showConfirmationAlert({
|
|
|
|
message: I18n.t('This_will_clear_all_your_offline_data'),
|
2020-08-25 20:04:18 +00:00
|
|
|
confirmationText: I18n.t('Clear'),
|
2020-02-10 14:53:42 +00:00
|
|
|
onPress: async() => {
|
|
|
|
const {
|
2020-03-10 11:49:54 +00:00
|
|
|
server: { server }, appStart, selectServerRequest
|
2020-02-10 14:53:42 +00:00
|
|
|
} = this.props;
|
2020-07-17 17:39:06 +00:00
|
|
|
appStart({ root: ROOT_LOADING, text: I18n.t('Clear_cache_loading') });
|
2020-02-10 14:53:42 +00:00
|
|
|
await RocketChat.clearCache({ server });
|
2020-07-17 17:39:06 +00:00
|
|
|
await FastImage.clearMemoryCache();
|
|
|
|
await FastImage.clearDiskCache();
|
|
|
|
selectServerRequest(server, null, true);
|
2020-02-10 14:53:42 +00:00
|
|
|
}
|
|
|
|
});
|
2020-02-05 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
2020-02-19 20:52:05 +00:00
|
|
|
navigateToScreen = (screen) => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events[`SE_GO_${ screen.replace('View', '').toUpperCase() }`]);
|
2019-06-11 14:01:40 +00:00
|
|
|
const { navigation } = this.props;
|
2020-02-19 20:52:05 +00:00
|
|
|
navigation.navigate(screen);
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
sendEmail = async() => {
|
2020-07-30 19:51:13 +00:00
|
|
|
logEvent(events.SE_CONTACT_US);
|
2019-06-11 14:01:40 +00:00
|
|
|
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) {
|
2020-07-30 19:51:13 +00:00
|
|
|
logEvent(events.SE_CONTACT_US_F);
|
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 = () => {
|
2020-08-24 12:24:10 +00:00
|
|
|
let message;
|
|
|
|
if (isAndroid) {
|
|
|
|
message = PLAY_MARKET_LINK;
|
|
|
|
if (isFDroidBuild) {
|
|
|
|
message = FDROID_MARKET_LINK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
message = APP_STORE_LINK;
|
|
|
|
}
|
|
|
|
Share.share({ message });
|
2019-08-08 18:28:51 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 14:12:55 +00:00
|
|
|
copyServerVersion = () => {
|
2020-07-30 19:51:13 +00:00
|
|
|
const { server: { version } } = this.props;
|
|
|
|
logEvent(events.SE_COPY_SERVER_VERSION, { serverVersion: version });
|
|
|
|
this.saveToClipboard(version);
|
2019-12-17 14:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
copyAppVersion = () => {
|
2020-07-30 19:51:13 +00:00
|
|
|
logEvent(events.SE_COPY_APP_VERSION, { appVersion: getReadableVersion });
|
2019-12-17 14:12:55 +00:00
|
|
|
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
|
|
|
onPressLicense = () => {
|
2020-07-30 19:51:13 +00:00
|
|
|
logEvent(events.SE_READ_LICENSE);
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
|
|
|
openLink(LICENSE_LINK, theme);
|
|
|
|
}
|
2019-06-11 14:01:40 +00:00
|
|
|
|
2018-06-05 01:17:02 +00:00
|
|
|
render() {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { server, isMasterDetail, theme } = this.props;
|
2018-06-05 01:17:02 +00:00
|
|
|
return (
|
2020-10-30 13:59:44 +00:00
|
|
|
<SafeAreaView testID='settings-view'>
|
|
|
|
<StatusBar />
|
|
|
|
<List.Container testID='settings-view-list'>
|
2020-06-15 14:00:46 +00:00
|
|
|
{isMasterDetail ? (
|
2019-11-25 20:01:17 +00:00
|
|
|
<>
|
2020-10-30 13:59:44 +00:00
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<SidebarView />
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Profile'
|
|
|
|
onPress={() => this.navigateToScreen('ProfileView')}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-profile'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
2019-11-25 20:01:17 +00:00
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
|
2020-10-30 13:59:44 +00:00
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Contact_us'
|
|
|
|
onPress={this.sendEmail}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-view-contact'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Language'
|
|
|
|
onPress={() => this.navigateToScreen('LanguageView')}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-view-language'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
{!isFDroidBuild ? (
|
|
|
|
<>
|
|
|
|
<List.Item
|
|
|
|
title='Review_this_app'
|
|
|
|
showActionIndicator
|
|
|
|
onPress={onReviewPress}
|
|
|
|
testID='settings-view-review-app'
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Share_this_app'
|
|
|
|
showActionIndicator
|
|
|
|
onPress={this.shareApp}
|
|
|
|
testID='settings-view-share-app'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Default_browser'
|
|
|
|
showActionIndicator
|
|
|
|
onPress={() => this.navigateToScreen('DefaultBrowserView')}
|
|
|
|
testID='settings-view-default-browser'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Theme'
|
|
|
|
showActionIndicator
|
|
|
|
onPress={() => this.navigateToScreen('ThemeView')}
|
|
|
|
testID='settings-view-theme'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
2020-10-30 18:31:04 +00:00
|
|
|
title='Security_and_privacy'
|
2020-10-30 13:59:44 +00:00
|
|
|
showActionIndicator
|
2020-10-30 18:31:04 +00:00
|
|
|
onPress={() => this.navigateToScreen('SecurityPrivacyView')}
|
|
|
|
testID='settings-view-security-privacy'
|
2020-10-30 13:59:44 +00:00
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
|
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='License'
|
|
|
|
onPress={this.onPressLicense}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-view-license'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title={I18n.t('Version_no', { version: getReadableVersion })}
|
|
|
|
onPress={this.copyAppVersion}
|
|
|
|
testID='settings-view-version'
|
|
|
|
translateTitle={false}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title={I18n.t('Server_version', { version: server.version })}
|
|
|
|
onPress={this.copyServerVersion}
|
|
|
|
subtitle={`${ server.server.split('//')[1] }`}
|
|
|
|
testID='settings-view-server-version'
|
|
|
|
translateTitle={false}
|
|
|
|
translateSubtitle={false}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
2019-06-11 14:01:40 +00:00
|
|
|
|
2020-10-30 13:59:44 +00:00
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Clear_cache'
|
|
|
|
testID='settings-clear-cache'
|
|
|
|
onPress={this.handleClearCache}
|
|
|
|
showActionIndicator
|
|
|
|
color={themes[theme].dangerColor}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Logout'
|
|
|
|
testID='settings-logout'
|
|
|
|
onPress={this.handleLogout}
|
|
|
|
showActionIndicator
|
|
|
|
color={themes[theme].dangerColor}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
</List.Container>
|
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,
|
2020-08-25 20:04:18 +00:00
|
|
|
user: getUserSelector(state),
|
2020-06-15 14:00:46 +00:00
|
|
|
isMasterDetail: state.app.isMasterDetail
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
2019-11-25 20:01:17 +00:00
|
|
|
logout: () => dispatch(logoutAction()),
|
2020-03-10 11:49:54 +00:00
|
|
|
selectServerRequest: params => dispatch(selectServerRequestAction(params)),
|
2020-06-15 14:00:46 +00:00
|
|
|
appStart: params => dispatch(appStartAction(params))
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(SettingsView));
|