signal-desktop/ts/jobs/removeStorageKeyJobQueue.ts
Jim Gustafson 6579b1a70a Update to RingRTC v2.35.0
Co-authored-by: ayumi yu <ayumi@signal.org>
Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com>
2024-01-10 11:14:58 -08:00

47 lines
1.2 KiB
TypeScript

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { z } from 'zod';
import type { JOB_STATUS } from './JobQueue';
import { JobQueue } from './JobQueue';
import { jobQueueDatabaseStore } from './JobQueueDatabaseStore';
const removeStorageKeyJobDataSchema = z.object({
key: z.enum([
'challenge:retry-message-ids',
'previousAudioDeviceModule',
'nextSignedKeyRotationTime',
'senderCertificateWithUuid',
'signedKeyRotationRejected',
]),
});
type RemoveStorageKeyJobData = z.infer<typeof removeStorageKeyJobDataSchema>;
export class RemoveStorageKeyJobQueue extends JobQueue<RemoveStorageKeyJobData> {
protected parseData(data: unknown): RemoveStorageKeyJobData {
return removeStorageKeyJobDataSchema.parse(data);
}
protected async run({
data,
}: Readonly<{ data: RemoveStorageKeyJobData }>): Promise<
typeof JOB_STATUS.NEEDS_RETRY | undefined
> {
await new Promise<void>(resolve => {
window.storage.onready(resolve);
});
await window.storage.remove(data.key);
return undefined;
}
}
export const removeStorageKeyJobQueue = new RemoveStorageKeyJobQueue({
store: jobQueueDatabaseStore,
queueType: 'remove storage key',
maxAttempts: 100,
});