Add views/mastodon/accounts.ts, views/mastodon/emojis.ts

This commit is contained in:
Alex Gleason
2023-10-06 15:28:02 -05:00
parent cb1141784e
commit 0b77e7d888
6 changed files with 138 additions and 121 deletions

View File

@@ -11,7 +11,8 @@ import { isFollowing, lookupAccount, nostrNow, Time } from '@/utils.ts';
import { paginated, paginationSchema, parseBody } from '@/utils/web.ts';
import { createEvent } from '@/utils/web.ts';
import { renderEventAccounts } from '@/views.ts';
import { accountFromPubkey, toAccount, toRelationship, toStatus } from '@/views/nostr-to-mastoapi.ts';
import { renderAccount } from '@/views/mastodon/accounts.ts';
import { accountFromPubkey, toRelationship, toStatus } from '@/views/nostr-to-mastoapi.ts';
const usernameSchema = z
.string().min(1).max(30)
@@ -60,7 +61,7 @@ const verifyCredentialsController: AppController = async (c) => {
const event = await getAuthor(pubkey);
if (event) {
return c.json(await toAccount(event, { withSource: true }));
return c.json(await renderAccount(event, { withSource: true }));
} else {
return c.json(await accountFromPubkey(pubkey, { withSource: true }));
}
@@ -71,7 +72,7 @@ const accountController: AppController = async (c) => {
const event = await getAuthor(pubkey);
if (event) {
return c.json(await toAccount(event));
return c.json(await renderAccount(event));
}
return c.json({ error: 'Could not find user.' }, 404);
@@ -86,7 +87,7 @@ const accountLookupController: AppController = async (c) => {
const event = await lookupAccount(decodeURIComponent(acct));
if (event) {
return c.json(await toAccount(event));
return c.json(await renderAccount(event));
}
return c.json({ error: 'Could not find user.' }, 404);
@@ -101,7 +102,7 @@ const accountSearchController: AppController = async (c) => {
const event = await lookupAccount(decodeURIComponent(q));
if (event) {
return c.json([await toAccount(event)]);
return c.json([await renderAccount(event)]);
}
return c.json([]);
@@ -199,7 +200,7 @@ const updateCredentialsController: AppController = async (c) => {
tags: [],
}, c);
const account = await toAccount(event);
const account = await renderAccount(event);
return c.json(account);
};
@@ -237,7 +238,7 @@ const followingController: AppController = async (c) => {
// TODO: pagination by offset.
const accounts = await Promise.all(pubkeys.map(async (pubkey) => {
const event = await getAuthor(pubkey);
return event ? await toAccount(event) : undefined;
return event ? await renderAccount(event) : undefined;
}));
return c.json(accounts.filter(Boolean));

View File

@@ -6,7 +6,8 @@ import { booleanParamSchema } from '@/schema.ts';
import { nostrIdSchema } from '@/schemas/nostr.ts';
import { dedupeEvents, Time } from '@/utils.ts';
import { lookupNip05Cached } from '@/utils/nip05.ts';
import { toAccount, toStatus } from '@/views/nostr-to-mastoapi.ts';
import { renderAccount } from '@/views/mastodon/accounts.ts';
import { toStatus } from '@/views/nostr-to-mastoapi.ts';
/** Matches NIP-05 names with or without an @ in front. */
const ACCT_REGEX = /^@?(?:([\w.+-]+)@)?([\w.-]+)$/;
@@ -44,7 +45,7 @@ const searchController: AppController = async (c) => {
Promise.all(
results
.filter((event): event is Event<0> => event.kind === 0)
.map((event) => toAccount(event)),
.map((event) => renderAccount(event)),
),
Promise.all(
results