From 4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Jul 2021 14:15:15 +0200 Subject: Add ability for instances to follow any actor --- server/controllers/api/server/follows.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index e6f4f6b92..cbe6b7e4f 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts @@ -29,6 +29,7 @@ import { removeFollowingValidator } from '../../../middlewares/validators' import { ActorFollowModel } from '../../../models/actor/actor-follow' +import { ServerFollowCreate } from '@shared/models' const serverFollowsRouter = express.Router() serverFollowsRouter.get('/following', @@ -45,10 +46,10 @@ serverFollowsRouter.post('/following', ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), followValidator, setBodyHostsPort, - asyncMiddleware(followInstance) + asyncMiddleware(addFollow) ) -serverFollowsRouter.delete('/following/:host', +serverFollowsRouter.delete('/following/:hostOrHandle', authenticate, ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), asyncMiddleware(removeFollowingValidator), @@ -125,8 +126,8 @@ async function listFollowers (req: express.Request, res: express.Response) { return res.json(getFormattedObjects(resultList.data, resultList.total)) } -async function followInstance (req: express.Request, res: express.Response) { - const hosts = req.body.hosts as string[] +async function addFollow (req: express.Request, res: express.Response) { + const { hosts, handles } = req.body as ServerFollowCreate const follower = await getServerActor() for (const host of hosts) { @@ -139,6 +140,18 @@ async function followInstance (req: express.Request, res: express.Response) { JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) } + for (const handle of handles) { + const [ name, host ] = handle.split('@') + + const payload = { + host, + name, + followerActorId: follower.id + } + + JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) + } + return res.status(HttpStatusCode.NO_CONTENT_204).end() } -- cgit v1.2.3