]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/activitypub/send/send-reject.ts
Refactor AP context builder
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-reject.ts
... / ...
CommitLineData
1import { ActivityFollow, ActivityReject } from '@shared/models'
2import { logger } from '../../../helpers/logger'
3import { MActor } from '../../../types/models'
4import { getLocalActorFollowRejectActivityPubUrl } from '../url'
5import { buildFollowActivity } from './send-follow'
6import { unicastTo } from './shared/send-utils'
7
8function sendReject (followUrl: string, follower: MActor, following: MActor) {
9 if (!follower.serverId) { // This should never happen
10 logger.warn('Do not sending reject to local follower.')
11 return
12 }
13
14 logger.info('Creating job to reject follower %s.', follower.url)
15
16 const followData = buildFollowActivity(followUrl, follower, following)
17
18 const url = getLocalActorFollowRejectActivityPubUrl(follower, following)
19 const data = buildRejectActivity(url, following, followData)
20
21 return unicastTo({ data, byActor: following, toActorUrl: follower.inboxUrl, contextType: 'Reject' })
22}
23
24// ---------------------------------------------------------------------------
25
26export {
27 sendReject
28}
29
30// ---------------------------------------------------------------------------
31
32function buildRejectActivity (url: string, byActor: MActor, followActivityData: ActivityFollow): ActivityReject {
33 return {
34 type: 'Reject',
35 id: url,
36 actor: byActor.url,
37 object: followActivityData
38 }
39}