+import { ActivityFollow } from '../../../../shared/models/activitypub'
+import { getActorFollowActivityPubUrl } from '../url'
+import { unicastTo } from './utils'
+import { logger } from '../../../helpers/logger'
import { Transaction } from 'sequelize'
-import { ActivityFollow } from '../../../../shared/models/activitypub/activity'
-import { AccountInstance } from '../../../models'
-import { AccountFollowInstance } from '../../../models/account/account-follow-interface'
-import { getAccountFollowActivityPubUrl } from '../url'
-import { unicastTo } from './misc'
+import { MActor, MActorFollowActors } from '../../../typings/models'
-function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) {
- const me = accountFollow.AccountFollower
- const following = accountFollow.AccountFollowing
+function sendFollow (actorFollow: MActorFollowActors, t: Transaction) {
+ const me = actorFollow.ActorFollower
+ const following = actorFollow.ActorFollowing
- const url = getAccountFollowActivityPubUrl(accountFollow)
- const data = followActivityData(url, me, following)
+ // Same server as ours
+ if (!following.serverId) return
- return unicastTo(data, me, following.inboxUrl, t)
+ logger.info('Creating job to send follow request to %s.', following.url)
+
+ const url = getActorFollowActivityPubUrl(me, following)
+ const data = buildFollowActivity(url, me, following)
+
+ t.afterCommit(() => unicastTo(data, me, following.inboxUrl))
}
-function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) {
- const activity: ActivityFollow = {
+function buildFollowActivity (url: string, byActor: MActor, targetActor: MActor): ActivityFollow {
+ return {
type: 'Follow',
id: url,
- actor: byAccount.url,
- object: targetAccount.url
+ actor: byActor.url,
+ object: targetActor.url
}
-
- return activity
}
// ---------------------------------------------------------------------------
export {
sendFollow,
- followActivityData
+ buildFollowActivity
}