Ask confirm before delete account (#1910)

* 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
pull/1921/head
Audric Ackermann 4 years ago committed by GitHub
parent 25453ee807
commit ab75f945ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -662,6 +662,7 @@ function getDefaultSQLKey() {
} }
async function removeDB() { async function removeDB() {
// this don't remove attachments and stuff like that...
const userDir = await getRealPath(app.getPath('userData')); const userDir = await getRealPath(app.getPath('userData'));
await sql.removeDB(userDir); await sql.removeDB(userDir);

@ -21,9 +21,6 @@ window.getEnvironment = () => config.environment;
window.getVersion = () => config.version; window.getVersion = () => config.version;
window.getAppInstance = () => config.appInstance; window.getAppInstance = () => config.appInstance;
const electron = require('electron');
const ipc = electron.ipcRenderer;
const { SessionPasswordPrompt } = require('./ts/components/session/SessionPasswordPrompt'); const { SessionPasswordPrompt } = require('./ts/components/session/SessionPasswordPrompt');
window.Signal = { window.Signal = {
@ -34,21 +31,11 @@ window.Signal = {
window.Signal.Logs = require('./js/modules/logs'); window.Signal.Logs = require('./js/modules/logs');
window.resetDatabase = () => { window.clearLocalData = async () => {
window.log.info('reset database'); window.log.info('reset database');
ipcRenderer.send('resetDatabase'); ipcRenderer.send('resetDatabase');
}; };
window.restart = () => {
window.log.info('restart');
ipc.send('restart');
};
window.clearLocalData = async () => {
window.resetDatabase();
window.restart();
};
window.onLogin = passPhrase => window.onLogin = passPhrase =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
ipcRenderer.once('password-window-login-response', (event, error) => { ipcRenderer.once('password-window-login-response', (event, error) => {

@ -156,11 +156,6 @@ window.restart = () => {
ipc.send('restart'); ipc.send('restart');
}; };
window.resetDatabase = () => {
window.log.info('reset database');
ipc.send('resetDatabase');
};
ipc.on('mediaPermissionsChanged', () => { ipc.on('mediaPermissionsChanged', () => {
Whisper.events.trigger('mediaPermissionsChanged'); Whisper.events.trigger('mediaPermissionsChanged');
}); });

@ -11,7 +11,7 @@ import { SessionSpinner } from '../session/SessionSpinner';
import { SessionWrapperModal } from '../session/SessionWrapperModal'; import { SessionWrapperModal } from '../session/SessionWrapperModal';
const deleteDbLocally = async () => { const deleteDbLocally = async () => {
window?.log?.info('configuration message sent successfully. Deleting everything'); window?.log?.info('last message sent successfully. Deleting everything');
window.persistStore?.purge(); window.persistStore?.purge();
await window.Signal.Logs.deleteAll(); await window.Signal.Logs.deleteAll();
await window.Signal.Data.removeAll(); await window.Signal.Data.removeAll();
@ -128,15 +128,13 @@ async function deleteEverythingAndNetworkData() {
export const DeleteAccountModal = () => { export const DeleteAccountModal = () => {
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [deleteDeviceOnly, setDeleteDeviceOnly] = useState(false);
const [deleteEverythingWithNetwork, setDeleteEverythingWithNetwork] = useState(false);
const dispatch = useDispatch(); const dispatch = useDispatch();
const onDeleteEverythingLocallyOnly = () => { const onDeleteEverythingLocallyOnly = async () => {
dispatch( if (!isLoading) {
updateConfirmModal({
message: window.i18n('areYouSureDeleteDeviceOnly'),
okText: window.i18n('iAmSure'),
okTheme: SessionButtonColor.Danger,
onClickOk: async () => {
setIsLoading(true); setIsLoading(true);
try { try {
window.log.warn('Deleting everything on device but keeping network data'); window.log.warn('Deleting everything on device but keeping network data');
@ -147,20 +145,10 @@ export const DeleteAccountModal = () => {
} finally { } finally {
setIsLoading(false); setIsLoading(false);
} }
}, }
onClickClose: () => {
window.inboxStore?.dispatch(updateConfirmModal(null));
},
})
);
}; };
const onDeleteEverythingAndNetworkData = () => { const onDeleteEverythingAndNetworkData = async () => {
dispatch( if (!isLoading) {
updateConfirmModal({
message: window.i18n('areYouSureDeleteEntireAccount'),
okText: window.i18n('iAmSure'),
okTheme: SessionButtonColor.Danger,
onClickOk: async () => {
setIsLoading(true); setIsLoading(true);
try { try {
window.log.warn('Deleting everything including network data'); window.log.warn('Deleting everything including network data');
@ -170,19 +158,14 @@ export const DeleteAccountModal = () => {
} finally { } finally {
setIsLoading(false); setIsLoading(false);
} }
}, }
onClickClose: () => {
window.inboxStore?.dispatch(updateConfirmModal(null));
},
})
);
}; };
/** /**
* Performs specified on close action then removes the modal. * Performs specified on close action then removes the modal.
*/ */
const onClickCancelHandler = useCallback(() => { const onClickCancelHandler = useCallback(() => {
window.inboxStore?.dispatch(updateDeleteAccountModal(null)); dispatch(updateDeleteAccountModal(null));
}, []); }, []);
return ( return (
@ -209,17 +192,65 @@ export const DeleteAccountModal = () => {
<SessionButton <SessionButton
text={window.i18n('entireAccount')} text={window.i18n('entireAccount')}
buttonColor={SessionButtonColor.Danger} buttonColor={SessionButtonColor.Danger}
onClick={onDeleteEverythingAndNetworkData} onClick={() => {
disabled={isLoading} setDeleteEverythingWithNetwork(true);
}}
disabled={deleteEverythingWithNetwork || deleteDeviceOnly}
/> />
<SessionButton <SessionButton
text={window.i18n('deviceOnly')} text={window.i18n('deviceOnly')}
buttonColor={SessionButtonColor.Primary} buttonColor={SessionButtonColor.Primary}
onClick={onDeleteEverythingLocallyOnly} 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} disabled={isLoading}
/> />
</div> </div>
)}
<SessionSpinner loading={isLoading} /> <SessionSpinner loading={isLoading} />
</div> </div>

@ -71,7 +71,7 @@ const SignUpSessionIDShown = (props: { continueSignUp: () => void }) => {
</div> </div>
</Flex> </Flex>
<SessionIdEditable editable={false} placeholder={undefined} /> <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} /> <ContinueSignUpButton continueSignUp={props.continueSignUp} />
<TermsAndConditions /> <TermsAndConditions />
</div> </div>

1
ts/window.d.ts vendored

@ -51,7 +51,6 @@ declare global {
lokiSnodeAPI: LokiSnodeAPI; lokiSnodeAPI: LokiSnodeAPI;
onLogin: any; onLogin: any;
persistStore?: Persistor; persistStore?: Persistor;
resetDatabase: any;
restart: any; restart: any;
getSeedNodeList: () => Array<any> | undefined; getSeedNodeList: () => Array<any> | undefined;
setPassword: any; setPassword: any;

Loading…
Cancel
Save