Skip to content

Commit 8eeeda4

Browse files
committed
refactor(moderation): ♻️ tighten warning copy and React Doctor findings
- Plainer UI strings and docs sentences: no spaced dashes, a named actor instead of passive voice, no pep-talk on an empty warning history. - Cache the UTC date formatter suspension notifications use, save a reason's translations in parallel, and split the staff warning card into WarningFacts and StaffNotes. - Give the Postgres warnings test the realtime model every request has. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFc4WPMdVa99L7jsTXY
1 parent c00e740 commit 8eeeda4

6 files changed

Lines changed: 134 additions & 95 deletions

File tree

‎apps/web/content/docs/dev/moderation/configure-warnings.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Open **AdminCP → Moderation → Warning thresholds** and choose **Add threshol
5353
| Active points | Action | Duration |
5454
| --- | --- | --- |
5555
| 8 | Temporary suspension | 24 hours |
56-
| 10 | Indefinite suspension | - |
56+
| 10 | Indefinite suspension | None |
5757

5858
<ImgDocs
5959
withoutBackground

‎apps/web/content/docs/dev/moderation/warnings.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ A temporary suspension ends at its own end time, even when the member still has
3333

3434
## What a suspended member sees
3535

36-
The server checks suspensions when it reads the session, for every request: core routes, plugin routes, server functions and WebSocket handshakes. A suspended account is treated as a guest everywhere, so it can browse public pages but cannot post, comment, report, moderate or open the AdminCP. Open WebSocket connections are closed when the suspension is applied.
36+
The server checks suspensions when it reads the session, for every request: core routes, plugin routes, server functions and WebSocket handshakes. The API treats a suspended account as a guest everywhere, so it can browse public pages but cannot post, comment, report, moderate or open the AdminCP. Applying a suspension also closes the member's open WebSocket connections.
3737

3838
The member keeps their session. A strip under the header says the account is suspended and links to **Account status** at `/account-status`, which shows the suspension end time, active points and the warning history with each message. Members reach the same page from **Settings → Account status** at any time. It never shows staff notes or which moderator issued a warning.
3939

‎packages/vitnode/src/api/lib/notifications/core-types.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ const reasonTextSchema = z
2424

2525
const ACCOUNT_STATUS_PATH = "/account-status";
2626

