2021-05-27 20:17:05 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-09-15 19:17:15 +00:00
|
|
|
import { assertDev } from '../../util/assert';
|
2023-02-08 00:55:12 +00:00
|
|
|
import { isDirectConversation } from '../../util/whatTypeOfConversation';
|
2021-05-27 20:17:05 +00:00
|
|
|
import * as log from '../../logging/log';
|
2023-09-14 17:04:48 +00:00
|
|
|
import { isAciString } from '../../util/isAciString';
|
2021-05-27 20:17:05 +00:00
|
|
|
import type { reportSpamJobQueue } from '../reportSpamJobQueue';
|
2024-03-12 16:29:31 +00:00
|
|
|
import type { ConversationType } from '../../state/ducks/conversations';
|
2021-05-27 20:17:05 +00:00
|
|
|
|
|
|
|
export async function addReportSpamJob({
|
|
|
|
conversation,
|
|
|
|
getMessageServerGuidsForSpam,
|
|
|
|
jobQueue,
|
|
|
|
}: Readonly<{
|
2023-02-08 00:55:12 +00:00
|
|
|
conversation: Readonly<
|
2024-03-12 16:29:31 +00:00
|
|
|
Pick<ConversationType, 'id' | 'type' | 'serviceId' | 'reportingToken'>
|
2023-02-08 00:55:12 +00:00
|
|
|
>;
|
2021-05-27 20:17:05 +00:00
|
|
|
getMessageServerGuidsForSpam: (
|
|
|
|
conversationId: string
|
|
|
|
) => Promise<Array<string>>;
|
|
|
|
jobQueue: Pick<typeof reportSpamJobQueue, 'add'>;
|
|
|
|
}>): Promise<void> {
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2023-02-08 00:55:12 +00:00
|
|
|
isDirectConversation(conversation),
|
2021-05-27 20:17:05 +00:00
|
|
|
'addReportSpamJob: cannot report spam for non-direct conversations'
|
|
|
|
);
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const { serviceId: aci } = conversation;
|
|
|
|
if (!aci || !isAciString(aci)) {
|
2021-05-27 20:17:05 +00:00
|
|
|
log.info(
|
2023-08-16 20:54:39 +00:00
|
|
|
'addReportSpamJob got a conversation with no aci, which the server does not support. Doing nothing'
|
2021-05-27 20:17:05 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const serverGuids = await getMessageServerGuidsForSpam(conversation.id);
|
|
|
|
if (!serverGuids.length) {
|
|
|
|
// This can happen under normal conditions. We haven't always stored server GUIDs, so
|
|
|
|
// a user might try to report spam for a conversation that doesn't have them. (It
|
|
|
|
// may also indicate developer error, but that's not necessarily the case.)
|
|
|
|
log.info(
|
|
|
|
'addReportSpamJob got no server GUIDs from the database. Doing nothing'
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
await jobQueue.add({ aci, serverGuids, token: conversation.reportingToken });
|
2021-05-27 20:17:05 +00:00
|
|
|
}
|