Merge branch 'favourites' into 'develop'
Add /api/v1/favourites Closes #64 See merge request soapbox-pub/ditto!32
This commit is contained in:
commit
6ef997fbd9
|
@ -17,6 +17,7 @@ import {
|
|||
accountSearchController,
|
||||
accountStatusesController,
|
||||
createAccountController,
|
||||
favouritesController,
|
||||
followController,
|
||||
followersController,
|
||||
followingController,
|
||||
|
@ -133,6 +134,7 @@ app.get('/api/v1/trends/tags', trendingTagsController);
|
|||
app.get('/api/v1/trends', trendingTagsController);
|
||||
|
||||
app.get('/api/v1/notifications', requirePubkey, notificationsController);
|
||||
app.get('/api/v1/favourites', requirePubkey, favouritesController);
|
||||
|
||||
// Not (yet) implemented.
|
||||
app.get('/api/v1/bookmarks', emptyArrayController);
|
||||
|
@ -144,7 +146,6 @@ app.get('/api/v1/mutes', emptyArrayController);
|
|||
app.get('/api/v1/domain_blocks', emptyArrayController);
|
||||
app.get('/api/v1/markers', emptyObjectController);
|
||||
app.get('/api/v1/conversations', emptyArrayController);
|
||||
app.get('/api/v1/favourites', emptyArrayController);
|
||||
app.get('/api/v1/lists', emptyArrayController);
|
||||
|
||||
app.get('/', indexController);
|
||||
|
|
|
@ -5,7 +5,7 @@ import { getAuthor, getFollowedPubkeys, getFollows, syncUser } from '@/queries.t
|
|||
import { booleanParamSchema } from '@/schema.ts';
|
||||
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
|
||||
import { toAccount, toRelationship, toStatus } from '@/transformers/nostr-to-mastoapi.ts';
|
||||
import { isFollowing, lookupAccount } from '@/utils.ts';
|
||||
import { isFollowing, lookupAccount, Time } from '@/utils.ts';
|
||||
import { paginated, paginationSchema, parseBody } from '@/utils/web.ts';
|
||||
import { createEvent } from '@/utils/web.ts';
|
||||
import { renderEventAccounts } from '@/views.ts';
|
||||
|
@ -193,12 +193,32 @@ const followingController: AppController = async (c) => {
|
|||
return c.json(accounts.filter(Boolean));
|
||||
};
|
||||
|
||||
const favouritesController: AppController = async (c) => {
|
||||
const pubkey = c.get('pubkey')!;
|
||||
const params = paginationSchema.parse(c.req.query());
|
||||
|
||||
const events7 = await mixer.getFilters(
|
||||
[{ kinds: [7], authors: [pubkey], ...params }],
|
||||
{ timeout: Time.seconds(1) },
|
||||
);
|
||||
|
||||
const ids = events7
|
||||
.map((event) => event.tags.find((tag) => tag[0] === 'e')?.[1])
|
||||
.filter((id): id is string => !!id);
|
||||
|
||||
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'))));
|
||||
return paginated(c, events1, statuses);
|
||||
};
|
||||
|
||||
export {
|
||||
accountController,
|
||||
accountLookupController,
|
||||
accountSearchController,
|
||||
accountStatusesController,
|
||||
createAccountController,
|
||||
favouritesController,
|
||||
followController,
|
||||
followersController,
|
||||
followingController,
|
||||
|
|
Loading…
Reference in New Issue