X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fprocess%2Fprocess-accept.ts;h=077b01eda878d9a56a5732435c184f903082701f;hb=47d883de2efbc2e8b5f6f94ae18c15224cbe982b;hp=5b321f771d348aa4d3c9727c036769b209972ba1;hpb=3fd3ab2d34d512b160a5e6084d7609be7b4f4452;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/process/process-accept.ts b/server/lib/activitypub/process/process-accept.ts index 5b321f771..077b01eda 100644 --- a/server/lib/activitypub/process/process-accept.ts +++ b/server/lib/activitypub/process/process-accept.ts @@ -1,14 +1,14 @@ import { ActivityAccept } from '../../../../shared/models/activitypub' -import { AccountModel } from '../../../models/account/account' -import { AccountFollowModel } from '../../../models/account/account-follow' -import { addFetchOutboxJob } from '../fetch' +import { ActorFollowModel } from '../../../models/actor/actor-follow' +import { APProcessorOptions } from '../../../types/activitypub-processor.model' +import { MActorDefault, MActorSignature } from '../../../types/models' +import { addFetchOutboxJob } from '../outbox' -async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountModel) { - if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.') +async function processAcceptActivity (options: APProcessorOptions) { + const { byActor: targetActor, inboxActor } = options + if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.') - const targetAccount = await AccountModel.loadByUrl(activity.actor) - - return processAccept(inboxAccount, targetAccount) + return processAccept(inboxActor, targetActor) } // --------------------------------------------------------------------------- @@ -19,11 +19,14 @@ export { // --------------------------------------------------------------------------- -async function processAccept (account: AccountModel, targetAccount: AccountModel) { - const follow = await AccountFollowModel.loadByAccountAndTarget(account.id, targetAccount.id) +async function processAccept (actor: MActorDefault, targetActor: MActorSignature) { + const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id) if (!follow) throw new Error('Cannot find associated follow.') - follow.set('state', 'accepted') - await follow.save() - await addFetchOutboxJob(targetAccount, undefined) + if (follow.state !== 'accepted') { + follow.state = 'accepted' + await follow.save() + + await addFetchOutboxJob(targetActor) + } }