mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
homeTimelineController: support exclude_replies, only_media params
This commit is contained in:
parent
9e7aeda364
commit
11adaef243
2 changed files with 31 additions and 2 deletions
|
|
@ -197,7 +197,7 @@ const accountStatusesQuerySchema = z.object({
|
||||||
limit: z.coerce.number().nonnegative().transform((v) => Math.min(v, 40)).catch(20),
|
limit: z.coerce.number().nonnegative().transform((v) => Math.min(v, 40)).catch(20),
|
||||||
exclude_replies: booleanParamSchema.optional(),
|
exclude_replies: booleanParamSchema.optional(),
|
||||||
tagged: z.string().optional(),
|
tagged: z.string().optional(),
|
||||||
only_media: z.coerce.boolean().optional(),
|
only_media: booleanParamSchema.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const accountStatusesController: AppController = async (c) => {
|
const accountStatusesController: AppController = async (c) => {
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,40 @@ import { paginated } from '@/utils/api.ts';
|
||||||
import { getTagSet } from '@/utils/tags.ts';
|
import { getTagSet } from '@/utils/tags.ts';
|
||||||
import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts';
|
import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts';
|
||||||
|
|
||||||
|
const homeQuerySchema = z.object({
|
||||||
|
exclude_replies: booleanParamSchema.optional(),
|
||||||
|
only_media: booleanParamSchema.optional(),
|
||||||
|
});
|
||||||
|
|
||||||
const homeTimelineController: AppController = async (c) => {
|
const homeTimelineController: AppController = async (c) => {
|
||||||
const params = c.get('pagination');
|
const params = c.get('pagination');
|
||||||
const pubkey = await c.get('signer')?.getPublicKey()!;
|
const pubkey = await c.get('signer')?.getPublicKey()!;
|
||||||
|
const result = homeQuerySchema.safeParse(c.req.query());
|
||||||
|
|
||||||
|
if (!result.success) {
|
||||||
|
return c.json({ error: 'Bad request', schema: result.error }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { exclude_replies, only_media } = result.data;
|
||||||
|
|
||||||
const authors = [...await getFeedPubkeys(pubkey)];
|
const authors = [...await getFeedPubkeys(pubkey)];
|
||||||
return renderStatuses(c, [{ authors, kinds: [1, 6, 20], ...params }]);
|
const filter: NostrFilter = { authors, kinds: [1, 6, 20], ...params };
|
||||||
|
|
||||||
|
const search: string[] = [];
|
||||||
|
|
||||||
|
if (only_media) {
|
||||||
|
search.push('media:true');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exclude_replies) {
|
||||||
|
search.push('reply:false');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (search.length) {
|
||||||
|
filter.search = search.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
return renderStatuses(c, [filter]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const publicQuerySchema = z.object({
|
const publicQuerySchema = z.object({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue