Make verify_credentials and update_credentials return a consistent CredentialAccount object

This commit is contained in:
Alex Gleason
2024-10-11 16:25:29 -05:00
parent fab0c8a409
commit c5ddd2ebb7
3 changed files with 34 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
import { NSchema as n } from '@nostrify/nostrify';
import { type NostrEvent, NSchema as n } from '@nostrify/nostrify';
import { escape } from 'entities';
import { nip19, UnsignedEvent } from 'nostr-tools';
@@ -12,16 +12,19 @@ import { faviconCache } from '@/utils/favicon.ts';
import { nostrDate, nostrNow } from '@/utils.ts';
import { renderEmojis } from '@/views/mastodon/emojis.ts';
interface ToAccountOpts {
withSource?: boolean;
}
type ToAccountOpts = {
withSource: true;
settingsStore: Record<string, unknown> | undefined;
captcha: NostrEvent | undefined;
} | {
withSource?: false;
};
async function renderAccount(
event: Omit<DittoEvent, 'id' | 'sig'>,
opts: ToAccountOpts = {},
signal = AbortSignal.timeout(3000),
): Promise<MastodonAccount> {
const { withSource = false } = opts;
const { pubkey } = event;
const names = getTagSet(event.user?.tags ?? [], 'n');
@@ -76,7 +79,7 @@ async function renderAccount(
locked: false,
note: about ? escape(about) : '',
roles: [],
source: withSource
source: opts.withSource
? {
fields: [],
language: '',
@@ -88,7 +91,7 @@ async function renderAccount(
nip05,
},
ditto: {
captcha_solved: false,
captcha_solved: Boolean(opts.captcha),
},
}
: undefined,
@@ -107,7 +110,7 @@ async function renderAccount(
is_moderator: names.has('admin') || names.has('moderator'),
is_suggested: names.has('suggested'),
is_local: parsed05?.domain === Conf.url.host,
settings_store: undefined as unknown,
settings_store: opts.withSource ? opts.settingsStore : undefined,
tags: [...getTagSet(event.user?.tags ?? [], 't')],
favicon: favicon?.toString(),
},