27+
const utcDateTimeFormats = new Map<string, Intl.DateTimeFormat>();
28+
29+
/** Emails have no viewer time zone, so suspension ends are written in UTC. */
30+
const utcDateTimeFormat = (locale: string): Intl.DateTimeFormat => {
31+
let format = utcDateTimeFormats.get(locale);
32+
if (!format) {
33+
format = new Intl.DateTimeFormat(locale, {
34+
dateStyle: "medium",
35+
timeStyle: "short",
36+
timeZone: "UTC",
37+
});
38+
utcDateTimeFormats.set(locale, format);
39+
}
40+
41+
return format;
42+
};
43+
2744
/** Sent to a member when a moderator warns them. Never carries staff notes. */
2845
export const warningIssuedNotification = buildNotificationType({
2946
id: "core.warning_issued",
@@ -99,11 +116,7 @@ export const accountSuspendedNotification = buildNotificationType({
99116
present: ({ data, locale, t }) => ({
100117
body: data.endsAt
101118
? t("core.notifications.types.account_suspended.body_until", {
102-
endsAt: new Intl.DateTimeFormat(locale, {
103-
dateStyle: "medium",
104-
timeStyle: "short",
105-
timeZone: "UTC",
106-
}).format(new Date(data.endsAt)),
119+
endsAt: utcDateTimeFormat(locale).format(new Date(data.endsAt)),
107120
})
108121
: t("core.notifications.types.account_suspended.body_indefinite"),
109122
target: ACCOUNT_STATUS_PATH,

‎packages/vitnode/src/api/modules/admin/warnings/routes/warning-reasons.routes.ts‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,18 @@ const saveReasonWords = async (
6161
reasonId: number,
6262
body: Partial<z.infer<typeof reasonBody>>,
6363
) => {
64-
for (const variable of ["title", "description", "message"] as const) {
65-
const values = body[variable];
66-
if (values === undefined) continue;
67-
await saveLanguageWords(c, {
68-
...WARNING_REASON_WORDS,
69-
itemId: reasonId,
70-
values: values.filter(item => item.value.length > 0),
71-
variable,
72-
});
73-
}
64+
await Promise.all(
65+
(["title", "description", "message"] as const).map(async variable => {
66+
const values = body[variable];
67+
if (values === undefined) return;
68+
await saveLanguageWords(c, {
69+
...WARNING_REASON_WORDS,
70+
itemId: reasonId,
71+
values: values.filter(item => item.value.length > 0),
72+
variable,
73+
});
74+
}),
75+
);
7476
};
7577

7678
/** What an audit entry keeps of a reason: settings, never the words. */

‎packages/vitnode/src/api/modules/moderation/warnings.postgres.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ describe.skipIf(!POSTGRES_TEST_URL)("issuing warnings on PostgreSQL", () => {
5959
c.set("notifications", {
6060
publish,
6161
} as unknown as Context["var"]["notifications"]);
62+
c.set("realtime", {
63+
closeUserConnections: () => undefined,
64+
} as unknown as Context["var"]["realtime"]);
6265
c.set("core", {
6366
moderation: { scopes: [], targets: [] },
6467
permissionStaff: [],

‎packages/vitnode/src/views/moderation/warnings/warning-list.tsx‎

Lines changed: 99 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,103 @@ const PersonOrDeleted = ({ person }: { person: null | ReportPerson }) => {
159159
return person ? <Person link person={person} /> : <>{t("deleted_user")}</>;
160160
};
161161

162+
/** Who, when, what for: the facts of one warning. */
163+
const WarningFacts = ({
164+
member,
165+
warning,
166+
}: {
167+
member?: null | ReportPerson;
168+
warning: ModcpStaffWarning;
169+
}) => {
170+
const t = useTranslations("core.moderation.warn");
171+
172+
return (
173+
<dl className="grid gap-3 sm:grid-cols-2">
174+
{member !== undefined ? (
175+
<Detail label={t("list.member")}>
176+
{member ? (
177+
<Link
178+
className="hover:bg-muted/50 focus-visible:ring-ring/50 -mx-1 inline-flex rounded-md px-1 outline-none focus-visible:ring-3"
179+
to={`/modcp/members/${member.id}`}
180+
>
181+
<Person person={member} />
182+
</Link>
183+
) : (
184+
<PersonOrDeleted person={member} />
185+
)}
186+
</Detail>
187+
) : null}
188+
<Detail label={t("list.issued_by")}>
189+
<PersonOrDeleted person={warning.issuedBy} />
190+
</Detail>
191+
<Detail label={t("list.expires")}>
192+
{warning.expiresAt ? (
193+
<DateFormat date={warning.expiresAt} showFullDate />
194+
) : (
195+
t("list.never")
196+
)}
197+
</Detail>
198+
{warning.defaultPoints !== null &&
199+
warning.defaultPoints !== warning.points ? (
200+
<Detail label={t("list.default_points")}>
201+
{t("points", { count: warning.defaultPoints })}
202+
</Detail>
203+
) : null}
204+
{warning.content ? (
205+
<Detail label={t("list.content")}>
206+
{warning.content.url ? (
207+
<a
208+
className="text-primary inline-flex items-center gap-1 underline-offset-4 hover:underline"
209+
href={warning.content.url}
210+
>
211+
{warning.content.title ?? t("list.untitled")}
212+
<ExternalLinkIcon aria-hidden="true" className="size-3.5" />
213+
</a>
214+
) : (
215+
(warning.content.title ?? t("list.untitled"))
216+
)}
217+
</Detail>
218+
) : null}
219+
{warning.reportId ? (
220+
<Detail label={t("list.report")}>
221+
<Link
222+
className="text-primary inline-flex items-center gap-1 underline-offset-4 hover:underline"
223+
to={`/modcp/reports/${warning.reportId}`}
224+
>
225+
<FlagIcon aria-hidden="true" className="size-3.5" />
226+
{t("list.report_link", { id: warning.reportId })}
227+
</Link>
228+
</Detail>
229+
) : null}
230+
</dl>
231+
);
232+
};
233+
234+
/** Staff notes and override explanations - `null` from the API unless the moderator may read them. */
235+
const StaffNotes = ({ warning }: { warning: ModcpStaffWarning }) => {
236+
const t = useTranslations("core.moderation.warn");
237+
if (!warning.staffNote && !warning.overrideNote) return null;
238+
239+
return (
240+
<div className="bg-muted/60 flex flex-col gap-3 rounded-lg p-3">
241+
<p className="text-muted-foreground flex items-center gap-1.5 text-xs font-medium">
242+
<LockIcon aria-hidden="true" className="size-3.5" />
243+
{t("list.staff_only")}
244+
</p>
245+
{warning.staffNote ? (
246+
<Detail label={t("list.staff_note")}>
247+
<span className="whitespace-pre-wrap">{warning.staffNote}</span>
248+
</Detail>
249+
) : null}
250+
{warning.overrideNote ? (
251+
<Detail label={t("list.override_note")}>
252+
<span className="whitespace-pre-wrap">{warning.overrideNote}</span>
253+
</Detail>
254+
) : null}
255+
</div>
256+
);
257+
};
258+
162259
/** One warning as staff see it, with Revoke when allowed. */
163260
export const StaffWarningCard = ({
164261
canRevoke,
@@ -216,89 +313,13 @@ export const StaffWarningCard = ({
216313
</div>
217314
</header>
218315

219-
<dl className="grid gap-3 sm:grid-cols-2">
220-
{member !== undefined ? (
221-
<Detail label={t("list.member")}>
222-
{member ? (
223-
<Link
224-
className="hover:bg-muted/50 focus-visible:ring-ring/50 -mx-1 inline-flex rounded-md px-1 outline-none focus-visible:ring-3"
225-
to={`/modcp/members/${member.id}`}
226-
>
227-
<Person person={member} />
228-
</Link>
229-
) : (
230-
<PersonOrDeleted person={member} />
231-
)}
232-
</Detail>
233-
) : null}
234-
<Detail label={t("list.issued_by")}>
235-
<PersonOrDeleted person={warning.issuedBy} />
236-
</Detail>
237-
<Detail label={t("list.expires")}>
238-
{warning.expiresAt ? (
239-
<DateFormat date={warning.expiresAt} showFullDate />
240-
) : (
241-
t("list.never")
242-
)}
243-
</Detail>
244-
{warning.defaultPoints !== null &&
245-
warning.defaultPoints !== warning.points ? (
246-
<Detail label={t("list.default_points")}>
247-
{t("points", { count: warning.defaultPoints })}
248-
</Detail>
249-
) : null}
250-
{warning.content ? (
251-
<Detail label={t("list.content")}>
252-
{warning.content.url ? (
253-
<a
254-
className="text-primary inline-flex items-center gap-1 underline-offset-4 hover:underline"
255-
href={warning.content.url}
256-
>
257-
{warning.content.title ?? t("list.untitled")}
258-
<ExternalLinkIcon aria-hidden="true" className="size-3.5" />
259-
</a>
260-
) : (
261-
(warning.content.title ?? t("list.untitled"))
262-
)}
263-
</Detail>
264-
) : null}
265-
{warning.reportId ? (
266-
<Detail label={t("list.report")}>
267-
<Link
268-
className="text-primary inline-flex items-center gap-1 underline-offset-4 hover:underline"
269-
to={`/modcp/reports/${warning.reportId}`}
270-
>
271-
<FlagIcon aria-hidden="true" className="size-3.5" />
272-
{t("list.report_link", { id: warning.reportId })}
273-
</Link>
274-
</Detail>
275-
) : null}
276-
</dl>
316+
<WarningFacts member={member} warning={warning} />
277317

278318
<Detail label={t("list.message")}>
279319
<span className="whitespace-pre-wrap">{warning.message}</span>
280320
</Detail>
281321

282-
{warning.staffNote || warning.overrideNote ? (
283-
<div className="bg-muted/60 flex flex-col gap-3 rounded-lg p-3">
284-
<p className="text-muted-foreground flex items-center gap-1.5 text-xs font-medium">
285-
<LockIcon aria-hidden="true" className="size-3.5" />
286-
{t("list.staff_only")}
287-
</p>
288-
{warning.staffNote ? (
289-
<Detail label={t("list.staff_note")}>
290-
<span className="whitespace-pre-wrap">{warning.staffNote}</span>
291-
</Detail>
292-
) : null}
293-
{warning.overrideNote ? (
294-
<Detail label={t("list.override_note")}>
295-
<span className="whitespace-pre-wrap">
296-
{warning.overrideNote}
297-
</span>
298-
</Detail>
299-
) : null}
300-
</div>
301-
) : null}
322+
<StaffNotes warning={warning} />
302323

303324
{revokedAt ? (
304325
<p className="text-muted-foreground text-sm leading-relaxed text-pretty">

0 commit comments

Comments
 (0)