aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/server/follows.ts34
1 files changed, 24 insertions, 10 deletions
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts
index 37e8d88f7..60d36ed59 100644
--- a/server/controllers/api/server/follows.ts
+++ b/server/controllers/api/server/follows.ts
@@ -1,5 +1,6 @@
1import express from 'express' 1import express from 'express'
2import { getServerActor } from '@server/models/application/application' 2import { getServerActor } from '@server/models/application/application'
3import { ServerFollowCreate } from '@shared/models'
3import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' 4import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
4import { UserRight } from '../../../../shared/models/users' 5import { UserRight } from '../../../../shared/models/users'
5import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
@@ -20,16 +21,16 @@ import {
20 setDefaultSort 21 setDefaultSort
21} from '../../../middlewares' 22} from '../../../middlewares'
22import { 23import {
23 acceptOrRejectFollowerValidator, 24 acceptFollowerValidator,
24 instanceFollowersSortValidator,
25 instanceFollowingSortValidator,
26 followValidator, 25 followValidator,
27 getFollowerValidator, 26 getFollowerValidator,
27 instanceFollowersSortValidator,
28 instanceFollowingSortValidator,
28 listFollowsValidator, 29 listFollowsValidator,
30 rejectFollowerValidator,
29 removeFollowingValidator 31 removeFollowingValidator
30} from '../../../middlewares/validators' 32} from '../../../middlewares/validators'
31import { ActorFollowModel } from '../../../models/actor/actor-follow' 33import { ActorFollowModel } from '../../../models/actor/actor-follow'
32import { ServerFollowCreate } from '@shared/models'
33 34
34const serverFollowsRouter = express.Router() 35const serverFollowsRouter = express.Router()
35serverFollowsRouter.get('/following', 36serverFollowsRouter.get('/following',
@@ -69,22 +70,22 @@ serverFollowsRouter.delete('/followers/:nameWithHost',
69 authenticate, 70 authenticate,
70 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), 71 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
71 asyncMiddleware(getFollowerValidator), 72 asyncMiddleware(getFollowerValidator),
72 asyncMiddleware(removeOrRejectFollower) 73 asyncMiddleware(removeFollower)
73) 74)
74 75
75serverFollowsRouter.post('/followers/:nameWithHost/reject', 76serverFollowsRouter.post('/followers/:nameWithHost/reject',
76 authenticate, 77 authenticate,
77 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), 78 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
78 asyncMiddleware(getFollowerValidator), 79 asyncMiddleware(getFollowerValidator),
79 acceptOrRejectFollowerValidator, 80 rejectFollowerValidator,
80 asyncMiddleware(removeOrRejectFollower) 81 asyncMiddleware(rejectFollower)
81) 82)
82 83
83serverFollowsRouter.post('/followers/:nameWithHost/accept', 84serverFollowsRouter.post('/followers/:nameWithHost/accept',
84 authenticate, 85 authenticate,
85 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), 86 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
86 asyncMiddleware(getFollowerValidator), 87 asyncMiddleware(getFollowerValidator),
87 acceptOrRejectFollowerValidator, 88 acceptFollowerValidator,
88 asyncMiddleware(acceptFollower) 89 asyncMiddleware(acceptFollower)
89) 90)
90 91
@@ -176,10 +177,23 @@ async function removeFollowing (req: express.Request, res: express.Response) {
176 return res.status(HttpStatusCode.NO_CONTENT_204).end() 177 return res.status(HttpStatusCode.NO_CONTENT_204).end()
177} 178}
178 179
179async function removeOrRejectFollower (req: express.Request, res: express.Response) { 180async function rejectFollower (req: express.Request, res: express.Response) {
180 const follow = res.locals.follow 181 const follow = res.locals.follow
181 182
182 await sendReject(follow.url, follow.ActorFollower, follow.ActorFollowing) 183 follow.state = 'rejected'
184 await follow.save()
185
186 sendReject(follow.url, follow.ActorFollower, follow.ActorFollowing)
187
188 return res.status(HttpStatusCode.NO_CONTENT_204).end()
189}
190
191async function removeFollower (req: express.Request, res: express.Response) {
192 const follow = res.locals.follow
193
194 if (follow.state === 'accepted' || follow.state === 'pending') {
195 sendReject(follow.url, follow.ActorFollower, follow.ActorFollowing)
196 }
183 197
184 await follow.destroy() 198 await follow.destroy()
185 199