2022-09-30 14:50:33 +00:00
|
|
|
import Clipboard from '@react-native-clipboard/clipboard';
|
2022-02-02 18:27:10 +00:00
|
|
|
import CookieManager from '@react-native-cookies/cookies';
|
2022-09-30 14:50:33 +00:00
|
|
|
import { useNavigation } from '@react-navigation/native';
|
|
|
|
import React, { useLayoutEffect } from 'react';
|
2022-03-29 16:09:44 +00:00
|
|
|
import { Linking, Share } from 'react-native';
|
2022-09-30 14:50:33 +00:00
|
|
|
import FastImage from 'react-native-fast-image';
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2022-02-02 18:27:10 +00:00
|
|
|
import { appStart } from '../../actions/app';
|
|
|
|
import { logout } from '../../actions/login';
|
|
|
|
import { selectServerRequest } from '../../actions/server';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../containers/HeaderButton';
|
2020-10-30 13:59:44 +00:00
|
|
|
import * as List from '../../containers/List';
|
2022-02-02 18:27:10 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
|
|
|
import StatusBar from '../../containers/StatusBar';
|
|
|
|
import { LISTENER } from '../../containers/Toast';
|
2022-09-30 14:50:33 +00:00
|
|
|
import { RootEnum } from '../../definitions';
|
2019-06-11 14:01:40 +00:00
|
|
|
import I18n from '../../i18n';
|
2022-09-30 14:50:33 +00:00
|
|
|
import { APP_STORE_LINK, FDROID_MARKET_LINK, isFDroidBuild, LICENSE_LINK, PLAY_MARKET_LINK } from '../../lib/constants';
|
2022-02-02 18:27:10 +00:00
|
|
|
import database from '../../lib/database';
|
2022-09-30 14:50:33 +00:00
|
|
|
import { useAppSelector } from '../../lib/hooks';
|
|
|
|
import { clearCache } from '../../lib/methods';
|
|
|
|
import { deleteAllAudioFiles } from '../../lib/methods/audioFile';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { getDeviceModel, getReadableVersion, isAndroid } from '../../lib/methods/helpers';
|
|
|
|
import EventEmitter from '../../lib/methods/helpers/events';
|
|
|
|
import { showConfirmationAlert, showErrorAlert } from '../../lib/methods/helpers/info';
|
|
|
|
import { events, logEvent } from '../../lib/methods/helpers/log';
|
|
|
|
import openLink from '../../lib/methods/helpers/openLink';
|
|
|
|
import { onReviewPress } from '../../lib/methods/helpers/review';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../../lib/services';
|
2022-09-30 14:50:33 +00:00
|
|
|
import { getUserSelector } from '../../selectors/login';
|
|
|
|
import { SettingsStackParamList } from '../../stacks/types';
|
|
|
|
import { useTheme } from '../../theme';
|
|
|
|
import SidebarView from '../SidebarView';
|
2020-08-24 12:24:10 +00:00
|
|
|
|
2022-05-10 21:19:06 +00:00
|
|
|
type TLogScreenName = 'SE_GO_LANGUAGE' | 'SE_GO_DEFAULTBROWSER' | 'SE_GO_THEME' | 'SE_GO_PROFILE' | 'SE_GO_SECURITYPRIVACY';
|
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
const SettingsView = (): React.ReactElement => {
|
|
|
|
const { colors, theme } = useTheme();
|
|
|
|
const navigation = useNavigation<StackNavigationProp<SettingsStackParamList, 'SettingsView'>>();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const isMasterDetail = useAppSelector(state => state.app.isMasterDetail);
|
|
|
|
const userId = useAppSelector(state => getUserSelector(state).id);
|
|
|
|
const { server, version } = useAppSelector(state => state.server);
|
2021-10-20 17:56:52 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
useLayoutEffect(() => {
|
|
|
|
navigation.setOptions({
|
|
|
|
headerLeft: () =>
|
|
|
|
isMasterDetail ? (
|
|
|
|
<HeaderButton.CloseModal navigation={navigation} testID='settings-view-close' />
|
|
|
|
) : (
|
|
|
|
<HeaderButton.Drawer navigation={navigation} testID='settings-view-drawer' />
|
|
|
|
),
|
|
|
|
title: I18n.t('Settings')
|
|
|
|
});
|
|
|
|
}, [navigation, isMasterDetail]);
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
const checkCookiesAndLogout = async () => {
|
2020-08-25 20:04:18 +00:00
|
|
|
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 {
|
2022-09-30 14:50:33 +00:00
|
|
|
const userRecord = await usersCollection.find(userId);
|
2021-07-05 18:21:15 +00:00
|
|
|
if (userRecord.isFromWebView) {
|
2020-08-25 20:04:18 +00:00
|
|
|
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'),
|
2021-09-13 20:41:05 +00:00
|
|
|
onPress: async () => {
|
2020-08-25 20:04:18 +00:00
|
|
|
await CookieManager.clearAll(true);
|
2022-02-02 18:27:10 +00:00
|
|
|
dispatch(logout());
|
2020-08-25 20:04:18 +00:00
|
|
|
},
|
|
|
|
onCancel: () => {
|
2022-02-02 18:27:10 +00:00
|
|
|
dispatch(logout());
|
2020-08-25 20:04:18 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2022-02-02 18:27:10 +00:00
|
|
|
dispatch(logout());
|
2020-08-25 20:04:18 +00:00
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// Do nothing: user not found
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-08-25 20:04:18 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
const 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'),
|
2022-09-30 14:50:33 +00:00
|
|
|
onPress: checkCookiesAndLogout
|
2020-02-10 14:53:42 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
const 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'),
|
2021-09-13 20:41:05 +00:00
|
|
|
onPress: async () => {
|
2022-02-02 18:27:10 +00:00
|
|
|
dispatch(appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Clear_cache_loading') }));
|
2022-08-19 13:24:29 +00:00
|
|
|
await deleteAllAudioFiles(server);
|
2022-04-28 20:37:25 +00:00
|
|
|
await clearCache({ server });
|
2020-07-17 17:39:06 +00:00
|
|
|
await FastImage.clearMemoryCache();
|
|
|
|
await FastImage.clearDiskCache();
|
2022-04-28 20:37:25 +00:00
|
|
|
Services.disconnect();
|
2022-02-02 18:27:10 +00:00
|
|
|
dispatch(selectServerRequest(server));
|
2020-02-10 14:53:42 +00:00
|
|
|
}
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-02-05 15:12:40 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
const navigateToScreen = (screen: keyof SettingsStackParamList) => {
|
2022-05-10 21:19:06 +00:00
|
|
|
const screenName = screen.replace('View', '').toUpperCase();
|
|
|
|
logEvent(events[`SE_GO_${screenName}` as TLogScreenName]);
|
2020-02-19 20:52:05 +00:00
|
|
|
navigation.navigate(screen);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
const sendEmail = async () => {
|
2020-07-30 19:51:13 +00:00
|
|
|
logEvent(events.SE_CONTACT_US);
|
2022-05-10 21:19:06 +00:00
|
|
|
const subject = encodeURI('Rocket.Chat Mobile App Support');
|
2019-06-11 14:01:40 +00:00
|
|
|
const email = encodeURI('support@rocket.chat');
|
|
|
|
const description = encodeURI(`
|
2021-09-13 20:41:05 +00:00
|
|
|
version: ${getReadableVersion}
|
|
|
|
device: ${getDeviceModel}
|
2019-06-11 14:01:40 +00:00
|
|
|
`);
|
2018-06-13 01:33:00 +00:00
|
|
|
try {
|
2021-09-13 20:41:05 +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
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
const 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 });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-08-08 18:28:51 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
const saveToClipboard = async (content: string) => {
|
|
|
|
await Clipboard.setString(content);
|
|
|
|
EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') });
|
|
|
|
};
|
|
|
|
|
|
|
|
const copyServerVersion = () => {
|
2022-02-02 18:27:10 +00:00
|
|
|
const vers = version as string;
|
|
|
|
logEvent(events.SE_COPY_SERVER_VERSION, { serverVersion: vers });
|
2022-09-30 14:50:33 +00:00
|
|
|
saveToClipboard(vers);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-12-17 14:12:55 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
const copyAppVersion = () => {
|
2020-07-30 19:51:13 +00:00
|
|
|
logEvent(events.SE_COPY_APP_VERSION, { appVersion: getReadableVersion });
|
2022-09-30 14:50:33 +00:00
|
|
|
saveToClipboard(getReadableVersion);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-12-17 14:12:55 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
const onPressLicense = () => {
|
2020-07-30 19:51:13 +00:00
|
|
|
logEvent(events.SE_READ_LICENSE);
|
2019-12-04 16:39:53 +00:00
|
|
|
openLink(LICENSE_LINK, theme);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-06-11 14:01:40 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
return (
|
|
|
|
<SafeAreaView testID='settings-view'>
|
|
|
|
<StatusBar />
|
|
|
|
<List.Container>
|
|
|
|
{isMasterDetail ? (
|
|
|
|
<>
|
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<SidebarView />
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item title='Display' onPress={() => navigateToScreen('DisplayPrefsView')} showActionIndicator />
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Profile'
|
|
|
|
onPress={() => navigateToScreen('ProfileView')}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-profile'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item title='Contact_us' onPress={sendEmail} showActionIndicator testID='settings-view-contact' />
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Language'
|
|
|
|
onPress={() => navigateToScreen('LanguageView')}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-view-language'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
{!isFDroidBuild ? (
|
2019-11-25 20:01:17 +00:00
|
|
|
<>
|
2022-09-30 14:50:33 +00:00
|
|
|
<List.Item title='Review_this_app' showActionIndicator onPress={onReviewPress} testID='settings-view-review-app' />
|
2019-11-25 20:01:17 +00:00
|
|
|
</>
|
|
|
|
) : null}
|
2022-09-30 14:50:33 +00:00
|
|
|
<List.Separator />
|
|
|
|
<List.Item title='Share_this_app' showActionIndicator onPress={shareApp} testID='settings-view-share-app' />
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Default_browser'
|
|
|
|
showActionIndicator
|
|
|
|
onPress={() => navigateToScreen('DefaultBrowserView')}
|
|
|
|
testID='settings-view-default-browser'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Theme'
|
|
|
|
showActionIndicator
|
|
|
|
onPress={() => navigateToScreen('ThemeView')}
|
|
|
|
testID='settings-view-theme'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Security_and_privacy'
|
|
|
|
showActionIndicator
|
|
|
|
onPress={() => navigateToScreen('SecurityPrivacyView')}
|
|
|
|
testID='settings-view-security-privacy'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item title='License' onPress={onPressLicense} showActionIndicator testID='settings-view-license' />
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title={I18n.t('Version_no', { version: getReadableVersion })}
|
|
|
|
onPress={copyAppVersion}
|
|
|
|
testID='settings-view-version'
|
|
|
|
translateTitle={false}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title={I18n.t('Server_version', { version })}
|
|
|
|
onPress={copyServerVersion}
|
|
|
|
subtitle={`${server.split('//')[1]}`}
|
|
|
|
testID='settings-view-server-version'
|
|
|
|
translateTitle={false}
|
|
|
|
translateSubtitle={false}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Clear_cache'
|
|
|
|
testID='settings-view-clear-cache'
|
|
|
|
onPress={handleClearCache}
|
|
|
|
showActionIndicator
|
|
|
|
color={colors.dangerColor}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Logout'
|
|
|
|
testID='settings-logout'
|
|
|
|
onPress={handleLogout}
|
|
|
|
showActionIndicator
|
|
|
|
color={colors.dangerColor}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
</List.Container>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
};
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2022-09-30 14:50:33 +00:00
|
|
|
export default SettingsView;
|