Skip to content

Commit

Permalink
[native] VersionSupportedChecker component
Browse files Browse the repository at this point in the history
Summary:
this component calls the identity service and displays an alert if the client code version is not supported by the identity service.

Depends on D9813

Test Plan: built the native app with an unsupported code version and saw the alert. built with the actual code version and no alert was displayed.

Reviewers: ashoat, ginsu

Reviewed By: ashoat

Subscribers: inka, tomek, wyilio

Differential Revision: https://phab.comm.dev/D9814
  • Loading branch information
vdhanan committed Nov 21, 2023
1 parent 18ec318 commit 14b32af
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 31 deletions.
10 changes: 3 additions & 7 deletions native/account/log-in-panel.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { NavContext } from '../navigation/navigation-context.js';
import { useSelector } from '../redux/redux-utils.js';
import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js';
import type { KeyPressEvent } from '../types/react-native.js';
import { AppOutOfDateAlertDetails } from '../utils/alert-messages.js';
import Alert from '../utils/alert.js';
import { useInitialNotificationsEncryptedMessage } from '../utils/crypto-utils.js';
import type { StateContainer } from '../utils/state-container.js';
Expand Down Expand Up @@ -270,14 +271,9 @@ class LogInPanel extends React.PureComponent<Props> {
{ cancelable: false },
);
} else if (e.message === 'client_version_unsupported') {
const app = Platform.select({
ios: 'App Store',
android: 'Play Store',
});
Alert.alert(
'App out of date',
'Your app version is pretty old, and the server doesn’t know how ' +
`to speak to it anymore. Please use the ${app} app to update!`,
AppOutOfDateAlertDetails.title,
AppOutOfDateAlertDetails.message,
[{ text: 'OK', onPress: this.onAppOutOfDateAlertAcknowledged }],
{ cancelable: false },
);
Expand Down
10 changes: 3 additions & 7 deletions native/account/register-panel.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { NavContext } from '../navigation/navigation-context.js';
import { useSelector } from '../redux/redux-utils.js';
import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js';
import type { KeyPressEvent } from '../types/react-native.js';
import { AppOutOfDateAlertDetails } from '../utils/alert-messages.js';
import Alert from '../utils/alert.js';
import { useInitialNotificationsEncryptedMessage } from '../utils/crypto-utils.js';
import { type StateContainer } from '../utils/state-container.js';
Expand Down Expand Up @@ -379,14 +380,9 @@ class RegisterPanel extends React.PureComponent<Props, State> {
{ cancelable: false },
);
} else if (e.message === 'client_version_unsupported') {
const app = Platform.select({
ios: 'App Store',
android: 'Play Store',
});
Alert.alert(
'App out of date',
'Your app version is pretty old, and the server doesn’t know how ' +
`to speak to it anymore. Please use the ${app} app to update!`,
AppOutOfDateAlertDetails.title,
AppOutOfDateAlertDetails.message,
[{ text: 'OK', onPress: this.onAppOutOfDateAlertAcknowledged }],
{ cancelable: false },
);
Expand Down
11 changes: 3 additions & 8 deletions native/account/registration/registration-server-call.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @flow

import * as React from 'react';
import { Platform } from 'react-native';
import { useDispatch } from 'react-redux';

import { setDataLoadedActionType } from 'lib/actions/client-db-store-actions.js';
Expand All @@ -25,6 +24,7 @@ import {
import { NavContext } from '../../navigation/navigation-context.js';
import { useSelector } from '../../redux/redux-utils.js';
import { nativeLogInExtraInfoSelector } from '../../selectors/account-selectors.js';
import { AppOutOfDateAlertDetails } from '../../utils/alert-messages.js';
import Alert from '../../utils/alert.js';
import { setNativeCredentials } from '../native-credentials.js';
import { useSIWEServerCall } from '../siwe-hooks.js';
Expand Down Expand Up @@ -103,14 +103,9 @@ function useRegistrationServerCall(): RegistrationServerCallInput => Promise<voi
'An account with that username already exists',
);
} else if (e.message === 'client_version_unsupported') {
const app = Platform.select({
ios: 'App Store',
android: 'Play Store',
});
Alert.alert(
'App out of date',
'Your app version is pretty old, and the server doesn’t know how ' +
`to speak to it anymore. Please use the ${app} app to update!`,
AppOutOfDateAlertDetails.title,
AppOutOfDateAlertDetails.message,
);
} else {
Alert.alert('Unknown error', 'Uhh... try again?');
Expand Down
65 changes: 65 additions & 0 deletions native/components/version-supported.react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// @flow

import * as React from 'react';

import { useLogOut, logOutActionTypes } from 'lib/actions/user-actions.js';
import { preRequestUserStateForSingleKeyserverSelector } from 'lib/selectors/account-selectors.js';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
import { useDispatchActionPromise } from 'lib/utils/action-utils.js';
import { ashoatKeyserverID } from 'lib/utils/validation-utils.js';

import { commRustModule } from '../native-modules.js';
import { useSelector } from '../redux/redux-utils.js';
import { AppOutOfDateAlertDetails } from '../utils/alert-messages.js';
import Alert from '../utils/alert.js';

function VersionSupportedChecker(): React.Node {
const hasRun = React.useRef(false);

const loggedIn = useSelector(isLoggedIn);
const preRequestUserState = useSelector(
preRequestUserStateForSingleKeyserverSelector(ashoatKeyserverID),
);
const dispatchActionPromise = useDispatchActionPromise();
const callLogOut = useLogOut();

const onUsernameAlertAcknowledged = React.useCallback(() => {
if (loggedIn) {
dispatchActionPromise(logOutActionTypes, callLogOut(preRequestUserState));
}
}, [callLogOut, dispatchActionPromise, loggedIn, preRequestUserState]);

const checkVersionSupport = React.useCallback(async () => {
try {
const isVersionSupported = await commRustModule.versionSupported();
if (isVersionSupported) {
return;
}
Alert.alert(
AppOutOfDateAlertDetails.title,
AppOutOfDateAlertDetails.message,
[
{
text: 'OK',
onPress: onUsernameAlertAcknowledged,
},
],
{ cancelable: false },
);
} catch (error) {
console.log('Error checking version:', error);
}
}, [onUsernameAlertAcknowledged]);

React.useEffect(() => {
if (hasRun.current) {
return;
}
hasRun.current = true;
checkVersionSupport();
}, [checkVersionSupport]);

return null;
}

export default VersionSupportedChecker;
16 changes: 7 additions & 9 deletions native/redux/redux-setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import { AppState as NativeAppState, Platform, Alert } from 'react-native';
import { AppState as NativeAppState, Alert } from 'react-native';
import { createStore, applyMiddleware, type Store, compose } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import thunk from 'redux-thunk';
Expand Down Expand Up @@ -46,6 +46,7 @@ import type { AppState } from './state-types.js';
import { getGlobalNavContext } from '../navigation/icky-global.js';
import { activeMessageListSelector } from '../navigation/nav-selectors.js';
import reactotron from '../reactotron.js';
import { AppOutOfDateAlertDetails } from '../utils/alert-messages.js';
import { isStaffRelease } from '../utils/staff-utils.js';
import { setCustomServer, getDevServerHostname } from '../utils/url-utils.js';

Expand Down Expand Up @@ -266,16 +267,13 @@ function sessionInvalidationAlert(payload: SetSessionPayload) {
return;
}
if (payload.error === 'client_version_unsupported') {
const app = Platform.select({
ios: 'App Store',
android: 'Play Store',
});
Alert.alert(
'App out of date',
'Your app version is pretty old, and the server doesn’t know how to ' +
`speak to it anymore. Please use the ${app} app to update!`,
AppOutOfDateAlertDetails.title,
AppOutOfDateAlertDetails.message,
[{ text: 'OK' }],
{ cancelable: true },
{
cancelable: true,
},
);
} else {
Alert.alert(
Expand Down
2 changes: 2 additions & 0 deletions native/root.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import ChatContextProvider from './chat/chat-context-provider.react.js';
import MessageEditingContextProvider from './chat/message-editing-context-provider.react.js';
import { FeatureFlagsProvider } from './components/feature-flags-provider.react.js';
import PersistedStateGate from './components/persisted-state-gate.js';
import VersionSupportedChecker from './components/version-supported.react.js';
import ConnectedStatusBar from './connected-status-bar.react.js';
import { SQLiteDataHandler } from './data/sqlite-data-handler.js';
import ErrorBoundary from './error-boundary.react.js';
Expand Down Expand Up @@ -308,6 +309,7 @@ function Root() {
detectUnsupervisedBackgroundRef
}
/>
<VersionSupportedChecker />
</PersistedStateGate>
{navigation}
</RegistrationContextProvider>
Expand Down
20 changes: 20 additions & 0 deletions native/utils/alert-messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @flow

import { Platform } from 'react-native';

type AlertDetails = {
+title: string,
+message: string,
};

const platformStore = Platform.select({
ios: 'App Store',
android: 'Play Store',
});

export const AppOutOfDateAlertDetails: AlertDetails = {
title: 'App out of date',
message:
'Your app version is pretty old, and the server doesn’t know how ' +
`to speak to it anymore. Please use the ${platformStore} to update!`,
};

0 comments on commit 14b32af

Please sign in to comment.