fix: create renderAdminAccountFromPubkey and use it if reported account doesn't have a kind 0

This commit is contained in:
P. Reis 2024-05-10 16:51:07 -03:00
parent 83adf4759e
commit d3b7668a1e
2 changed files with 37 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 { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { nostrDate } from '@/utils.ts';
import { renderAccount } from '@/views/mastodon/accounts.ts'; /** Expects a kind 0 fully hydrated */
/** Expects a kind 0 fully hydrated or a kind 30361 hydrated with `d_author` */
async function renderAdminAccount(event: DittoEvent) { async function renderAdminAccount(event: DittoEvent) {
const account = await renderAccount(event); const account = await renderAccount(event);
return { return {
id: account.id, id: account.id,
username: event.tags.find(([name]) => name === 'name')?.[1]!, username: account.username,
domain: account.acct.split('@')[1] || null, domain: account.acct.split('@')[1] || null,
created_at: nostrDate(event.created_at).toISOString(), created_at: account.created_at,
email: '', email: '',
ip: null, ip: null,
ips: [], ips: [],
locale: '', locale: '',
invite_request: null, invite_request: null,
role: event.tags.find(([name]) => name === 'role')?.[1] || 'user', role: event.tags.find(([name]) => name === 'role')?.[1],
confirmed: true, confirmed: true,
approved: true, approved: true,
disabled: false, 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 { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts'; import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
import { nostrDate } from '@/utils.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'; 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 */
@ -57,8 +57,12 @@ async function renderAdminReport(reportEvent: DittoEvent, opts: RenderAdminRepor
comment: reportEvent.content, comment: reportEvent.content,
forwarded: false, forwarded: false,
created_at: nostrDate(reportEvent.created_at).toISOString(), created_at: nostrDate(reportEvent.created_at).toISOString(),
account: await renderAdminAccount(reportEvent.author as DittoEvent), account: reportEvent.author
target_account: await renderAdminAccount(reportEvent.reported_profile as DittoEvent), ? 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, assigned_account: null,
action_taken_by_account: null, action_taken_by_account: null,
statuses, statuses,