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';
|
import * as Errors from '../types/errors';
|
||||||
|
|
||||||
export async function deleteAllData(): Promise<void> {
|
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 {
|
try {
|
||||||
await deleteAllLogs();
|
await deleteAllLogs();
|
||||||
|
|
||||||
|
|
|
@ -578,6 +578,7 @@ const URL_CALLS = {
|
||||||
challenge: 'v1/challenge',
|
challenge: 'v1/challenge',
|
||||||
config: 'v1/config',
|
config: 'v1/config',
|
||||||
deliveryCert: 'v1/certificate/delivery',
|
deliveryCert: 'v1/certificate/delivery',
|
||||||
|
devices: 'v1/devices',
|
||||||
directoryAuthV2: 'v2/directory/auth',
|
directoryAuthV2: 'v2/directory/auth',
|
||||||
discovery: 'v1/discovery',
|
discovery: 'v1/discovery',
|
||||||
getGroupAvatarUpload: 'v1/groups/avatar/form',
|
getGroupAvatarUpload: 'v1/groups/avatar/form',
|
||||||
|
@ -647,6 +648,7 @@ const WEBSOCKET_CALLS = new Set<keyof typeof URL_CALLS>([
|
||||||
'getGroupCredentials',
|
'getGroupCredentials',
|
||||||
|
|
||||||
// Devices
|
// Devices
|
||||||
|
'devices',
|
||||||
'linkDevice',
|
'linkDevice',
|
||||||
'registerCapabilities',
|
'registerCapabilities',
|
||||||
|
|
||||||
|
@ -1327,6 +1329,7 @@ export type WebAPIType = {
|
||||||
abortSignal: AbortSignal
|
abortSignal: AbortSignal
|
||||||
) => Promise<null | linkPreviewFetch.LinkPreviewImage>;
|
) => Promise<null | linkPreviewFetch.LinkPreviewImage>;
|
||||||
linkDevice: (options: LinkDeviceOptionsType) => Promise<LinkDeviceResultType>;
|
linkDevice: (options: LinkDeviceOptionsType) => Promise<LinkDeviceResultType>;
|
||||||
|
unlink: () => Promise<void>;
|
||||||
makeProxiedRequest: (
|
makeProxiedRequest: (
|
||||||
targetUrl: string,
|
targetUrl: string,
|
||||||
options?: ProxiedRequestOptionsType
|
options?: ProxiedRequestOptionsType
|
||||||
|
@ -1806,6 +1809,7 @@ export function initialize({
|
||||||
setBackupSignatureKey,
|
setBackupSignatureKey,
|
||||||
setPhoneNumberDiscoverability,
|
setPhoneNumberDiscoverability,
|
||||||
startRegistration,
|
startRegistration,
|
||||||
|
unlink,
|
||||||
unregisterRequestHandler,
|
unregisterRequestHandler,
|
||||||
updateDeviceName,
|
updateDeviceName,
|
||||||
uploadAvatar,
|
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) {
|
async function updateDeviceName(deviceName: string) {
|
||||||
await _ajax({
|
await _ajax({
|
||||||
call: 'updateDeviceName',
|
call: 'updateDeviceName',
|
||||||
|
|
Loading…
Reference in a new issue