1
0
Fork 0
peertube/server/lib/activitypub/send/send-accept.ts

45 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-12-19 04:34:56 -05:00
import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub'
2017-12-14 11:38:41 -05:00
import { ActorModel } from '../../../models/activitypub/actor'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
2017-12-19 04:34:56 -05:00
import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url'
2018-05-25 05:32:36 -04:00
import { unicastTo } from './utils'
2018-09-11 10:27:07 -04:00
import { buildFollowActivity } from './send-follow'
2018-07-30 11:02:40 -04:00
import { logger } from '../../../helpers/logger'
2017-11-20 03:43:39 -05:00
async function sendAccept (actorFollow: ActorFollowModel) {
2017-12-14 11:38:41 -05:00
const follower = actorFollow.ActorFollower
const me = actorFollow.ActorFollowing
2017-11-20 03:43:39 -05:00
if (!follower.serverId) { // This should never happen
logger.warn('Do not sending accept to local follower.')
return
}
2018-07-30 11:02:40 -04:00
logger.info('Creating job to accept follower %s.', follower.url)
2019-04-08 08:04:57 -04:00
const followUrl = getActorFollowActivityPubUrl(follower, me)
2018-09-11 10:27:07 -04:00
const followData = buildFollowActivity(followUrl, follower, me)
2017-12-19 04:34:56 -05:00
2017-12-14 11:38:41 -05:00
const url = getActorFollowAcceptActivityPubUrl(actorFollow)
2018-09-11 10:27:07 -04:00
const data = buildAcceptActivity(url, me, followData)
2017-11-20 03:43:39 -05:00
return unicastTo(data, me, follower.inboxUrl)
2017-11-20 03:43:39 -05:00
}
// ---------------------------------------------------------------------------
export {
sendAccept
}
// ---------------------------------------------------------------------------
2018-09-11 10:27:07 -04:00
function buildAcceptActivity (url: string, byActor: ActorModel, followActivityData: ActivityFollow): ActivityAccept {
2017-12-14 11:38:41 -05:00
return {
2017-11-20 03:43:39 -05:00
type: 'Accept',
id: url,
2017-12-19 04:34:56 -05:00
actor: byActor.url,
object: followActivityData
2017-11-20 03:43:39 -05:00
}
}