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