X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Flib%2Factivitypub%2Fsend%2Fsend-follow.ts;h=170b46b482e035ce3b97ea1acfaf9c136e323d56;hb=c48e82b5e0478434de30626d14594a97f2402e7c;hp=3c01fb77c378cc71462c277b7fa0091c45444b7f;hpb=892211e8493b1f992fce7616cb1e48b7ff87a1dc;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts index 3c01fb77c..170b46b48 100644 --- a/server/lib/activitypub/send/send-follow.ts +++ b/server/lib/activitypub/send/send-follow.ts @@ -1,34 +1,37 @@ -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 { ActorModel } from '../../../models/activitypub/actor' +import { ActorFollowModel } from '../../../models/activitypub/actor-follow' +import { getActorFollowActivityPubUrl } from '../url' +import { unicastTo } from './utils' +import { logger } from '../../../helpers/logger' -async function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) { - const me = accountFollow.AccountFollower - const following = accountFollow.AccountFollowing +function sendFollow (actorFollow: ActorFollowModel) { + const me = actorFollow.ActorFollower + const following = actorFollow.ActorFollowing - const url = getAccountFollowActivityPubUrl(accountFollow) - const data = await 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(actorFollow) + const data = buildFollowActivity(url, me, following) + + return unicastTo(data, me, following.inboxUrl) } -async function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) { - const activity: ActivityFollow = { +function buildFollowActivity (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow { + return { type: 'Follow', id: url, - actor: byAccount.url, - object: targetAccount.url + actor: byActor.url, + object: targetActor.url } - - return activity } // --------------------------------------------------------------------------- export { sendFollow, - followActivityData + buildFollowActivity }