X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fprocess%2Fprocess-follow.ts;h=0cd537187a93ccacc939d85f0258ef473f68a28b;hb=594d0c6a7c64b045c11508bb4e4b19b75b3fc557;hp=24c9085f7ac77520a537e713e8c09a336518341c;hpb=0491173a61aed66205c017e0d7e0503ea316c144;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index 24c9085f7..0cd537187 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts @@ -5,9 +5,11 @@ import { sequelizeTypescript } from '../../../initializers' import { ActorModel } from '../../../models/activitypub/actor' import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { sendAccept } from '../send' +import { Notifier } from '../../notifier' +import { getAPId } from '../../../helpers/activitypub' async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) { - const activityObject = activity.object + const activityObject = getAPId(activity.object) return retryTransactionWrapper(processFollow, byActor, activityObject) } @@ -21,13 +23,13 @@ export { // --------------------------------------------------------------------------- async function processFollow (actor: ActorModel, targetActorURL: string) { - await sequelizeTypescript.transaction(async t => { + const { actorFollow, created } = await sequelizeTypescript.transaction(async 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.') - const [ actorFollow ] = await ActorFollowModel.findOrCreate({ + const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({ where: { actorId: actor.id, targetActorId: targetActor.id @@ -52,8 +54,12 @@ async function processFollow (actor: ActorModel, targetActorURL: string) { actorFollow.ActorFollowing = targetActor // Target sends to actor he accepted the follow request - return sendAccept(actorFollow) + await sendAccept(actorFollow) + + return { actorFollow, created } }) + if (created) Notifier.Instance.notifyOfNewFollow(actorFollow) + logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url) }