renderAccount: stop calling findUser, rely on event hydration
This commit is contained in:
parent
1549398f83
commit
c71d3f9d3c
|
@ -1,5 +1,4 @@
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { findUser } from '@/db/users.ts';
|
|
||||||
import { lodash, nip19, type UnsignedEvent } from '@/deps.ts';
|
import { lodash, nip19, type UnsignedEvent } from '@/deps.ts';
|
||||||
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
|
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
|
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
|
||||||
|
@ -30,11 +29,8 @@ async function renderAccount(
|
||||||
} = jsonMetaContentSchema.parse(event.content);
|
} = jsonMetaContentSchema.parse(event.content);
|
||||||
|
|
||||||
const npub = nip19.npubEncode(pubkey);
|
const npub = nip19.npubEncode(pubkey);
|
||||||
|
const parsed05 = await parseAndVerifyNip05(nip05, pubkey);
|
||||||
const [user, parsed05] = await Promise.all([
|
const role = event.user?.tags.find(([name]) => name === 'role')?.[1] ?? 'user';
|
||||||
findUser({ pubkey }),
|
|
||||||
parseAndVerifyNip05(nip05, pubkey),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: pubkey,
|
id: pubkey,
|
||||||
|
@ -42,7 +38,7 @@ async function renderAccount(
|
||||||
avatar: picture,
|
avatar: picture,
|
||||||
avatar_static: picture,
|
avatar_static: picture,
|
||||||
bot: false,
|
bot: false,
|
||||||
created_at: user ? user.inserted_at.toISOString() : nostrDate(event.created_at).toISOString(),
|
created_at: nostrDate(event.user?.created_at ?? event.created_at).toISOString(),
|
||||||
discoverable: true,
|
discoverable: true,
|
||||||
display_name: name,
|
display_name: name,
|
||||||
emojis: renderEmojis(event),
|
emojis: renderEmojis(event),
|
||||||
|
@ -75,11 +71,11 @@ async function renderAccount(
|
||||||
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 })),
|
||||||
is_registered: Boolean(user),
|
is_registered: Boolean(event.user),
|
||||||
},
|
},
|
||||||
pleroma: {
|
pleroma: {
|
||||||
is_admin: user?.admin || false,
|
is_admin: role === 'admin',
|
||||||
is_moderator: user?.admin || false,
|
is_moderator: ['admin', 'moderator'].includes(role),
|
||||||
},
|
},
|
||||||
nostr: {
|
nostr: {
|
||||||
pubkey,
|
pubkey,
|
||||||
|
|
Loading…
Reference in New Issue