Add hashtag timeline

This commit is contained in:
Alex Gleason
2023-08-28 19:51:21 -05:00
parent d8b7608346
commit ccb8c534ca
2 changed files with 24 additions and 2 deletions

View File

@@ -1,8 +1,10 @@
import { z } from '@/deps.ts';
import * as mixer from '@/mixer.ts';
import { getFeed, getPublicFeed } from '@/queries.ts';
import { booleanParamSchema } from '@/schema.ts';
import { toStatus } from '@/transformers/nostr-to-mastoapi.ts';
import { buildLinkHeader, paginationSchema } from '@/utils/web.ts';
import { Time } from '@/utils.ts';
import type { AppController } from '@/app.ts';
@@ -40,4 +42,23 @@ const publicController: AppController = async (c) => {
return c.json(statuses, 200, link ? { link } : undefined);
};
export { homeController, publicController };
const hashtagTimelineController: AppController = async (c) => {
const hashtag = c.req.param('hashtag')!;
const params = paginationSchema.parse(c.req.query());
const events = await mixer.getFilters(
[{ kinds: [1], '#t': [hashtag], ...params }],
{ timeout: Time.seconds(3) },
);
if (!events.length) {
return c.json([]);
}
const statuses = (await Promise.all(events.map(toStatus))).filter(Boolean);
const link = buildLinkHeader(c.req.url, events);
return c.json(statuses, 200, link ? { link } : undefined);
};
export { hashtagTimelineController, homeController, publicController };