Mimic Mastodon's uri/url fields exactly on Accounts and Statuses

This commit is contained in:
Alex Gleason 2024-08-07 15:23:33 -05:00
parent 8f704e4ea2
commit dbd40357af
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 7 additions and 4 deletions

View file

@ -36,6 +36,7 @@ export interface MastodonAccount {
}; };
}; };
statuses_count: number; statuses_count: number;
uri: string;
url: string; url: string;
username: string; username: string;
ditto: { ditto: {

View file

@ -42,10 +42,11 @@ async function renderAccount(
const npub = nip19.npubEncode(pubkey); const npub = nip19.npubEncode(pubkey);
const parsed05 = await parseAndVerifyNip05(nip05, pubkey); const parsed05 = await parseAndVerifyNip05(nip05, pubkey);
const acct = parsed05?.handle || npub;
return { return {
id: pubkey, id: pubkey,
acct: parsed05?.handle || npub, acct,
avatar: picture, avatar: picture,
avatar_static: picture, avatar_static: picture,
bot: false, bot: false,
@ -78,7 +79,8 @@ async function renderAccount(
} }
: undefined, : undefined,
statuses_count: event.author_stats?.notes_count ?? 0, statuses_count: event.author_stats?.notes_count ?? 0,
url: Conf.local(`/users/${pubkey}`), uri: Conf.local(`/users/${acct}`),
url: Conf.local(`/@${acct}`),
username: parsed05?.nickname || npub.substring(0, 8), username: parsed05?.nickname || npub.substring(0, 8),
ditto: { ditto: {
accepts_zaps: Boolean(getLnurl({ lud06, lud16 })), accepts_zaps: Boolean(getLnurl({ lud06, lud16 })),

View file

@ -121,8 +121,8 @@ async function renderStatus(event: DittoEvent, opts: RenderStatusOpts): Promise<
poll: null, poll: null,
quote: !event.quote ? null : await renderStatus(event.quote, { depth: depth + 1 }), quote: !event.quote ? null : await renderStatus(event.quote, { depth: depth + 1 }),
quote_id: event.quote?.id ?? null, quote_id: event.quote?.id ?? null,
uri: Conf.local(`/${note}`), uri: Conf.local(`/users/${account.acct}/statuses/${event.id}`),
url: Conf.local(`/${note}`), url: Conf.local(`/@${account.acct}/${event.id}`),
zapped: Boolean(zapEvent), zapped: Boolean(zapEvent),
ditto: { ditto: {
external_url: Conf.external(note), external_url: Conf.external(note),