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