mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-18 04:44:24 +01:00
Move statuses view into its own file
This commit is contained in:
@@ -12,7 +12,8 @@ import { paginated, paginationSchema, parseBody } from '@/utils/web.ts';
|
||||
import { createEvent } from '@/utils/web.ts';
|
||||
import { renderEventAccounts } from '@/views.ts';
|
||||
import { renderAccount } from '@/views/mastodon/accounts.ts';
|
||||
import { accountFromPubkey, toRelationship, toStatus } from '@/views/nostr-to-mastoapi.ts';
|
||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||
import { accountFromPubkey, toRelationship } from '@/views/nostr-to-mastoapi.ts';
|
||||
|
||||
const usernameSchema = z
|
||||
.string().min(1).max(30)
|
||||
@@ -149,7 +150,7 @@ const accountStatusesController: AppController = async (c) => {
|
||||
events = events.filter((event) => !findReplyTag(event));
|
||||
}
|
||||
|
||||
const statuses = await Promise.all(events.map((event) => toStatus(event, c.get('pubkey'))));
|
||||
const statuses = await Promise.all(events.map((event) => renderStatus(event, c.get('pubkey'))));
|
||||
return paginated(c, events, statuses);
|
||||
};
|
||||
|
||||
@@ -259,7 +260,7 @@ const favouritesController: AppController = async (c) => {
|
||||
|
||||
const events1 = await mixer.getFilters([{ kinds: [1], ids }], { timeout: Time.seconds(1) });
|
||||
|
||||
const statuses = await Promise.all(events1.map((event) => toStatus(event, c.get('pubkey'))));
|
||||
const statuses = await Promise.all(events1.map((event) => renderStatus(event, c.get('pubkey'))));
|
||||
return paginated(c, events1, statuses);
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { nostrIdSchema } from '@/schemas/nostr.ts';
|
||||
import { dedupeEvents, Time } from '@/utils.ts';
|
||||
import { lookupNip05Cached } from '@/utils/nip05.ts';
|
||||
import { renderAccount } from '@/views/mastodon/accounts.ts';
|
||||
import { toStatus } from '@/views/nostr-to-mastoapi.ts';
|
||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||
|
||||
/** Matches NIP-05 names with or without an @ in front. */
|
||||
const ACCT_REGEX = /^@?(?:([\w.+-]+)@)?([\w.-]+)$/;
|
||||
@@ -50,7 +50,7 @@ const searchController: AppController = async (c) => {
|
||||
Promise.all(
|
||||
results
|
||||
.filter((event): event is Event<1> => event.kind === 1)
|
||||
.map((event) => toStatus(event, c.get('pubkey'))),
|
||||
.map((event) => renderStatus(event, c.get('pubkey'))),
|
||||
),
|
||||
]);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { type Event, ISO6391, z } from '@/deps.ts';
|
||||
import { getAncestors, getDescendants, getEvent } from '@/queries.ts';
|
||||
import { createEvent, paginationSchema, parseBody } from '@/utils/web.ts';
|
||||
import { renderEventAccounts } from '@/views.ts';
|
||||
import { toStatus } from '@/views/nostr-to-mastoapi.ts';
|
||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||
|
||||
const createStatusSchema = z.object({
|
||||
in_reply_to_id: z.string().regex(/[0-9a-f]{64}/).nullish(),
|
||||
@@ -31,7 +31,7 @@ const statusController: AppController = async (c) => {
|
||||
|
||||
const event = await getEvent(id, { kind: 1 });
|
||||
if (event) {
|
||||
return c.json(await toStatus(event, c.get('pubkey')));
|
||||
return c.json(await renderStatus(event, c.get('pubkey')));
|
||||
}
|
||||
|
||||
return c.json({ error: 'Event not found.' }, 404);
|
||||
@@ -83,7 +83,7 @@ const createStatusController: AppController = async (c) => {
|
||||
tags,
|
||||
}, c);
|
||||
|
||||
return c.json(await toStatus(event, c.get('pubkey')));
|
||||
return c.json(await renderStatus(event, c.get('pubkey')));
|
||||
};
|
||||
|
||||
const contextController: AppController = async (c) => {
|
||||
@@ -91,7 +91,7 @@ const contextController: AppController = async (c) => {
|
||||
const event = await getEvent(id, { kind: 1 });
|
||||
|
||||
async function renderStatuses(events: Event<1>[]) {
|
||||
const statuses = await Promise.all(events.map((event) => toStatus(event, c.get('pubkey'))));
|
||||
const statuses = await Promise.all(events.map((event) => renderStatus(event, c.get('pubkey'))));
|
||||
return statuses.filter(Boolean);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ const favouriteController: AppController = async (c) => {
|
||||
],
|
||||
}, c);
|
||||
|
||||
const status = await toStatus(target, c.get('pubkey'));
|
||||
const status = await renderStatus(target, c.get('pubkey'));
|
||||
|
||||
if (status) {
|
||||
status.favourited = true;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { type DittoFilter } from '@/filter.ts';
|
||||
import { getFeedPubkeys } from '@/queries.ts';
|
||||
import { Sub } from '@/subs.ts';
|
||||
import { bech32ToPubkey } from '@/utils.ts';
|
||||
import { toStatus } from '@/views/nostr-to-mastoapi.ts';
|
||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||
|
||||
/**
|
||||
* Streaming timelines/categories.
|
||||
@@ -63,7 +63,7 @@ const streamingController: AppController = (c) => {
|
||||
|
||||
if (filter) {
|
||||
for await (const event of Sub.sub(socket, '1', [filter])) {
|
||||
const status = await toStatus(event, pubkey);
|
||||
const status = await renderStatus(event, pubkey);
|
||||
if (status) {
|
||||
send('update', status);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getFeedPubkeys } from '@/queries.ts';
|
||||
import { booleanParamSchema } from '@/schema.ts';
|
||||
import { Time } from '@/utils.ts';
|
||||
import { paginated, paginationSchema } from '@/utils/web.ts';
|
||||
import { toStatus } from '@/views/nostr-to-mastoapi.ts';
|
||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||
|
||||
import type { AppContext, AppController } from '@/app.ts';
|
||||
|
||||
@@ -40,7 +40,7 @@ async function renderStatuses(c: AppContext, filters: DittoFilter<1>[]) {
|
||||
return c.json([]);
|
||||
}
|
||||
|
||||
const statuses = await Promise.all(events.map((event) => toStatus(event, c.get('pubkey'))));
|
||||
const statuses = await Promise.all(events.map((event) => renderStatus(event, c.get('pubkey'))));
|
||||
return paginated(c, events, statuses);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user