]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-reject.ts
Stronger actor association typing in AP functions
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-reject.ts
CommitLineData
0e9c48c2
C
1import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub'
2import { ActorModel } from '../../../models/activitypub/actor'
5b9c965d 3import { getActorFollowActivityPubUrl, getActorFollowRejectActivityPubUrl } from '../url'
0e9c48c2
C
4import { unicastTo } from './utils'
5import { buildFollowActivity } from './send-follow'
6import { logger } from '../../../helpers/logger'
5224c394 7import { SignatureActorModel } from '../../../typings/models'
0e9c48c2 8
5224c394 9async function sendReject (follower: SignatureActorModel, following: ActorModel) {
0e9c48c2
C
10 if (!follower.serverId) { // This should never happen
11 logger.warn('Do not sending reject to local follower.')
12 return
13 }
14
15 logger.info('Creating job to reject follower %s.', follower.url)
16
5b9c965d
C
17 const followUrl = getActorFollowActivityPubUrl(follower, following)
18 const followData = buildFollowActivity(followUrl, follower, following)
0e9c48c2 19
5b9c965d
C
20 const url = getActorFollowRejectActivityPubUrl(follower, following)
21 const data = buildRejectActivity(url, following, followData)
0e9c48c2 22
5b9c965d 23 return unicastTo(data, following, follower.inboxUrl)
0e9c48c2
C
24}
25
26// ---------------------------------------------------------------------------
27
28export {
29 sendReject
30}
31
32// ---------------------------------------------------------------------------
33
34function buildRejectActivity (url: string, byActor: ActorModel, followActivityData: ActivityFollow): ActivityReject {
35 return {
36 type: 'Reject',
37 id: url,
38 actor: byActor.url,
39 object: followActivityData
40 }
41}