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 @@ -1,5 +1,7 @@ // @flow +import React from 'React'; + import threadWatcher from '../shared/thread-watcher.js'; import type { LogOutResult, @@ -18,6 +20,7 @@ UpdateUserAvatarResponse, } from '../types/avatar-types.js'; import type { RawEntryInfo, CalendarQuery } from '../types/entry-types.js'; +import type { IdentityServiceClient } from '../types/identity-service-types'; import type { RawMessageInfo, MessageTruncationStatuses, @@ -149,6 +152,24 @@ return useKeyserverCall(deleteKeyserverAccount); } +const deleteIdentityAccountActionTypes = Object.freeze({ + started: 'DELETE_IDENTITY_ACCOUNT_STARTED', + success: 'DELETE_IDENTITY_ACCOUNT_SUCCESS', + failed: 'DELETE_IDENTITY_ACCOUNT_FAILED', +}); + +const deleteIdentityAccount = async ( + client: IdentityServiceClient, +): Promise => { + await client.deleteUser(); +}; + +function useDeleteIdentityAccount( + client: IdentityServiceClient, +): () => Promise { + return React.useCallback(() => deleteIdentityAccount(client), [client]); +} + const registerActionTypes = Object.freeze({ started: 'REGISTER_STARTED', success: 'REGISTER_SUCCESS', @@ -526,4 +547,6 @@ updateUserAvatar, resetUserStateActionType, setAccessTokenActionType, + deleteIdentityAccountActionTypes, + useDeleteIdentityAccount, }; diff --git a/lib/types/identity-service-types.js b/lib/types/identity-service-types.js --- a/lib/types/identity-service-types.js +++ b/lib/types/identity-service-types.js @@ -18,3 +18,8 @@ +oneTimeContentPrekey: ?string, +oneTimeNotifPrekey: ?string, }; + +export type IdentityServiceClient = { + +deleteUser: () => Promise, + ... +}; 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 @@ -229,6 +229,22 @@ +payload: LogOutResult, +loadingInfo: LoadingInfo, } + | { + +type: 'DELETE_IDENTITY_ACCOUNT_STARTED', + +payload?: void, + +loadingInfo: LoadingInfo, + } + | { + +type: 'DELETE_IDENTITY_ACCOUNT_FAILED', + +error: true, + +payload: Error, + +loadingInfo: LoadingInfo, + } + | { + +type: 'DELETE_IDENTITY_ACCOUNT_SUCCESS', + +payload: void, + +loadingInfo: LoadingInfo, + } | { +type: 'CREATE_LOCAL_ENTRY', +payload: RawEntryInfo,