Merge branch 'favourites' into 'develop'

Add /api/v1/favourites

Closes #64

See merge request soapbox-pub/ditto!32
This commit is contained in:
Alex Gleason 2023-09-01 18:17:02 +00:00
commit 6ef997fbd9
No known key found for this signature in database
2 changed files with 23 additions and 2 deletions

View File

@ -17,6 +17,7 @@ import {
accountSearchController, accountSearchController,
accountStatusesController, accountStatusesController,
createAccountController, createAccountController,
favouritesController,
followController, followController,
followersController, followersController,
followingController, followingController,
@ -133,6 +134,7 @@ app.get('/api/v1/trends/tags', trendingTagsController);
app.get('/api/v1/trends', trendingTagsController); app.get('/api/v1/trends', trendingTagsController);
app.get('/api/v1/notifications', requirePubkey, notificationsController); app.get('/api/v1/notifications', requirePubkey, notificationsController);
app.get('/api/v1/favourites', requirePubkey, favouritesController);
// Not (yet) implemented. // Not (yet) implemented.
app.get('/api/v1/bookmarks', emptyArrayController); 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/domain_blocks', emptyArrayController);
app.get('/api/v1/markers', emptyObjectController); app.get('/api/v1/markers', emptyObjectController);
app.get('/api/v1/conversations', emptyArrayController); app.get('/api/v1/conversations', emptyArrayController);
app.get('/api/v1/favourites', emptyArrayController);
app.get('/api/v1/lists', emptyArrayController); app.get('/api/v1/lists', emptyArrayController);
app.get('/', indexController); app.get('/', indexController);

View File

@ -5,7 +5,7 @@ import { getAuthor, getFollowedPubkeys, getFollows, syncUser } from '@/queries.t
import { booleanParamSchema } from '@/schema.ts'; import { booleanParamSchema } from '@/schema.ts';
import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
import { toAccount, toRelationship, toStatus } from '@/transformers/nostr-to-mastoapi.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 { paginated, paginationSchema, parseBody } from '@/utils/web.ts';
import { createEvent } from '@/utils/web.ts'; import { createEvent } from '@/utils/web.ts';
import { renderEventAccounts } from '@/views.ts'; import { renderEventAccounts } from '@/views.ts';
@ -193,12 +193,32 @@ const followingController: AppController = async (c) => {
return c.json(accounts.filter(Boolean)); 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 { export {
accountController, accountController,
accountLookupController, accountLookupController,
accountSearchController, accountSearchController,
accountStatusesController, accountStatusesController,
createAccountController, createAccountController,
favouritesController,
followController, followController,
followersController, followersController,
followingController, followingController,