reportController: hydrate the report itself to get the author
This commit is contained in:
parent
f99958c40e
commit
8530749192
|
@ -33,11 +33,6 @@ const reportController: AppController = async (c) => {
|
||||||
category,
|
category,
|
||||||
} = result.data;
|
} = result.data;
|
||||||
|
|
||||||
const [profile] = await store.query([{ kinds: [0], authors: [account_id] }]);
|
|
||||||
if (profile) {
|
|
||||||
await hydrateEvents({ events: [profile], storage: store });
|
|
||||||
}
|
|
||||||
|
|
||||||
const tags = [
|
const tags = [
|
||||||
['p', account_id, category],
|
['p', account_id, category],
|
||||||
['P', Conf.pubkey],
|
['P', Conf.pubkey],
|
||||||
|
@ -53,7 +48,8 @@ const reportController: AppController = async (c) => {
|
||||||
tags,
|
tags,
|
||||||
}, c);
|
}, 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 */
|
/** https://docs.joinmastodon.org/methods/admin/reports/#get */
|
||||||
|
@ -113,7 +109,7 @@ const adminReportResolveController: AppController = async (c) => {
|
||||||
content: 'Report closed.',
|
content: 'Report closed.',
|
||||||
}, c);
|
}, 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 };
|
export { adminReportController, adminReportResolveController, adminReportsController, reportController };
|
||||||
|
|
|
@ -5,26 +5,24 @@ import { renderAdminAccount } from '@/views/mastodon/admin-accounts.ts';
|
||||||
import { renderStatus } from '@/views/mastodon/statuses.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 */
|
/** 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
|
// 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 category = event.tags.find(([name]) => name === 'p')?.[2];
|
||||||
|
const statusIds = event.tags.filter(([name]) => name === 'e').map((tag) => tag[1]) ?? [];
|
||||||
const statusIds = reportEvent.tags.filter(([name]) => name === 'e').map((tag) => tag[1]) ?? [];
|
const reportedPubkey = event.tags.find(([name]) => name === 'p')?.[1];
|
||||||
|
|
||||||
const reportedPubkey = reportEvent.tags.find(([name]) => name === 'p')?.[1];
|
|
||||||
if (!reportedPubkey) return;
|
if (!reportedPubkey) return;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: reportEvent.id,
|
id: event.id,
|
||||||
action_taken: false,
|
action_taken: false,
|
||||||
action_taken_at: null,
|
action_taken_at: null,
|
||||||
category,
|
category,
|
||||||
comment: reportEvent.content,
|
comment: event.content,
|
||||||
forwarded: false,
|
forwarded: false,
|
||||||
created_at: nostrDate(reportEvent.created_at).toISOString(),
|
created_at: nostrDate(event.created_at).toISOString(),
|
||||||
status_ids: statusIds,
|
status_ids: statusIds,
|
||||||
rules_ids: null,
|
rules_ids: null,
|
||||||
target_account: profile ? await renderAccount(profile) : await accountFromPubkey(reportedPubkey),
|
target_account: event.author ? await renderAccount(event.author) : await accountFromPubkey(reportedPubkey),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue