]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/activitypub/send/send-accept.ts
Add ability to search a video with an URL
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-accept.ts
... / ...
CommitLineData
1import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub'
2import { ActorModel } from '../../../models/activitypub/actor'
3import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
4import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url'
5import { unicastTo } from './utils'
6import { followActivityData } from './send-follow'
7import { logger } from '../../../helpers/logger'
8
9async function sendAccept (actorFollow: ActorFollowModel) {
10 const follower = actorFollow.ActorFollower
11 const me = actorFollow.ActorFollowing
12
13 if (!follower.serverId) { // This should never happen
14 logger.warn('Do not sending accept to local follower.')
15 return
16 }
17
18 logger.info('Creating job to accept follower %s.', follower.url)
19
20 const followUrl = getActorFollowActivityPubUrl(actorFollow)
21 const followData = followActivityData(followUrl, follower, me)
22
23 const url = getActorFollowAcceptActivityPubUrl(actorFollow)
24 const data = acceptActivityData(url, me, followData)
25
26 return unicastTo(data, me, follower.inboxUrl)
27}
28
29// ---------------------------------------------------------------------------
30
31export {
32 sendAccept
33}
34
35// ---------------------------------------------------------------------------
36
37function acceptActivityData (url: string, byActor: ActorModel, followActivityData: ActivityFollow): ActivityAccept {
38 return {
39 type: 'Accept',
40 id: url,
41 actor: byActor.url,
42 object: followActivityData
43 }
44}