Add unblock and unfollow endpoints

This commit is contained in:
Alex Gleason
2024-01-01 12:50:09 -06:00
parent 5b7c3a1d5e
commit 3807ca175f
2 changed files with 40 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ import { type DittoFilter } from '@/filter.ts';
import { getAuthor, getFollowedPubkeys } from '@/queries.ts';
import { booleanParamSchema, fileSchema } from '@/schema.ts';
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
import { addTag } from '@/tags.ts';
import { addTag, deleteTag } from '@/tags.ts';
import { uploadFile } from '@/upload.ts';
import { lookupAccount, nostrNow } from '@/utils.ts';
import { paginated, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts';
@@ -213,6 +213,7 @@ const updateCredentialsController: AppController = async (c) => {
return c.json(account);
};
/** https://docs.joinmastodon.org/methods/accounts/#follow */
const followController: AppController = async (c) => {
const sourcePubkey = c.get('pubkey')!;
const targetPubkey = c.req.param('pubkey');
@@ -227,6 +228,21 @@ const followController: AppController = async (c) => {
return c.json(relationship);
};
/** https://docs.joinmastodon.org/methods/accounts/#unfollow */
const unfollowController: AppController = async (c) => {
const sourcePubkey = c.get('pubkey')!;
const targetPubkey = c.req.param('pubkey');
await updateListEvent(
{ kinds: [3], authors: [sourcePubkey] },
(tags) => deleteTag(tags, ['p', targetPubkey]),
c,
);
const relationship = await renderRelationship(sourcePubkey, targetPubkey);
return c.json(relationship);
};
const followersController: AppController = (c) => {
const pubkey = c.req.param('pubkey');
const params = paginationSchema.parse(c.req.query());
@@ -254,6 +270,21 @@ const blockController: AppController = async (c) => {
return c.json(relationship);
};
/** https://docs.joinmastodon.org/methods/accounts/#unblock */
const unblockController: AppController = async (c) => {
const sourcePubkey = c.get('pubkey')!;
const targetPubkey = c.req.param('pubkey');
await updateListEvent(
{ kinds: [10000], authors: [sourcePubkey] },
(tags) => deleteTag(tags, ['p', targetPubkey]),
c,
);
const relationship = await renderRelationship(sourcePubkey, targetPubkey);
return c.json(relationship);
};
const favouritesController: AppController = async (c) => {
const pubkey = c.get('pubkey')!;
const params = paginationSchema.parse(c.req.query());
@@ -290,6 +321,8 @@ export {
followersController,
followingController,
relationshipsController,
unblockController,
unfollowController,
updateCredentialsController,
verifyCredentialsController,
};