diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -65,6 +65,7 @@ UpdateUserAvatarRequest, UpdateUserAvatarResponse, } from '../types/avatar-types.js'; +import type { LocalLatestBackupInfo } from '../types/backup-types.js'; import type { RawEntryInfo, CalendarQuery } from '../types/entry-types.js'; import type { IdentityAuthResult } from '../types/identity-service-types.js'; import type { @@ -1493,9 +1494,10 @@ failed: 'RESTORE_USER_FAILED', }); -export type RestoreUserResult = $ReadOnly<{ +export type RestoreProtocolResult = $ReadOnly<{ ...IdentityAuthResult, ...SetPeerDeviceListsPayload, + +latestBackupInfo: LocalLatestBackupInfo, }>; export { diff --git a/lib/reducers/backup-reducer.js b/lib/reducers/backup-reducer.js --- a/lib/reducers/backup-reducer.js +++ b/lib/reducers/backup-reducer.js @@ -4,7 +4,10 @@ createUserDataBackupActionTypes, createUserKeysBackupActionTypes, } from '../actions/backup-actions.js'; -import { changeIdentityUserPasswordActionTypes } from '../actions/user-actions.js'; +import { + changeIdentityUserPasswordActionTypes, + restoreUserActionTypes, +} from '../actions/user-actions.js'; import type { BackupStore } from '../types/backup-types.js'; import type { BaseAction } from '../types/redux-types.js'; @@ -12,7 +15,13 @@ store: BackupStore, action: BaseAction, ): BackupStore { - if (action.type === createUserKeysBackupActionTypes.success) { + if (action.type === restoreUserActionTypes.success) { + const { latestBackupInfo } = action.payload; + return { + ...store, + latestBackupInfo, + }; + } else if (action.type === createUserKeysBackupActionTypes.success) { const latestBackupInfo = action.payload; return { ...store, diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -178,7 +178,7 @@ ProcessHoldersFailedPayload, ProcessHoldersFinishedPayload, } from '../actions/holder-actions.js'; -import type { RestoreUserResult } from '../actions/user-actions.js'; +import type { RestoreProtocolResult } from '../actions/user-actions.js'; import type { UpdateConnectionStatusPayload, SetLateResponsePayload, @@ -1659,7 +1659,7 @@ } | { +type: 'RESTORE_USER_SUCCESS', - +payload: RestoreUserResult, + +payload: RestoreProtocolResult, +loadingInfo: LoadingInfo, } | { diff --git a/native/account/restore.js b/native/account/restore.js --- a/native/account/restore.js +++ b/native/account/restore.js @@ -5,7 +5,7 @@ import { restoreUserActionTypes, - type RestoreUserResult, + type RestoreProtocolResult, } from 'lib/actions/user-actions.js'; import { useUserDataRestore } from 'lib/backup/use-user-data-restore.js'; import { logTypes, useDebugLogs } from 'lib/components/debug-logs-context.js'; @@ -42,7 +42,7 @@ secret: string, // social proof for SIWE restore siweSocialProof?: SignedMessage, -) => Promise { +) => Promise { const identityContext = React.useContext(IdentityClientContext); invariant(identityContext, 'identity context not set'); const { identityClient } = identityContext; @@ -61,7 +61,7 @@ userIdentifier: string, secret: string, siweSocialProof?: SignedMessage, - ): Promise => { + ): Promise => { //1. Runs Key Generation const { olmAPI } = getConfig(); await olmAPI.initializeCryptoAccount(); @@ -124,7 +124,7 @@ // - send device list to Comm // - create User Keys backup // - get new CSAT - const result = await restoreUser( + const { backupID: newBackupID, ...authResult } = await restoreUser( userID, signedDeviceList, siweSocialProof, @@ -145,15 +145,18 @@ const authMetadata = { userID, deviceID: primaryDeviceID, - accessToken: result.accessToken, + accessToken: authResult.accessToken, }; const { usersDevicesPlatformDetails } = await rawGetDeviceListsForUsers( authMetadata, [userID], ); + const newBackupInfo = { + backupID: newBackupID, + timestamp: Date.now(), + }; //8. Return the result - const { backupID: _, ...authResult } = result; return { ...authResult, preRequestUserState, @@ -161,6 +164,7 @@ usersPlatformDetails: { [userID]: usersDevicesPlatformDetails[userID], }, + latestBackupInfo: newBackupInfo, }; }, [