2021-04-29 23:02:27 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-05-25 22:40:04 +00:00
|
|
|
import { z } from 'zod';
|
2021-04-29 23:02:27 +00:00
|
|
|
|
|
|
|
import { JobQueue } from './JobQueue';
|
|
|
|
import { jobQueueDatabaseStore } from './JobQueueDatabaseStore';
|
|
|
|
|
|
|
|
const removeStorageKeyJobDataSchema = z.object({
|
2022-03-21 21:19:37 +00:00
|
|
|
key: z.enum(['senderCertificateWithUuid', 'challenge:retry-message-ids']),
|
2021-04-29 23:02:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
type RemoveStorageKeyJobData = z.infer<typeof removeStorageKeyJobDataSchema>;
|
|
|
|
|
2021-07-21 21:10:08 +00:00
|
|
|
export class RemoveStorageKeyJobQueue extends JobQueue<RemoveStorageKeyJobData> {
|
|
|
|
protected parseData(data: unknown): RemoveStorageKeyJobData {
|
2021-04-29 23:02:27 +00:00
|
|
|
return removeStorageKeyJobDataSchema.parse(data);
|
2021-07-21 21:10:08 +00:00
|
|
|
}
|
2021-04-29 23:02:27 +00:00
|
|
|
|
2021-07-21 21:10:08 +00:00
|
|
|
protected async run({
|
2021-04-29 23:02:27 +00:00
|
|
|
data,
|
|
|
|
}: Readonly<{ data: RemoveStorageKeyJobData }>): Promise<void> {
|
|
|
|
await new Promise<void>(resolve => {
|
|
|
|
window.storage.onready(resolve);
|
|
|
|
});
|
|
|
|
|
|
|
|
await window.storage.remove(data.key);
|
2021-07-21 21:10:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const removeStorageKeyJobQueue = new RemoveStorageKeyJobQueue({
|
|
|
|
store: jobQueueDatabaseStore,
|
|
|
|
queueType: 'remove storage key',
|
|
|
|
maxAttempts: 100,
|
2021-04-29 23:02:27 +00:00
|
|
|
});
|