From 4d5d4868ce2fa81d95b4d2f674d4c8eaab076f52 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Sat, 4 May 2024 20:14:39 -0300 Subject: [PATCH] feat: create renderAdminReport() func --- src/views/mastodon/reports.ts | 44 ++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/views/mastodon/reports.ts b/src/views/mastodon/reports.ts index 03291f7..50fea46 100644 --- a/src/views/mastodon/reports.ts +++ b/src/views/mastodon/reports.ts @@ -1,6 +1,8 @@ import { type DittoEvent } from '@/interfaces/DittoEvent.ts'; import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts'; import { nostrDate } from '@/utils.ts'; +import { renderAdminAccount } from '@/views/mastodon/admin-accounts.ts'; +import { renderStatus } from '@/views/mastodon/statuses.ts'; /** Expects a `reportEvent` of kind 1984 and a `profile` of kind 0 of the person being reported */ async function renderReport(reportEvent: DittoEvent, profile: DittoEvent) { @@ -26,4 +28,44 @@ async function renderReport(reportEvent: DittoEvent, profile: DittoEvent) { }; } -export { renderReport }; +interface RenderAdminReportOpts { + viewerPubkey?: string; +} + +/** Admin-level information about a filed report. + * Expects an event of kind 1984 fully hydrated. + * https://docs.joinmastodon.org/entities/Admin_Report */ +async function renderAdminReport(reportEvent: DittoEvent, opts: RenderAdminReportOpts) { + const { viewerPubkey } = opts; + + const { + comment, + forward, + category, + } = JSON.parse(reportEvent.content); + + const statuses = []; + if (reportEvent.reported_statuses) { + for (const status of reportEvent.reported_statuses) { + statuses.push(await renderStatus(status, { viewerPubkey })); + } + } + + return { + id: reportEvent.id, + action_taken: false, + action_taken_at: null, + category, + comment, + forwarded: forward, + created_at: nostrDate(reportEvent.created_at).toISOString(), + account: await renderAdminAccount(reportEvent.author as DittoEvent), + target_account: await renderAdminAccount(reportEvent.target_account as DittoEvent), + assigned_account: null, + action_taken_by_account: null, + statuses, + rule: [], + }; +} + +export { renderAdminReport, renderReport };