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