reportController: hydrate the report itself to get the author

This commit is contained in:
Alex Gleason 2024-05-08 15:03:58 -05:00
parent f99958c40e
commit 8530749192
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 11 additions and 17 deletions

View File

@ -33,11 +33,6 @@ const reportController: AppController = async (c) => {
category,
} = result.data;
const [profile] = await store.query([{ kinds: [0], authors: [account_id] }]);
if (profile) {
await hydrateEvents({ events: [profile], storage: store });
}
const tags = [
['p', account_id, category],
['P', Conf.pubkey],
@ -53,7 +48,8 @@ const reportController: AppController = async (c) => {
tags,
}, c);
return c.json(await renderReport(event, profile));
await hydrateEvents({ events: [event], storage: store });
return c.json(await renderReport(event));
};
/** https://docs.joinmastodon.org/methods/admin/reports/#get */
@ -113,7 +109,7 @@ const adminReportResolveController: AppController = async (c) => {
content: 'Report closed.',
}, c);
return c.json(await renderAdminReport(event, { viewerPubkey: pubkey, action_taken: true }));
return c.json(await renderAdminReport(event, { viewerPubkey: pubkey, actionTaken: true }));
};
export { adminReportController, adminReportResolveController, adminReportsController, reportController };

View File

@ -5,26 +5,24 @@ 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) {
async function renderReport(event: DittoEvent) {
// The category is present in both the 'e' and 'p' tag, however, it is possible to report a user without reporting a note, so it's better to get the category from the 'p' tag
const category = reportEvent.tags.find(([name]) => name === 'p')?.[2];
const statusIds = reportEvent.tags.filter(([name]) => name === 'e').map((tag) => tag[1]) ?? [];
const reportedPubkey = reportEvent.tags.find(([name]) => name === 'p')?.[1];
const category = event.tags.find(([name]) => name === 'p')?.[2];
const statusIds = event.tags.filter(([name]) => name === 'e').map((tag) => tag[1]) ?? [];
const reportedPubkey = event.tags.find(([name]) => name === 'p')?.[1];
if (!reportedPubkey) return;
return {
id: reportEvent.id,
id: event.id,
action_taken: false,
action_taken_at: null,
category,
comment: reportEvent.content,
comment: event.content,
forwarded: false,
created_at: nostrDate(reportEvent.created_at).toISOString(),
created_at: nostrDate(event.created_at).toISOString(),
status_ids: statusIds,
rules_ids: null,
target_account: profile ? await renderAccount(profile) : await accountFromPubkey(reportedPubkey),
target_account: event.author ? await renderAccount(event.author) : await accountFromPubkey(reportedPubkey),
};
}