X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fprocess%2Fprocess-follow.ts;h=24c9085f7ac77520a537e713e8c09a336518341c;hb=e587e0ecee5bec43a225995948faaa4bc97f080a;hp=bc02d5043835466e648804e3e2bfcd91de137b52;hpb=39fdb3c032875ab8c9a1e5e52f76d3baa0ac4e63;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index bc02d5043..24c9085f7 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts @@ -1,16 +1,15 @@ import { ActivityFollow } from '../../../../shared/models/activitypub' -import { logger, retryTransactionWrapper } from '../../../helpers' +import { retryTransactionWrapper } from '../../../helpers/database-utils' +import { logger } from '../../../helpers/logger' import { sequelizeTypescript } from '../../../initializers' import { ActorModel } from '../../../models/activitypub/actor' import { ActorFollowModel } from '../../../models/activitypub/actor-follow' -import { getOrCreateActorAndServerAndModel } from '../actor' import { sendAccept } from '../send' -async function processFollowActivity (activity: ActivityFollow) { +async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) { const activityObject = activity.object - const actor = await getOrCreateActorAndServerAndModel(activity.actor) - return processFollow(actor, activityObject) + return retryTransactionWrapper(processFollow, byActor, activityObject) } // --------------------------------------------------------------------------- @@ -21,18 +20,9 @@ export { // --------------------------------------------------------------------------- -function processFollow (actor: ActorModel, targetActorURL: string) { - const options = { - arguments: [ actor, targetActorURL ], - errorMessage: 'Cannot follow with many retries.' - } - - return retryTransactionWrapper(follow, options) -} - -async function follow (actor: ActorModel, targetActorURL: string) { +async function processFollow (actor: ActorModel, targetActorURL: string) { await sequelizeTypescript.transaction(async t => { - const targetActor = await ActorModel.loadByUrl(targetActorURL, t) + const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) if (!targetActor) throw new Error('Unknown actor') if (targetActor.isOwned() === false) throw new Error('This is not a local actor.') @@ -50,6 +40,9 @@ async function follow (actor: ActorModel, targetActorURL: string) { transaction: t }) + actorFollow.ActorFollower = actor + actorFollow.ActorFollowing = targetActor + if (actorFollow.state !== 'accepted') { actorFollow.state = 'accepted' await actorFollow.save({ transaction: t }) @@ -59,8 +52,8 @@ async function follow (actor: ActorModel, targetActorURL: string) { actorFollow.ActorFollowing = targetActor // Target sends to actor he accepted the follow request - return sendAccept(actorFollow, t) + return sendAccept(actorFollow) }) - logger.info('Actor %s is followed by actor %s.', actor.url, targetActorURL) + logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url) }