fix: create renderAdminAccountFromPubkey and use it if reported account doesn't have a kind 0
This commit is contained in:
parent
83adf4759e
commit
d3b7668a1e
|
@ -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 };
|
||||
|
|
|
@ -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 */
|
||||
|
@ -57,8 +57,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(reportEvent.tags.find(([name]) => name === 'p')![1]),
|
||||
assigned_account: null,
|
||||
action_taken_by_account: null,
|
||||
statuses,
|
||||
|
|
Loading…
Reference in New Issue