feat: create renderAdminReport() func

This commit is contained in:
P. Reis 2024-05-04 20:14:39 -03:00
parent 8a7f0892d7
commit 4d5d4868ce
1 changed files with 43 additions and 1 deletions

View File

@ -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 };