diff options
Diffstat (limited to 'server/lib/job-queue/handlers/activitypub-follow.ts')
-rw-r--r-- | server/lib/job-queue/handlers/activitypub-follow.ts | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts index 5cb55cad6..af7c8a838 100644 --- a/server/lib/job-queue/handlers/activitypub-follow.ts +++ b/server/lib/job-queue/handlers/activitypub-follow.ts | |||
@@ -10,12 +10,13 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | |||
10 | import { ActorModel } from '../../../models/activitypub/actor' | 10 | import { ActorModel } from '../../../models/activitypub/actor' |
11 | import { Notifier } from '../../notifier' | 11 | import { Notifier } from '../../notifier' |
12 | import { sequelizeTypescript } from '../../../initializers/database' | 12 | import { sequelizeTypescript } from '../../../initializers/database' |
13 | import { MAccount, MActor, MActorFollowActors, MActorFollowFull, MActorFull } from '../../../typings/models' | 13 | import { MActor, MActorFollowActors, MActorFull } from '../../../typings/models' |
14 | 14 | ||
15 | export type ActivitypubFollowPayload = { | 15 | export type ActivitypubFollowPayload = { |
16 | followerActorId: number | 16 | followerActorId: number |
17 | name: string | 17 | name: string |
18 | host: string | 18 | host: string |
19 | isAutoFollow?: boolean | ||
19 | } | 20 | } |
20 | 21 | ||
21 | async function processActivityPubFollow (job: Bull.Job) { | 22 | async function processActivityPubFollow (job: Bull.Job) { |
@@ -35,7 +36,7 @@ async function processActivityPubFollow (job: Bull.Job) { | |||
35 | 36 | ||
36 | const fromActor = await ActorModel.load(payload.followerActorId) | 37 | const fromActor = await ActorModel.load(payload.followerActorId) |
37 | 38 | ||
38 | return retryTransactionWrapper(follow, fromActor, targetActor) | 39 | return retryTransactionWrapper(follow, fromActor, targetActor, payload.isAutoFollow) |
39 | } | 40 | } |
40 | // --------------------------------------------------------------------------- | 41 | // --------------------------------------------------------------------------- |
41 | 42 | ||
@@ -45,7 +46,7 @@ export { | |||
45 | 46 | ||
46 | // --------------------------------------------------------------------------- | 47 | // --------------------------------------------------------------------------- |
47 | 48 | ||
48 | async function follow (fromActor: MActor, targetActor: MActorFull) { | 49 | async function follow (fromActor: MActor, targetActor: MActorFull, isAutoFollow = false) { |
49 | if (fromActor.id === targetActor.id) { | 50 | if (fromActor.id === targetActor.id) { |
50 | throw new Error('Follower is the same than target actor.') | 51 | throw new Error('Follower is the same than target actor.') |
51 | } | 52 | } |
@@ -75,14 +76,15 @@ async function follow (fromActor: MActor, targetActor: MActorFull) { | |||
75 | return actorFollow | 76 | return actorFollow |
76 | }) | 77 | }) |
77 | 78 | ||
78 | if (actorFollow.state === 'accepted') { | 79 | const followerFull = await ActorModel.loadFull(fromActor.id) |
79 | const followerFull = Object.assign(fromActor, { Account: await actorFollow.ActorFollower.$get('Account') as MAccount }) | ||
80 | 80 | ||
81 | const actorFollowFull = Object.assign(actorFollow, { | 81 | const actorFollowFull = Object.assign(actorFollow, { |
82 | ActorFollowing: targetActor, | 82 | ActorFollowing: targetActor, |
83 | ActorFollower: followerFull | 83 | ActorFollower: followerFull |
84 | }) | 84 | }) |
85 | 85 | ||
86 | Notifier.Instance.notifyOfNewUserFollow(actorFollowFull) | 86 | if (actorFollow.state === 'accepted') Notifier.Instance.notifyOfNewUserFollow(actorFollowFull) |
87 | } | 87 | if (isAutoFollow === true) Notifier.Instance.notifyOfAutoInstanceFollowing(actorFollowFull) |
88 | |||
89 | return actorFollow | ||
88 | } | 90 | } |