fix(reports): put notes in tag & only let comment in event.content
This commit is contained in:
parent
7890504add
commit
394599734f
|
@ -12,7 +12,6 @@ const reportsSchema = z.object({
|
||||||
account_id: n.id(),
|
account_id: n.id(),
|
||||||
status_ids: n.id().array().default([]),
|
status_ids: n.id().array().default([]),
|
||||||
comment: z.string().max(1000).default(''),
|
comment: z.string().max(1000).default(''),
|
||||||
forward: z.boolean().default(false),
|
|
||||||
category: z.string().default('other'),
|
category: z.string().default('other'),
|
||||||
// TODO: rules_ids[] is not implemented
|
// TODO: rules_ids[] is not implemented
|
||||||
});
|
});
|
||||||
|
@ -31,7 +30,6 @@ const reportsController: AppController = async (c) => {
|
||||||
account_id,
|
account_id,
|
||||||
status_ids,
|
status_ids,
|
||||||
comment,
|
comment,
|
||||||
forward,
|
|
||||||
category,
|
category,
|
||||||
} = result.data;
|
} = result.data;
|
||||||
|
|
||||||
|
@ -40,13 +38,19 @@ const reportsController: AppController = async (c) => {
|
||||||
await hydrateEvents({ events: [profile], storage: store });
|
await hydrateEvents({ events: [profile], storage: store });
|
||||||
}
|
}
|
||||||
|
|
||||||
const event = await createEvent({
|
const tags = [
|
||||||
kind: 1984,
|
|
||||||
content: JSON.stringify({ account_id, status_ids, comment, forward, category }),
|
|
||||||
tags: [
|
|
||||||
['p', account_id, category],
|
['p', account_id, category],
|
||||||
['P', Conf.pubkey],
|
['P', Conf.pubkey],
|
||||||
],
|
];
|
||||||
|
|
||||||
|
for (const status of status_ids) {
|
||||||
|
tags.push(['e', status, category]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const event = await createEvent({
|
||||||
|
kind: 1984,
|
||||||
|
content: comment,
|
||||||
|
tags,
|
||||||
}, c);
|
}, c);
|
||||||
|
|
||||||
return c.json(await renderReport(event, profile));
|
return c.json(await renderReport(event, profile));
|
||||||
|
|
|
@ -105,14 +105,12 @@ function assembleEvents(
|
||||||
}
|
}
|
||||||
const reportedEvents: DittoEvent[] = [];
|
const reportedEvents: DittoEvent[] = [];
|
||||||
|
|
||||||
const { status_ids } = JSON.parse(event.content);
|
const status_ids = event.tags.filter(([name]) => name === 'e').map((tag) => tag[1]);
|
||||||
if (status_ids && Array.isArray(status_ids)) {
|
if (status_ids.length > 0) {
|
||||||
for (const id of status_ids) {
|
for (const id of status_ids) {
|
||||||
if (typeof id === 'string') {
|
|
||||||
const reportedEvent = b.find((e) => matchFilter({ kinds: [1], ids: [id] }, e));
|
const reportedEvent = b.find((e) => matchFilter({ kinds: [1], ids: [id] }, e));
|
||||||
if (reportedEvent) reportedEvents.push(reportedEvent);
|
if (reportedEvent) reportedEvents.push(reportedEvent);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
event.reported_notes = reportedEvents;
|
event.reported_notes = reportedEvents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,10 +204,10 @@ function gatherReportedNotes({ events, storage, signal }: HydrateOpts): Promise<
|
||||||
const ids = new Set<string>();
|
const ids = new Set<string>();
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
if (event.kind === 1984) {
|
if (event.kind === 1984) {
|
||||||
const { status_ids } = JSON.parse(event.content);
|
const status_ids = event.tags.filter(([name]) => name === 'e').map((tag) => tag[1]);
|
||||||
if (status_ids && Array.isArray(status_ids)) {
|
if (status_ids.length > 0) {
|
||||||
for (const id of status_ids) {
|
for (const id of status_ids) {
|
||||||
if (typeof id === 'string') ids.add(id);
|
ids.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,25 +6,24 @@ 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(reportEvent: DittoEvent, profile: DittoEvent) {
|
||||||
const {
|
// 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
|
||||||
account_id,
|
const category = reportEvent.tags.find(([name]) => name === 'p')?.[2] as string;
|
||||||
status_ids,
|
|
||||||
comment,
|
const status_ids = reportEvent.tags.filter(([name]) => name === 'e').map((tag) => tag[1]) ?? [];
|
||||||
forward,
|
|
||||||
category,
|
const reported_profile_pubkey = reportEvent.tags.find(([name]) => name === 'p')?.[1] as string;
|
||||||
} = JSON.parse(reportEvent.content);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: account_id,
|
id: reportEvent.id,
|
||||||
action_taken: false,
|
action_taken: false,
|
||||||
action_taken_at: null,
|
action_taken_at: null,
|
||||||
category,
|
category,
|
||||||
comment,
|
comment: reportEvent.content,
|
||||||
forwarded: forward,
|
forwarded: false,
|
||||||
created_at: nostrDate(reportEvent.created_at).toISOString(),
|
created_at: nostrDate(reportEvent.created_at).toISOString(),
|
||||||
status_ids,
|
status_ids,
|
||||||
rules_ids: null,
|
rules_ids: null,
|
||||||
target_account: profile ? await renderAccount(profile) : await accountFromPubkey(account_id),
|
target_account: profile ? await renderAccount(profile) : await accountFromPubkey(reported_profile_pubkey),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +37,8 @@ interface RenderAdminReportOpts {
|
||||||
async function renderAdminReport(reportEvent: DittoEvent, opts: RenderAdminReportOpts) {
|
async function renderAdminReport(reportEvent: DittoEvent, opts: RenderAdminReportOpts) {
|
||||||
const { viewerPubkey } = opts;
|
const { viewerPubkey } = opts;
|
||||||
|
|
||||||
const {
|
// 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
|
||||||
comment,
|
const category = reportEvent.tags.find(([name]) => name === 'p')?.[2] as string;
|
||||||
forward,
|
|
||||||
category,
|
|
||||||
} = JSON.parse(reportEvent.content);
|
|
||||||
|
|
||||||
const statuses = [];
|
const statuses = [];
|
||||||
if (reportEvent.reported_notes) {
|
if (reportEvent.reported_notes) {
|
||||||
|
@ -56,8 +52,8 @@ async function renderAdminReport(reportEvent: DittoEvent, opts: RenderAdminRepor
|
||||||
action_taken: false,
|
action_taken: false,
|
||||||
action_taken_at: null,
|
action_taken_at: null,
|
||||||
category,
|
category,
|
||||||
comment,
|
comment: reportEvent.content,
|
||||||
forwarded: forward,
|
forwarded: false,
|
||||||
created_at: nostrDate(reportEvent.created_at).toISOString(),
|
created_at: nostrDate(reportEvent.created_at).toISOString(),
|
||||||
account: await renderAdminAccount(reportEvent.author as DittoEvent),
|
account: await renderAdminAccount(reportEvent.author as DittoEvent),
|
||||||
target_account: await renderAdminAccount(reportEvent.reported_profile as DittoEvent),
|
target_account: await renderAdminAccount(reportEvent.reported_profile as DittoEvent),
|
||||||
|
|
Loading…
Reference in New Issue