Skip to content

Commit

Permalink
Ask confirm before delete account (#1910)
Browse files Browse the repository at this point in the history
* disable sending on enter while composing

Fixes #1899 #1497

* ask confirmation before deleting account

* fix app start delete db when passowrd error

* fix double dialog issue with delete account

* fixup login screen
  • Loading branch information
Bilb authored Sep 16, 2021
1 parent 25453ee commit ab75f94
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 72 deletions.
1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ function getDefaultSQLKey() {
}

async function removeDB() {
// this don't remove attachments and stuff like that...
const userDir = await getRealPath(app.getPath('userData'));
await sql.removeDB(userDir);

Expand Down
15 changes: 1 addition & 14 deletions password_preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ window.getEnvironment = () => config.environment;
window.getVersion = () => config.version;
window.getAppInstance = () => config.appInstance;

const electron = require('electron');

const ipc = electron.ipcRenderer;
const { SessionPasswordPrompt } = require('./ts/components/session/SessionPasswordPrompt');

window.Signal = {
Expand All @@ -34,21 +31,11 @@ window.Signal = {

window.Signal.Logs = require('./js/modules/logs');

window.resetDatabase = () => {
window.clearLocalData = async () => {
window.log.info('reset database');
ipcRenderer.send('resetDatabase');
};

window.restart = () => {
window.log.info('restart');
ipc.send('restart');
};

window.clearLocalData = async () => {
window.resetDatabase();
window.restart();
};

window.onLogin = passPhrase =>
new Promise((resolve, reject) => {
ipcRenderer.once('password-window-login-response', (event, error) => {
Expand Down
5 changes: 0 additions & 5 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ window.restart = () => {
ipc.send('restart');
};

window.resetDatabase = () => {
window.log.info('reset database');
ipc.send('resetDatabase');
};

ipc.on('mediaPermissionsChanged', () => {
Whisper.events.trigger('mediaPermissionsChanged');
});
Expand Down
133 changes: 82 additions & 51 deletions ts/components/dialog/DeleteAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SessionSpinner } from '../session/SessionSpinner';
import { SessionWrapperModal } from '../session/SessionWrapperModal';

const deleteDbLocally = async () => {
window?.log?.info('configuration message sent successfully. Deleting everything');
window?.log?.info('last message sent successfully. Deleting everything');
window.persistStore?.purge();
await window.Signal.Logs.deleteAll();
await window.Signal.Data.removeAll();
Expand Down Expand Up @@ -128,61 +128,44 @@ async function deleteEverythingAndNetworkData() {

export const DeleteAccountModal = () => {
const [isLoading, setIsLoading] = useState(false);
const [deleteDeviceOnly, setDeleteDeviceOnly] = useState(false);
const [deleteEverythingWithNetwork, setDeleteEverythingWithNetwork] = useState(false);

const dispatch = useDispatch();

const onDeleteEverythingLocallyOnly = () => {
dispatch(
updateConfirmModal({
message: window.i18n('areYouSureDeleteDeviceOnly'),
okText: window.i18n('iAmSure'),
okTheme: SessionButtonColor.Danger,
onClickOk: async () => {
setIsLoading(true);
try {
window.log.warn('Deleting everything on device but keeping network data');

await sendConfigMessageAndDeleteEverything();
} catch (e) {
window.log.warn(e);
} finally {
setIsLoading(false);
}
},
onClickClose: () => {
window.inboxStore?.dispatch(updateConfirmModal(null));
},
})
);
const onDeleteEverythingLocallyOnly = async () => {
if (!isLoading) {
setIsLoading(true);
try {
window.log.warn('Deleting everything on device but keeping network data');

await sendConfigMessageAndDeleteEverything();
} catch (e) {
window.log.warn(e);
} finally {
setIsLoading(false);
}
}
};
const onDeleteEverythingAndNetworkData = () => {
dispatch(
updateConfirmModal({
message: window.i18n('areYouSureDeleteEntireAccount'),
okText: window.i18n('iAmSure'),
okTheme: SessionButtonColor.Danger,
onClickOk: async () => {
setIsLoading(true);
try {
window.log.warn('Deleting everything including network data');
await deleteEverythingAndNetworkData();
} catch (e) {
window.log.warn(e);
} finally {
setIsLoading(false);
}
},
onClickClose: () => {
window.inboxStore?.dispatch(updateConfirmModal(null));
},
})
);
const onDeleteEverythingAndNetworkData = async () => {
if (!isLoading) {
setIsLoading(true);
try {
window.log.warn('Deleting everything including network data');
await deleteEverythingAndNetworkData();
} catch (e) {
window.log.warn(e);
} finally {
setIsLoading(false);
}
}
};

/**
* Performs specified on close action then removes the modal.
*/
const onClickCancelHandler = useCallback(() => {
window.inboxStore?.dispatch(updateDeleteAccountModal(null));
dispatch(updateDeleteAccountModal(null));
}, []);

return (
Expand All @@ -209,17 +192,65 @@ export const DeleteAccountModal = () => {
<SessionButton
text={window.i18n('entireAccount')}
buttonColor={SessionButtonColor.Danger}
onClick={onDeleteEverythingAndNetworkData}
disabled={isLoading}
onClick={() => {
setDeleteEverythingWithNetwork(true);
}}
disabled={deleteEverythingWithNetwork || deleteDeviceOnly}
/>

<SessionButton
text={window.i18n('deviceOnly')}
buttonColor={SessionButtonColor.Primary}
onClick={onDeleteEverythingLocallyOnly}
disabled={isLoading}
onClick={() => {
setDeleteDeviceOnly(true);
}}
disabled={deleteEverythingWithNetwork || deleteDeviceOnly}
/>
</div>
<SpacerLG />

{deleteEverythingWithNetwork && (
<SessionHtmlRenderer
tag="span"
className="session-confirm-main-message"
html={window.i18n('areYouSureDeleteEntireAccount')}
/>
)}

{deleteDeviceOnly && (
<SessionHtmlRenderer
tag="span"
className="session-confirm-main-message"
html={window.i18n('areYouSureDeleteDeviceOnly')}
/>
)}
<SpacerLG />

{(deleteDeviceOnly || deleteEverythingWithNetwork) && (
<div className="session-modal__button-group">
<SessionButton
text={window.i18n('iAmSure')}
buttonColor={SessionButtonColor.Danger}
onClick={() => {
if (deleteDeviceOnly) {
void onDeleteEverythingLocallyOnly();
} else if (deleteEverythingWithNetwork) {
void onDeleteEverythingAndNetworkData();
}
}}
disabled={isLoading}
/>

<SessionButton
text={window.i18n('cancel')}
buttonColor={SessionButtonColor.Primary}
onClick={() => {
dispatch(updateDeleteAccountModal(null));
}}
disabled={isLoading}
/>
</div>
)}

<SessionSpinner loading={isLoading} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion ts/components/session/registration/SignUpTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const SignUpSessionIDShown = (props: { continueSignUp: () => void }) => {
</div>
</Flex>
<SessionIdEditable editable={false} placeholder={undefined} />
<div className="session-description-long">{window.i18n('signupSessionIDBlurb')}</div>
<div className="session-description-long">{window.i18n('allUsersAreRandomly...')}</div>
<ContinueSignUpButton continueSignUp={props.continueSignUp} />
<TermsAndConditions />
</div>
Expand Down
1 change: 0 additions & 1 deletion ts/window.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ declare global {
lokiSnodeAPI: LokiSnodeAPI;
onLogin: any;
persistStore?: Persistor;
resetDatabase: any;
restart: any;
getSeedNodeList: () => Array<any> | undefined;
setPassword: any;
Expand Down

0 comments on commit ab75f94

Please sign in to comment.