diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-09 08:17:16 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-09 08:17:16 +0200 |
commit | 5224c394b3bbac6ec1543e41fa0ec6db436e84fa (patch) | |
tree | 36eaecfe095547aca903a8a43fb6e0b0b01899a9 /server/lib/activitypub/process/process-follow.ts | |
parent | 511765c9f86fb07d5d856decd9dbf0ec2092f4fe (diff) | |
download | PeerTube-5224c394b3bbac6ec1543e41fa0ec6db436e84fa.tar.gz PeerTube-5224c394b3bbac6ec1543e41fa0ec6db436e84fa.tar.zst PeerTube-5224c394b3bbac6ec1543e41fa0ec6db436e84fa.zip |
Stronger actor association typing in AP functions
Diffstat (limited to 'server/lib/activitypub/process/process-follow.ts')
-rw-r--r-- | server/lib/activitypub/process/process-follow.ts | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index 8fe9975f6..240aa5799 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts | |||
@@ -10,6 +10,8 @@ import { getAPId } from '../../../helpers/activitypub' | |||
10 | import { getServerActor } from '../../../helpers/utils' | 10 | import { getServerActor } from '../../../helpers/utils' |
11 | import { CONFIG } from '../../../initializers/config' | 11 | import { CONFIG } from '../../../initializers/config' |
12 | import { APProcessorOptions } from '../../../typings/activitypub-processor.model' | 12 | import { APProcessorOptions } from '../../../typings/activitypub-processor.model' |
13 | import { SignatureActorModel } from '../../../typings/models' | ||
14 | import { ActorFollowModelLight } from '../../../typings/models/actor-follow' | ||
13 | 15 | ||
14 | async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) { | 16 | async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) { |
15 | const { activity, byActor } = options | 17 | const { activity, byActor } = options |
@@ -26,7 +28,7 @@ export { | |||
26 | 28 | ||
27 | // --------------------------------------------------------------------------- | 29 | // --------------------------------------------------------------------------- |
28 | 30 | ||
29 | async function processFollow (actor: ActorModel, targetActorURL: string) { | 31 | async function processFollow (byActor: SignatureActorModel, targetActorURL: string) { |
30 | const { actorFollow, created, isFollowingInstance } = await sequelizeTypescript.transaction(async t => { | 32 | const { actorFollow, created, isFollowingInstance } = await sequelizeTypescript.transaction(async t => { |
31 | const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) | 33 | const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) |
32 | 34 | ||
@@ -39,30 +41,30 @@ async function processFollow (actor: ActorModel, targetActorURL: string) { | |||
39 | if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { | 41 | if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { |
40 | logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) | 42 | logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) |
41 | 43 | ||
42 | await sendReject(actor, targetActor) | 44 | await sendReject(byActor, targetActor) |
43 | 45 | ||
44 | return { actorFollow: undefined } | 46 | return { actorFollow: undefined } |
45 | } | 47 | } |
46 | 48 | ||
47 | const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({ | 49 | const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({ |
48 | where: { | 50 | where: { |
49 | actorId: actor.id, | 51 | actorId: byActor.id, |
50 | targetActorId: targetActor.id | 52 | targetActorId: targetActor.id |
51 | }, | 53 | }, |
52 | defaults: { | 54 | defaults: { |
53 | actorId: actor.id, | 55 | actorId: byActor.id, |
54 | targetActorId: targetActor.id, | 56 | targetActorId: targetActor.id, |
55 | state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL ? 'pending' : 'accepted' | 57 | state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL ? 'pending' : 'accepted' |
56 | }, | 58 | }, |
57 | transaction: t | 59 | transaction: t |
58 | }) | 60 | }) as [ ActorFollowModelLight, boolean ] |
59 | 61 | ||
60 | if (actorFollow.state !== 'accepted' && CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL === false) { | 62 | if (actorFollow.state !== 'accepted' && CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL === false) { |
61 | actorFollow.state = 'accepted' | 63 | actorFollow.state = 'accepted' |
62 | await actorFollow.save({ transaction: t }) | 64 | await actorFollow.save({ transaction: t }) |
63 | } | 65 | } |
64 | 66 | ||
65 | actorFollow.ActorFollower = actor | 67 | actorFollow.ActorFollower = byActor |
66 | actorFollow.ActorFollowing = targetActor | 68 | actorFollow.ActorFollowing = targetActor |
67 | 69 | ||
68 | // Target sends to actor he accepted the follow request | 70 | // Target sends to actor he accepted the follow request |
@@ -79,5 +81,5 @@ async function processFollow (actor: ActorModel, targetActorURL: string) { | |||
79 | else Notifier.Instance.notifyOfNewUserFollow(actorFollow) | 81 | else Notifier.Instance.notifyOfNewUserFollow(actorFollow) |
80 | } | 82 | } |
81 | 83 | ||
82 | logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url) | 84 | logger.info('Actor %s is followed by actor %s.', targetActorURL, byActor.url) |
83 | } | 85 | } |