1 import { ActivityFollow } from '../../../../shared/models/activitypub'
2 import { getActorFollowActivityPubUrl } from '../url'
3 import { unicastTo } from './utils'
4 import { logger } from '../../../helpers/logger'
5 import { Transaction } from 'sequelize'
6 import { MActor, MActorFollowActors } from '../../../types/models'
8 function sendFollow (actorFollow: MActorFollowActors, t: Transaction) {
9 const me = actorFollow.ActorFollower
10 const following = actorFollow.ActorFollowing
12 // Same server as ours
13 if (!following.serverId) return
15 logger.info('Creating job to send follow request to %s.', following.url)
17 const url = getActorFollowActivityPubUrl(me, following)
18 const data = buildFollowActivity(url, me, following)
20 t.afterCommit(() => unicastTo(data, me, following.inboxUrl))
23 function buildFollowActivity (url: string, byActor: MActor, targetActor: MActor): ActivityFollow {
28 object: targetActor.url
32 // ---------------------------------------------------------------------------