signal-desktop/ts/sql/migrations/55-report-message-aci.ts

53 lines
1.5 KiB
TypeScript
Raw Normal View History

// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { LoggerType } from '../../types/Logging.js';
import { getJobsInQueue, insertJob } from '../Server.js';
import type { WritableDB } from '../Interface.js';
import { isRecord } from '../../util/isRecord.js';
import { isIterable } from '../../util/iterables.js';
export default function updateToSchemaVersion55(
2024-07-22 11:16:33 -07:00
db: WritableDB,
logger: LoggerType
): void {
2025-08-06 10:32:08 -07:00
const deleteJobsInQueue = db.prepare(
'DELETE FROM jobs WHERE queueType = $queueType'
);
// First, make sure that report spam job data has e164 and serverGuids
const reportSpamJobs = getJobsInQueue(db, 'report spam');
deleteJobsInQueue.run({ queueType: 'report spam' });
reportSpamJobs.forEach(job => {
const { data, id } = job;
if (!isRecord(data)) {
logger.warn(`report spam queue job ${id} was missing valid data`);
return;
}
const { e164, serverGuids } = data;
if (typeof e164 !== 'string') {
logger.warn(`report spam queue job ${id} had a non-string e164`);
return;
}
if (!isIterable(serverGuids)) {
logger.warn(`report spam queue job ${id} had a non-iterable serverGuids`);
return;
}
const newJob = {
...job,
queueType: 'report spam',
data: {
uuid: e164, // this looks odd, but they are both strings and interchangeable in the server API
serverGuids,
},
};
insertJob(db, newJob);
});
}