Add case follow-up queues and personal update notifications
This commit is contained in:
@@ -4,6 +4,7 @@ import { archivedEvidenceSnapshots } from './evidence.js';
|
||||
import { caseActionReference, recordedCaseAction, isCaseActionLinked } from './case-actions.js';
|
||||
import { assessmentDraft } from './assessments.js';
|
||||
import { linkCases, unlinkCases } from './relationships.js';
|
||||
import { notifyCase, caseReviewSchedule, readCaseUpdates } from './followups.js';
|
||||
import { AuthError } from '../auth/index.js';
|
||||
import { moderatorMaximumRestrictionMs, type AuthUser } from '../../auth.js';
|
||||
import {
|
||||
@@ -53,6 +54,9 @@ type CaseRow = {
|
||||
title: string;
|
||||
priority: ModerationCasePriority;
|
||||
assignee_id: string | null;
|
||||
review_at: string | null;
|
||||
review_reason: string;
|
||||
review_sanction_id: string | null;
|
||||
};
|
||||
|
||||
function serverTarget(name: unknown, game?: ModerationGame) {
|
||||
@@ -390,7 +394,8 @@ function createCase(actor: AuthUser, input: Record<string, unknown>, now: string
|
||||
assignee.id
|
||||
);
|
||||
if (note) evidence(actor, id, note, 'Staff note', null, now);
|
||||
if (input.evidence !== undefined) archivedEvidence(actor, id, target, input.evidence, now);
|
||||
const attached =
|
||||
input.evidence === undefined ? 0 : archivedEvidence(actor, id, target, input.evidence, now);
|
||||
moderationEvent(actor, 'case.opened', target, id, title, now);
|
||||
if (priority !== 'normal' || assignee.id)
|
||||
moderationEvent(
|
||||
@@ -404,6 +409,8 @@ function createCase(actor: AuthUser, input: Record<string, unknown>, now: string
|
||||
}),
|
||||
now
|
||||
);
|
||||
if (note || attached) notifyCase(actor.id, id, 'evidence', now);
|
||||
if (assignee.id) notifyCase(actor.id, id, 'assignment', now);
|
||||
return { id };
|
||||
}
|
||||
function archivedEvidence(
|
||||
@@ -465,6 +472,8 @@ function updateCase(actor: AuthUser, input: Record<string, unknown>, now: string
|
||||
JSON.stringify({ ...changes, ...(reason ? { reason } : {}) }),
|
||||
now
|
||||
);
|
||||
if (assigneeId !== row.assignee_id)
|
||||
notifyCase(actor.id, row.id, 'assignment', now, row.assignee_id);
|
||||
return { id: row.id };
|
||||
}
|
||||
export function mutateModeration(actorId: string, input: Record<string, unknown>) {
|
||||
@@ -474,6 +483,37 @@ export function mutateModeration(actorId: string, input: Record<string, unknown>
|
||||
if (input.op === 'action') return liveAction(actor, input, now);
|
||||
if (input.op === 'create-case') return createCase(actor, input, now);
|
||||
if (input.op === 'update-case') return updateCase(actor, input, now);
|
||||
if (input.op === 'schedule-case-review') {
|
||||
const row = caseRow(input.id);
|
||||
checkCaseRevision(row, input.revision);
|
||||
const schedule = caseReviewSchedule(row, input, now);
|
||||
if (
|
||||
row.review_at === schedule.reviewAt &&
|
||||
row.review_reason === schedule.reason &&
|
||||
row.review_sanction_id === schedule.restrictionId
|
||||
)
|
||||
return { id: row.id };
|
||||
db()
|
||||
.prepare(
|
||||
`UPDATE moderation_cases SET review_at=?,review_reason=?,review_sanction_id=?,
|
||||
updated_at=?,revision=revision+1 WHERE id=?`
|
||||
)
|
||||
.run(schedule.reviewAt, schedule.reason, schedule.restrictionId, now, row.id);
|
||||
moderationEvent(
|
||||
actor,
|
||||
'case.review_scheduled',
|
||||
row,
|
||||
row.id,
|
||||
JSON.stringify(schedule),
|
||||
now
|
||||
);
|
||||
return { id: row.id };
|
||||
}
|
||||
if (input.op === 'read-case-updates') {
|
||||
const row = caseRow(input.id);
|
||||
readCaseUpdates(actor.id, row.id, input.throughId, now);
|
||||
return { id: row.id };
|
||||
}
|
||||
if (input.op === 'link-case' || input.op === 'unlink-case') {
|
||||
const row = caseRow(input.id);
|
||||
checkCaseRevision(row, input.revision);
|
||||
@@ -542,6 +582,7 @@ export function mutateModeration(actorId: string, input: Record<string, unknown>
|
||||
evidence(actor, row.id, text, 'Staff note', null, now);
|
||||
touchCase(row.id, now);
|
||||
moderationEvent(actor, 'case.note', row, row.id, text, now);
|
||||
notifyCase(actor.id, row.id, 'evidence', now);
|
||||
return { id: row.id };
|
||||
}
|
||||
if (input.op === 'resolve-case') {
|
||||
@@ -626,6 +667,7 @@ export function mutateModeration(actorId: string, input: Record<string, unknown>
|
||||
JSON.stringify({ count, matchId: (input.evidence as { matchId: number }).matchId }),
|
||||
now
|
||||
);
|
||||
notifyCase(actor.id, row.id, 'evidence', now);
|
||||
return { id: row.id };
|
||||
}
|
||||
if (input.op === 'note') {
|
||||
|
||||
Reference in New Issue
Block a user