Message Requests: Add new "Report spam and block" button
This commit is contained in:
parent
20e501d9f1
commit
d4dc9b8e39
33 changed files with 630 additions and 92 deletions
45
ts/jobs/helpers/addReportSpamJob.ts
Normal file
45
ts/jobs/helpers/addReportSpamJob.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from '../../util/assert';
|
||||
import * as log from '../../logging/log';
|
||||
import { ConversationType } from '../../state/ducks/conversations';
|
||||
import type { reportSpamJobQueue } from '../reportSpamJobQueue';
|
||||
|
||||
export async function addReportSpamJob({
|
||||
conversation,
|
||||
getMessageServerGuidsForSpam,
|
||||
jobQueue,
|
||||
}: Readonly<{
|
||||
conversation: Readonly<ConversationType>;
|
||||
getMessageServerGuidsForSpam: (
|
||||
conversationId: string
|
||||
) => Promise<Array<string>>;
|
||||
jobQueue: Pick<typeof reportSpamJobQueue, 'add'>;
|
||||
}>): Promise<void> {
|
||||
assert(
|
||||
conversation.type === 'direct',
|
||||
'addReportSpamJob: cannot report spam for non-direct conversations'
|
||||
);
|
||||
|
||||
const { e164 } = conversation;
|
||||
if (!e164) {
|
||||
log.info(
|
||||
'addReportSpamJob got a conversation with no E164, which the server does not support. Doing nothing'
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
await jobQueue.add({ e164, serverGuids });
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue