1 import { pick } from 'lodash'
2 import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models'
3 import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
4 import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 import { ServerInfo } from './servers'
7 export class FollowsCommand extends AbstractCommand {
9 getFollowers (options: OverrideCommandOptions & {
14 actorType?: ActivityPubActorType
17 const path = '/api/v1/server/followers'
19 const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]
20 const query = pick(options, toPick)
22 return this.getRequestBody<ResultList<ActorFollow>>({
29 defaultExpectedStatus: HttpStatusCode.OK_200
33 getFollowings (options: OverrideCommandOptions & {
38 actorType?: ActivityPubActorType
41 const path = '/api/v1/server/following'
43 const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]
44 const query = pick(options, toPick)
46 return this.getRequestBody<ResultList<ActorFollow>>({
53 defaultExpectedStatus: HttpStatusCode.OK_200
57 follow (options: OverrideCommandOptions & {
60 const path = '/api/v1/server/following'
62 const hosts = options.targets.map(f => f.replace(/^http:\/\//, ''))
64 return this.postBodyRequest({
69 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
73 async unfollow (options: OverrideCommandOptions & {
76 const path = '/api/v1/server/following/' + options.target.host
78 return this.deleteRequest({
82 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
86 acceptFollower (options: OverrideCommandOptions & {
89 const path = '/api/v1/server/followers/' + options.follower + '/accept'
91 return this.postBodyRequest({
95 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
99 rejectFollower (options: OverrideCommandOptions & {
102 const path = '/api/v1/server/followers/' + options.follower + '/reject'
104 return this.postBodyRequest({
108 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
112 removeFollower (options: OverrideCommandOptions & {
115 const path = '/api/v1/server/followers/peertube@' + options.follower.host
117 return this.deleteRequest({
121 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204