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