mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-09 00:24:20 +01:00
Support GET /api/v1/blocks
This commit is contained in:
@@ -12,7 +12,7 @@ import { uploadFile } from '@/upload.ts';
|
||||
import { lookupAccount, nostrNow } from '@/utils.ts';
|
||||
import { paginated, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts';
|
||||
import { createEvent } from '@/utils/web.ts';
|
||||
import { renderEventAccounts } from '@/views.ts';
|
||||
import { renderAccounts, renderEventAccounts } from '@/views.ts';
|
||||
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
|
||||
import { renderRelationship } from '@/views/mastodon/relationships.ts';
|
||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||
@@ -236,16 +236,10 @@ const followersController: AppController = (c) => {
|
||||
const followingController: AppController = async (c) => {
|
||||
const pubkey = c.req.param('pubkey');
|
||||
const pubkeys = await getFollowedPubkeys(pubkey);
|
||||
|
||||
// TODO: pagination by offset.
|
||||
const accounts = await Promise.all(pubkeys.map(async (pubkey) => {
|
||||
const event = await getAuthor(pubkey);
|
||||
return event ? await renderAccount(event) : undefined;
|
||||
}));
|
||||
|
||||
return c.json(accounts.filter(Boolean));
|
||||
return renderAccounts(c, pubkeys);
|
||||
};
|
||||
|
||||
/** https://docs.joinmastodon.org/methods/accounts/#block */
|
||||
const blockController: AppController = async (c) => {
|
||||
const sourcePubkey = c.get('pubkey')!;
|
||||
const targetPubkey = c.req.param('pubkey');
|
||||
|
||||
22
src/controllers/api/blocks.ts
Normal file
22
src/controllers/api/blocks.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { type AppController } from '@/app.ts';
|
||||
import { eventsDB } from '@/db/events.ts';
|
||||
import { getTagSet } from '@/tags.ts';
|
||||
import { renderAccounts } from '@/views.ts';
|
||||
|
||||
/** https://docs.joinmastodon.org/methods/blocks/#get */
|
||||
const blocksController: AppController = async (c) => {
|
||||
const pubkey = c.get('pubkey')!;
|
||||
|
||||
const [event10000] = await eventsDB.getEvents([
|
||||
{ kinds: [10000], authors: [pubkey], limit: 1 },
|
||||
]);
|
||||
|
||||
if (event10000) {
|
||||
const pubkeys = getTagSet(event10000.tags, 'p');
|
||||
return renderAccounts(c, [...pubkeys].reverse());
|
||||
} else {
|
||||
return c.json([]);
|
||||
}
|
||||
};
|
||||
|
||||
export { blocksController };
|
||||
Reference in New Issue
Block a user