Add unlink step to existing UI flow
This commit is contained in:
parent
38f532cdda
commit
09bd95228d
2 changed files with 28 additions and 0 deletions
|
@ -7,6 +7,17 @@ import { deleteAllLogs } from '../util/deleteAllLogs';
|
|||
import * as Errors from '../types/errors';
|
||||
|
||||
export async function deleteAllData(): Promise<void> {
|
||||
try {
|
||||
// This might fail if websocket closes before we receive the response, while
|
||||
// still unlinking the device on the server.
|
||||
await window.textsecure.server?.unlink();
|
||||
} catch (error) {
|
||||
log.error(
|
||||
'Something went wrong unlinking device:',
|
||||
Errors.toLogFormat(error)
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
await deleteAllLogs();
|
||||
|
||||
|
|
|
@ -578,6 +578,7 @@ const URL_CALLS = {
|
|||
challenge: 'v1/challenge',
|
||||
config: 'v1/config',
|
||||
deliveryCert: 'v1/certificate/delivery',
|
||||
devices: 'v1/devices',
|
||||
directoryAuthV2: 'v2/directory/auth',
|
||||
discovery: 'v1/discovery',
|
||||
getGroupAvatarUpload: 'v1/groups/avatar/form',
|
||||
|
@ -647,6 +648,7 @@ const WEBSOCKET_CALLS = new Set<keyof typeof URL_CALLS>([
|
|||
'getGroupCredentials',
|
||||
|
||||
// Devices
|
||||
'devices',
|
||||
'linkDevice',
|
||||
'registerCapabilities',
|
||||
|
||||
|
@ -1327,6 +1329,7 @@ export type WebAPIType = {
|
|||
abortSignal: AbortSignal
|
||||
) => Promise<null | linkPreviewFetch.LinkPreviewImage>;
|
||||
linkDevice: (options: LinkDeviceOptionsType) => Promise<LinkDeviceResultType>;
|
||||
unlink: () => Promise<void>;
|
||||
makeProxiedRequest: (
|
||||
targetUrl: string,
|
||||
options?: ProxiedRequestOptionsType
|
||||
|
@ -1806,6 +1809,7 @@ export function initialize({
|
|||
setBackupSignatureKey,
|
||||
setPhoneNumberDiscoverability,
|
||||
startRegistration,
|
||||
unlink,
|
||||
unregisterRequestHandler,
|
||||
updateDeviceName,
|
||||
uploadAvatar,
|
||||
|
@ -2697,6 +2701,19 @@ export function initialize({
|
|||
);
|
||||
}
|
||||
|
||||
async function unlink() {
|
||||
if (!username) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [, deviceId] = username.split('.');
|
||||
await _ajax({
|
||||
call: 'devices',
|
||||
httpType: 'DELETE',
|
||||
urlParameters: `/${deviceId}`,
|
||||
});
|
||||
}
|
||||
|
||||
async function updateDeviceName(deviceName: string) {
|
||||
await _ajax({
|
||||
call: 'updateDeviceName',
|
||||
|
|
Loading…
Reference in a new issue