// ── Report, block and hide on a chat line: what the menu offers ──────────── // // USER_SAFETY.md §4.2. Nothing here decides what a reader may SEE — the server // already left out what they blocked or hid, and staff's hidden lines for // everybody else (S11). This file only turns what the server said about a line // into which buttons its menu shows, and it is pure so a DOM-less runner can ask // all of it. /** The report target a chat line is filed as. Registered by `server/safety.js`. */ export const CHAT_TARGET = 'rust.chat' /** * The reasons a report can give. Core's `content_reports.reason` enum, in the * order and words core's own forum report uses, so a member reads one list * wherever they report from. */ export const REPORT_REASONS = Object.freeze([ ['abuse', 'Abusive or harassing'], ['spam', 'Spam'], ['sexual', 'Sexual content'], ['illegal', 'Illegal content'], ['impersonation', 'Impersonation'], ['other', 'Something else'], ]) /** * The roles that hide a line for everyone: the two core's Reports queue is open * to, and the two `POST /admin/rust/chat/:id/hide` admits. An editor writes * content and moderates none. */ export const HIDE_ROLES = Object.freeze(['admin', 'moderator']) /** * What a chat line's menu offers this reader. * * signIn a signed-out reader gets one line telling them to sign in (S6) * report any signed-in reader, on any line * hide "Hide for me", likewise — a staff member's line included (S8) * block only where the server said `canBlock` (S8, S13) * staff 'hide' or 'unhide' for a reader who can hide for everyone (S10) * * @param {{ kind: string, canBlock?: boolean, hidden?: boolean }} line * @param {{ role?: string } | null} user */ export function chatActions(line, user) { if (!line || line.kind !== 'player.chat') return null if (!user) return { signIn: true, report: false, hide: false, block: false, staff: null } const canHideForAll = HIDE_ROLES.includes(user.role) return { signIn: false, report: true, hide: true, block: line.canBlock === true, staff: canHideForAll ? (line.hidden ? 'unhide' : 'hide') : null, } }