mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Merge branch 'home-filters' into 'main'
homeTimelineController: support exclude_replies, only_media params See merge request soapbox-pub/ditto!648
This commit is contained in:
commit
e468072b55
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),
|
||||
exclude_replies: booleanParamSchema.optional(),
|
||||
tagged: z.string().optional(),
|
||||
only_media: z.coerce.boolean().optional(),
|
||||
only_media: booleanParamSchema.optional(),
|
||||
});
|
||||
|
||||
const accountStatusesController: AppController = async (c) => {
|
||||
|
|
|
|||
|
|
@ -10,11 +10,40 @@ import { paginated } from '@/utils/api.ts';
|
|||
import { getTagSet } from '@/utils/tags.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 params = c.get('pagination');
|
||||
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)];
|
||||
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({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue