Merge branch 'fix-reports-no-kind-0' into 'main'

renderAdminAccount - Get account from pubkey if there is no kind 0 in the database

Closes #122

See merge request soapbox-pub/ditto!243
This commit is contained in:
Alex Gleason 2024-05-10 22:20:23 +00:00
commit d278fc980a
2 changed files with 42 additions and 11 deletions

View File

@ -1,23 +1,21 @@
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { nostrDate } from '@/utils.ts';
import { renderAccount } from '@/views/mastodon/accounts.ts';
/** Expects a kind 0 fully hydrated or a kind 30361 hydrated with `d_author` */
/** Expects a kind 0 fully hydrated */
async function renderAdminAccount(event: DittoEvent) {
const account = await renderAccount(event);
return {
id: account.id,
username: event.tags.find(([name]) => name === 'name')?.[1]!,
username: account.username,
domain: account.acct.split('@')[1] || null,
created_at: nostrDate(event.created_at).toISOString(),
created_at: account.created_at,
email: '',
ip: null,
ips: [],
locale: '',
invite_request: null,
role: event.tags.find(([name]) => name === 'role')?.[1] || 'user',
role: event.tags.find(([name]) => name === 'role')?.[1],
confirmed: true,
approved: true,
disabled: false,
@ -27,4 +25,28 @@ async function renderAdminAccount(event: DittoEvent) {
};
}
export { renderAdminAccount };
/** Expects a target pubkey */
async function renderAdminAccountFromPubkey(pubkey: string) {
const account = await accountFromPubkey(pubkey);
return {
id: account.id,
username: account.username,
domain: account.acct.split('@')[1] || null,
created_at: account.created_at,
email: '',
ip: null,
ips: [],
locale: '',
invite_request: null,
role: 'user',
confirmed: true,
approved: true,
disabled: false,
silenced: false,
suspended: false,
account,
};
}
export { renderAdminAccount, renderAdminAccountFromPubkey };

View File

@ -1,7 +1,7 @@
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 { renderAdminAccount, renderAdminAccountFromPubkey } 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 */
@ -49,6 +49,11 @@ async function renderAdminReport(reportEvent: DittoEvent, opts: RenderAdminRepor
}
}
const reportedPubkey = reportEvent.tags.find(([name]) => name === 'p')?.[1];
if (!reportedPubkey) {
return;
}
return {
id: reportEvent.id,
action_taken: actionTaken,
@ -57,8 +62,12 @@ async function renderAdminReport(reportEvent: DittoEvent, opts: RenderAdminRepor
comment: reportEvent.content,
forwarded: false,
created_at: nostrDate(reportEvent.created_at).toISOString(),
account: await renderAdminAccount(reportEvent.author as DittoEvent),
target_account: await renderAdminAccount(reportEvent.reported_profile as DittoEvent),
account: reportEvent.author
? await renderAdminAccount(reportEvent.author)
: await renderAdminAccountFromPubkey(reportEvent.pubkey),
target_account: reportEvent.reported_profile
? await renderAdminAccount(reportEvent.reported_profile)
: await renderAdminAccountFromPubkey(reportedPubkey),
assigned_account: null,
action_taken_by_account: null,
statuses,