diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-30 16:50:12 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-09-04 16:24:58 +0200 |
commit | 8424c4026afd7304880a4ce8138a04ffb3d8c938 (patch) | |
tree | 5b42625a59307b03333aa7d293b40b4c90da8f73 /server/lib/activitypub/process | |
parent | f69ec5f340638ef577e8f5b9b1fb844778656a1f (diff) | |
download | PeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.tar.gz PeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.tar.zst PeerTube-8424c4026afd7304880a4ce8138a04ffb3d8c938.zip |
Add auto follow back support for instances
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r-- | server/lib/activitypub/process/process-accept.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-follow.ts | 20 |
2 files changed, 13 insertions, 9 deletions
diff --git a/server/lib/activitypub/process/process-accept.ts b/server/lib/activitypub/process/process-accept.ts index 86f7c764d..dcfbb2c84 100644 --- a/server/lib/activitypub/process/process-accept.ts +++ b/server/lib/activitypub/process/process-accept.ts | |||
@@ -24,7 +24,7 @@ async function processAccept (actor: MActorDefault, targetActor: MActorSignature | |||
24 | if (!follow) throw new Error('Cannot find associated follow.') | 24 | if (!follow) throw new Error('Cannot find associated follow.') |
25 | 25 | ||
26 | if (follow.state !== 'accepted') { | 26 | if (follow.state !== 'accepted') { |
27 | follow.set('state', 'accepted') | 27 | follow.state = 'accepted' |
28 | await follow.save() | 28 | await follow.save() |
29 | 29 | ||
30 | await addFetchOutboxJob(targetActor) | 30 | await addFetchOutboxJob(targetActor) |
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index bc5660395..85f22d654 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts | |||
@@ -10,7 +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 { MAccount, MActorFollowActors, MActorFollowFull, MActorSignature } from '../../../typings/models' | 13 | import { MActorFollowActors, MActorSignature } from '../../../typings/models' |
14 | import { autoFollowBackIfNeeded } from '../follow' | ||
14 | 15 | ||
15 | async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) { | 16 | async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) { |
16 | const { activity, byActor } = options | 17 | const { activity, byActor } = options |
@@ -28,7 +29,7 @@ export { | |||
28 | // --------------------------------------------------------------------------- | 29 | // --------------------------------------------------------------------------- |
29 | 30 | ||
30 | async function processFollow (byActor: MActorSignature, targetActorURL: string) { | 31 | async function processFollow (byActor: MActorSignature, targetActorURL: string) { |
31 | const { actorFollow, created, isFollowingInstance } = await sequelizeTypescript.transaction(async t => { | 32 | const { actorFollow, created, isFollowingInstance, targetActor } = await sequelizeTypescript.transaction(async t => { |
32 | const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) | 33 | const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) |
33 | 34 | ||
34 | if (!targetActor) throw new Error('Unknown actor') | 35 | if (!targetActor) throw new Error('Unknown actor') |
@@ -67,21 +68,24 @@ async function processFollow (byActor: MActorSignature, targetActorURL: string) | |||
67 | actorFollow.ActorFollowing = targetActor | 68 | actorFollow.ActorFollowing = targetActor |
68 | 69 | ||
69 | // Target sends to actor he accepted the follow request | 70 | // Target sends to actor he accepted the follow request |
70 | if (actorFollow.state === 'accepted') await sendAccept(actorFollow) | 71 | if (actorFollow.state === 'accepted') { |
72 | await sendAccept(actorFollow) | ||
73 | await autoFollowBackIfNeeded(actorFollow) | ||
74 | } | ||
71 | 75 | ||
72 | return { actorFollow, created, isFollowingInstance } | 76 | return { actorFollow, created, isFollowingInstance, targetActor } |
73 | }) | 77 | }) |
74 | 78 | ||
75 | // Rejected | 79 | // Rejected |
76 | if (!actorFollow) return | 80 | if (!actorFollow) return |
77 | 81 | ||
78 | if (created) { | 82 | if (created) { |
83 | const follower = await ActorModel.loadFull(byActor.id) | ||
84 | const actorFollowFull = Object.assign(actorFollow, { ActorFollowing: targetActor, ActorFollower: follower }) | ||
85 | |||
79 | if (isFollowingInstance) { | 86 | if (isFollowingInstance) { |
80 | Notifier.Instance.notifyOfNewInstanceFollow(actorFollow) | 87 | Notifier.Instance.notifyOfNewInstanceFollow(actorFollowFull) |
81 | } else { | 88 | } else { |
82 | const actorFollowFull = actorFollow as MActorFollowFull | ||
83 | actorFollowFull.ActorFollower.Account = await actorFollow.ActorFollower.$get('Account') as MAccount | ||
84 | |||
85 | Notifier.Instance.notifyOfNewUserFollow(actorFollowFull) | 89 | Notifier.Instance.notifyOfNewUserFollow(actorFollowFull) |
86 | } | 90 | } |
87 | } | 91 | } |