X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fsend%2Fsend-follow.ts;h=9219640ddaae85cb8733e5c5ff6d44d7a78b02ca;hb=4d7ce9218a3f695bf3d013cbdce1c5c6a5221927;hp=8fba1b6b57661ca765714091bc2055f36512d19a;hpb=25ed141c7c7631ef21d8764c1163fbf8a6591391;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts index 8fba1b6b5..9219640dd 100644 --- a/server/lib/activitypub/send/send-follow.ts +++ b/server/lib/activitypub/send/send-follow.ts @@ -1,34 +1,35 @@ 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 { ActivityFollow } from '../../../../shared/models/activitypub' +import { logger } from '../../../helpers/logger' +import { MActor, MActorFollowActors } from '../../../types/models' +import { unicastTo } from './utils' -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 data = buildFollowActivity(actorFollow.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 }