Merge branch 'feat-create-reports' into 'main'

Create user reports through kind 1984

Closes #97

See merge request soapbox-pub/ditto!210
This commit is contained in:
Alex Gleason
2024-05-03 14:25:22 +00:00
3 changed files with 85 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
import { nostrDate } from '@/utils.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) {
const {
account_id,
status_ids,
comment,
forward,
category,
} = JSON.parse(reportEvent.content);
return {
id: account_id,
action_taken: false,
action_taken_at: null,
category,
comment,
forwarded: forward,
created_at: nostrDate(reportEvent.created_at).toISOString(),
status_ids,
rules_ids: null,
target_account: profile ? await renderAccount(profile) : await accountFromPubkey(account_id),
};
}
export { renderReport };