import React from 'react';
import { Switch } from 'react-native';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import AsyncStorage from '@react-native-community/async-storage';
import { toggleCrashReport as toggleCrashReportAction, toggleAnalyticsEvents as toggleAnalyticsEventsAction } from '../actions/crashReport';
import { SWITCH_TRACK_COLOR } from '../constants/colors';
import StatusBar from '../containers/StatusBar';
import * as List from '../containers/List';
import I18n from '../i18n';
import { CRASH_REPORT_KEY, ANALYTICS_EVENTS_KEY } from '../lib/rocketchat';
import {
loggerConfig, analytics, logEvent, events
} from '../utils/log';
import SafeAreaView from '../containers/SafeAreaView';
import { isFDroidBuild } from '../constants/environment';
import { getUserSelector } from '../selectors/login';
class SecurityPrivacyView extends React.Component {
static navigationOptions = () => ({
title: I18n.t('Security_and_privacy')
});
static propTypes = {
navigation: PropTypes.object,
allowCrashReport: PropTypes.bool,
allowAnalyticsEvents: PropTypes.bool,
e2eEnabled: PropTypes.bool,
toggleCrashReport: PropTypes.func,
toggleAnalyticsEvents: PropTypes.func,
user: PropTypes.shape({
roles: PropTypes.array,
id: PropTypes.string
})
}
toggleCrashReport = (value) => {
logEvent(events.SE_TOGGLE_CRASH_REPORT);
AsyncStorage.setItem(CRASH_REPORT_KEY, JSON.stringify(value));
const { toggleCrashReport } = this.props;
toggleCrashReport(value);
if (!isFDroidBuild) {
loggerConfig.autoNotify = value;
if (value) {
loggerConfig.clearBeforeSendCallbacks();
} else {
loggerConfig.registerBeforeSendCallback(() => false);
}
}
}
toggleAnalyticsEvents = (value) => {
logEvent(events.SE_TOGGLE_ANALYTICS_EVENTS);
const { toggleAnalyticsEvents } = this.props;
AsyncStorage.setItem(ANALYTICS_EVENTS_KEY, JSON.stringify(value));
toggleAnalyticsEvents(value);
analytics().setAnalyticsCollectionEnabled(value);
}
navigateToScreen = (screen) => {
logEvent(events[`SP_GO_${ screen.replace('View', '').toUpperCase() }`]);
const { navigation } = this.props;
navigation.navigate(screen);
}
renderCrashReportSwitch = () => {
const { allowCrashReport } = this.props;
return (
);
}
renderAnalyticsEventsSwitch = () => {
const { allowAnalyticsEvents } = this.props;
return (
);
}
render() {
const { e2eEnabled } = this.props;
return (
{e2eEnabled
? (
<>
this.navigateToScreen('E2EEncryptionSecurityView')}
testID='security-privacy-view-e2e-encryption'
/>
>
)
: null
}
this.navigateToScreen('ScreenLockConfigView')}
testID='security-privacy-view-screen-lock'
/>
{!isFDroidBuild ? (
<>
this.renderAnalyticsEventsSwitch()}
/>
this.renderCrashReportSwitch()}
/>
>
) : null}
);
}
}
const mapStateToProps = state => ({
user: getUserSelector(state),
allowCrashReport: state.crashReport.allowCrashReport,
allowAnalyticsEvents: state.crashReport.allowAnalyticsEvents,
e2eEnabled: state.settings.E2E_Enable
});
const mapDispatchToProps = dispatch => ({
toggleCrashReport: params => dispatch(toggleCrashReportAction(params)),
toggleAnalyticsEvents: params => dispatch(toggleAnalyticsEventsAction(params))
});
export default connect(mapStateToProps, mapDispatchToProps)(SecurityPrivacyView);