2017-12-12 10:53:50 -06:00
|
|
|
import { ActivityFollow } from '../../../../shared/models/activitypub'
|
2017-12-14 10:38:41 -06:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
|
|
|
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
|
|
|
import { getActorFollowActivityPubUrl } from '../url'
|
2018-05-25 04:32:36 -05:00
|
|
|
import { unicastTo } from './utils'
|
2018-07-30 10:02:40 -05:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2018-01-25 08:05:18 -06:00
|
|
|
function sendFollow (actorFollow: ActorFollowModel) {
|
2017-12-14 10:38:41 -06:00
|
|
|
const me = actorFollow.ActorFollower
|
|
|
|
const following = actorFollow.ActorFollowing
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2018-08-16 08:25:20 -05:00
|
|
|
// Same server as ours
|
|
|
|
if (!following.serverId) return
|
|
|
|
|
2018-07-30 10:02:40 -05:00
|
|
|
logger.info('Creating job to send follow request to %s.', following.url)
|
|
|
|
|
2019-04-08 07:04:57 -05:00
|
|
|
const url = getActorFollowActivityPubUrl(me, following)
|
2018-09-11 09:27:07 -05:00
|
|
|
const data = buildFollowActivity(url, me, following)
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2018-01-25 08:05:18 -06:00
|
|
|
return unicastTo(data, me, following.inboxUrl)
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|
|
|
|
|
2018-09-11 09:27:07 -05:00
|
|
|
function buildFollowActivity (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow {
|
2017-12-12 10:53:50 -06:00
|
|
|
return {
|
2017-11-20 02:43:39 -06:00
|
|
|
type: 'Follow',
|
|
|
|
id: url,
|
2017-12-14 10:38:41 -06:00
|
|
|
actor: byActor.url,
|
|
|
|
object: targetActor.url
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendFollow,
|
2018-09-11 09:27:07 -05:00
|
|
|
buildFollowActivity
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|