Merge branch 'suggested-timeline' into 'main'
Add suggested timeline endpoint See merge request soapbox-pub/ditto!349
This commit is contained in:
commit
29753795e4
|
@ -76,6 +76,7 @@ import {
|
||||||
hashtagTimelineController,
|
hashtagTimelineController,
|
||||||
homeTimelineController,
|
homeTimelineController,
|
||||||
publicTimelineController,
|
publicTimelineController,
|
||||||
|
suggestedTimelineController,
|
||||||
} from '@/controllers/api/timelines.ts';
|
} from '@/controllers/api/timelines.ts';
|
||||||
import { trendingStatusesController, trendingTagsController } from '@/controllers/api/trends.ts';
|
import { trendingStatusesController, trendingTagsController } from '@/controllers/api/trends.ts';
|
||||||
import { indexController } from '@/controllers/site.ts';
|
import { indexController } from '@/controllers/site.ts';
|
||||||
|
@ -194,6 +195,7 @@ app.post('/api/v2/media', mediaController);
|
||||||
app.get('/api/v1/timelines/home', requireSigner, homeTimelineController);
|
app.get('/api/v1/timelines/home', requireSigner, homeTimelineController);
|
||||||
app.get('/api/v1/timelines/public', publicTimelineController);
|
app.get('/api/v1/timelines/public', publicTimelineController);
|
||||||
app.get('/api/v1/timelines/tag/:hashtag', hashtagTimelineController);
|
app.get('/api/v1/timelines/tag/:hashtag', hashtagTimelineController);
|
||||||
|
app.get('/api/v1/timeines/suggested', suggestedTimelineController);
|
||||||
|
|
||||||
app.get('/api/v1/preferences', preferencesController);
|
app.get('/api/v1/preferences', preferencesController);
|
||||||
app.get('/api/v1/search', searchController);
|
app.get('/api/v1/search', searchController);
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { getFeedPubkeys } from '@/queries.ts';
|
||||||
import { booleanParamSchema } from '@/schema.ts';
|
import { booleanParamSchema } from '@/schema.ts';
|
||||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||||
import { paginated, paginationSchema } from '@/utils/api.ts';
|
import { paginated, paginationSchema } from '@/utils/api.ts';
|
||||||
|
import { getTagSet } from '@/utils/tags.ts';
|
||||||
import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts';
|
import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts';
|
||||||
|
|
||||||
const homeTimelineController: AppController = async (c) => {
|
const homeTimelineController: AppController = async (c) => {
|
||||||
|
@ -25,7 +26,7 @@ const publicTimelineController: AppController = (c) => {
|
||||||
const params = paginationSchema.parse(c.req.query());
|
const params = paginationSchema.parse(c.req.query());
|
||||||
const { local, instance } = publicQuerySchema.parse(c.req.query());
|
const { local, instance } = publicQuerySchema.parse(c.req.query());
|
||||||
|
|
||||||
const filter: NostrFilter = { kinds: [1, 6], ...params };
|
const filter: NostrFilter = { kinds: [1], ...params };
|
||||||
|
|
||||||
if (local) {
|
if (local) {
|
||||||
filter.search = `domain:${Conf.url.host}`;
|
filter.search = `domain:${Conf.url.host}`;
|
||||||
|
@ -42,6 +43,19 @@ const hashtagTimelineController: AppController = (c) => {
|
||||||
return renderStatuses(c, [{ kinds: [1], '#t': [hashtag], ...params }]);
|
return renderStatuses(c, [{ kinds: [1], '#t': [hashtag], ...params }]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const suggestedTimelineController: AppController = async (c) => {
|
||||||
|
const store = c.get('store');
|
||||||
|
const params = paginationSchema.parse(c.req.query());
|
||||||
|
|
||||||
|
const [follows] = await store.query(
|
||||||
|
[{ kinds: [3], authors: [Conf.pubkey], limit: 1 }],
|
||||||
|
);
|
||||||
|
|
||||||
|
const authors = [...getTagSet(follows?.tags ?? [], 'p')];
|
||||||
|
|
||||||
|
return renderStatuses(c, [{ authors, kinds: [1], ...params }]);
|
||||||
|
};
|
||||||
|
|
||||||
/** Render statuses for timelines. */
|
/** Render statuses for timelines. */
|
||||||
async function renderStatuses(c: AppContext, filters: NostrFilter[]) {
|
async function renderStatuses(c: AppContext, filters: NostrFilter[]) {
|
||||||
const { signal } = c.req.raw;
|
const { signal } = c.req.raw;
|
||||||
|
@ -71,4 +85,4 @@ async function renderStatuses(c: AppContext, filters: NostrFilter[]) {
|
||||||
return paginated(c, events, statuses);
|
return paginated(c, events, statuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { hashtagTimelineController, homeTimelineController, publicTimelineController };
|
export { hashtagTimelineController, homeTimelineController, publicTimelineController, suggestedTimelineController };
|
||||||
|
|
Loading…
Reference in New Issue