Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3393993
D14059.id46102.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D14059.id46102.diff
View Options
diff --git a/native/backup/backup-handler.js b/native/backup/backup-handler.js
--- a/native/backup/backup-handler.js
+++ b/native/backup/backup-handler.js
@@ -2,10 +2,13 @@
import * as React from 'react';
+import { createUserKeysBackupActionTypes } from 'lib/actions/backup-actions.js';
import { useCheckIfPrimaryDevice } from 'lib/hooks/primary-device-hooks.js';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
import { getMessageForException } from 'lib/utils/errors.js';
+import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
+import { useClientBackup } from './use-client-backup.js';
import { commCoreModule } from '../native-modules.js';
import { useSelector } from '../redux/redux-utils.js';
import Alert from '../utils/alert.js';
@@ -19,6 +22,13 @@
);
const canPerformBackupOperation = loggedIn && !isBackground;
const checkIfPrimaryDevice = useCheckIfPrimaryDevice();
+ const latestBackupInfo = useSelector(
+ state => state.backupStore.latestBackupInfo,
+ );
+ const dispatchActionPromise = useDispatchActionPromise();
+ const { createUserKeysBackup } = useClientBackup();
+ const backupUploadInProgress = React.useRef<boolean>(false);
+ const [handlerStarted, setHandlerStarted] = React.useState(false);
React.useEffect(() => {
if (!staffCanSee) {
@@ -31,17 +41,22 @@
return;
}
- if (canPerformBackupOperation) {
+ if (!handlerStarted && canPerformBackupOperation) {
try {
commCoreModule.startBackupHandler();
+ setHandlerStarted(true);
} catch (err) {
const message = getMessageForException(err) ?? 'unknown error';
Alert.alert('Error starting backup handler', message);
console.log('Error starting backup handler:', message);
}
- } else {
+ }
+
+ if (handlerStarted && !canPerformBackupOperation) {
try {
+ console.log('stopping');
commCoreModule.stopBackupHandler();
+ setHandlerStarted(false);
} catch (err) {
const message = getMessageForException(err) ?? 'unknown error';
Alert.alert('Error stopping backup handler', message);
@@ -55,6 +70,47 @@
isBackground,
checkIfPrimaryDevice,
canPerformBackupOperation,
+ handlerStarted,
+ ]);
+
+ React.useEffect(() => {
+ if (
+ !staffCanSee ||
+ !canPerformBackupOperation ||
+ !handlerStarted ||
+ backupUploadInProgress.current ||
+ !!latestBackupInfo
+ ) {
+ return;
+ }
+
+ void (async () => {
+ backupUploadInProgress.current = true;
+ const isPrimaryDevice = await checkIfPrimaryDevice();
+ if (!isPrimaryDevice) {
+ backupUploadInProgress.current = false;
+ return;
+ }
+
+ try {
+ const promise = createUserKeysBackup();
+ void dispatchActionPromise(createUserKeysBackupActionTypes, promise);
+ await promise;
+ } catch (err) {
+ const message = getMessageForException(err) ?? 'unknown error';
+ Alert.alert('Error creating User Keys backup', message);
+ console.log('Error creating User Keys backup:', message);
+ }
+ backupUploadInProgress.current = false;
+ })();
+ }, [
+ canPerformBackupOperation,
+ checkIfPrimaryDevice,
+ createUserKeysBackup,
+ dispatchActionPromise,
+ handlerStarted,
+ latestBackupInfo,
+ staffCanSee,
]);
return null;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 1, 4:49 PM (21 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2605031
Default Alt Text
D14059.id46102.diff (3 KB)
Attached To
Mode
D14059: [native] upload User Keys backup when user is staff
Attached
Detach File
Event Timeline
Log In to Comment